RFR: 8297379: Enable the ByteBuffer path of Poly1305 optimizations

Sandhya Viswanathan sviswanathan at openjdk.org
Tue Nov 29 01:20:19 UTC 2022


On Wed, 23 Nov 2022 23:33:32 GMT, Volodymyr Paprotski <duke at openjdk.org> wrote:

> Regarding mainline:
> - I decided not to 'unroll' the top while loop (i.e. `engineUpdate(byte[] input, int offset, int len)` is unrolled)
>    - It is debatable which version is easier to understand. If this version is 'too complex', I can unroll the top while loop. 
> - I do think this version is incremental (i.e. easier to review?):
>    - Move `remaining -= bytesToWrite;` into each `if` branch
>    - Change first `if` case to process multiple blocks instead of one
> 
> This `while` loop has a lot of cases to remember; Very roughly:
> 
> 1. process from previous call
> 2. process current data
> 3. store overflow
> 
> Interesting situations:
> - `blockOffset` might be non-`0`
> - `remaining+blockOffset` might not be enough to fill a single block. Or just enough for one block and to leave an overflow again..
> - etc.
> 
> Regarding testing
> - Correctness of intrinsic was already tested in https://github.com/openjdk/jdk/pull/10582 so not adding any tests there (i.e. no KAT)
> - In principle, fuzz test should also be sufficient to test bytebuffer (did increase repetitions)

src/java.base/share/classes/com/sun/crypto/provider/Poly1305.java line 260:

> 258:         if (buf.hasArray()) {
> 259:             byte[] input = buf.array();
> 260:             int offset = buf.arrayOffset();

arrayOffset returns the offset of the first element of the backing buffer. Need to also take into account the position() of the buffer here. We should also add test case for this.

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

PR: https://git.openjdk.org/jdk/pull/11338


More information about the security-dev mailing list