Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8283a81 authored by Shawn Willden's avatar Shawn Willden
Browse files

Fix encryption/decryption of large blocks.

There's a long-standing bug (since ~Marshmallow) that causes
AndroidKeyStore to truncate large (>64 KiB) blocks of data.  This can
be avoided by callers by processing data in smaller chunks, and
smaller chunks are more memory-efficient while not being much (if any)
more time-efficient.  But, Keystore should handle large blocks
correctly.  This CL adds a test to all block cipher tests that
attempts to encrypt and then decrypt a 100 KiB block.

Bug: 123391046
Test:  CtsKeystoreTestCases
Change-Id: I0c0286fd5360d4fe62cbd8130aa0c17f97318801
parent 3d8f95a4
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -162,16 +162,16 @@ class KeyStoreCryptoOperationChunkedStreamer implements KeyStoreCryptoOperationS
            }

            if ((opResult.output != null) && (opResult.output.length > 0)) {
                if (inputLength > 0) {
                if (inputLength + mBufferedLength > 0) {
                    // More output might be produced in this loop -- buffer the current output
                    if (bufferedOutput == null) {
                        bufferedOutput = new ByteArrayOutputStream();
                    }
                    try {
                        bufferedOutput.write(opResult.output);
                    } catch (IOException e) {
                        throw new ProviderException("Failed to buffer output", e);
                    }
                    }
                } else {
                    // No more output will be produced in this loop
                    byte[] result;