RFR: 8318756 Create better internal buffer for AEADs

Daniel Jeliński djelinski at openjdk.org
Tue Nov 28 07:28:10 UTC 2023


On Tue, 28 Nov 2023 00:51:54 GMT, Anthony Scarpino <ascarpino at openjdk.org> wrote:

>> src/java.base/share/classes/com/sun/crypto/provider/ChaCha20Cipher.java line 1427:
>> 
>>> 1425:             input.get(in);
>>> 1426:             byte[] out = new byte[in.length];
>>> 1427:             doUpdate(in, 0, in.length, out, out.length);
>> 
>> Suggestion:
>> 
>>             byte[] out = in;
>>             doUpdate(in, 0, in.length, out, 0);
>> 
>> I guess we need more test coverage here
>
> I don't see a testing issue there, but that's better memory usage.  I probably copied this code over from AES/GCM where it's blocksized data and `in` and `out` could have been different sizes.  But CC20 can use this optimization because it's a streaming cipher.

I was talking about the second line:

doUpdate(in, 0, in.length, out, out.length);

this tells the doUpdate operation to start writing to `out` at `out.length`; that should have triggered an exception in testing.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16487#discussion_r1407327505



More information about the security-dev mailing list