mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8297379: Enable the ByteBuffer path of Poly1305 optimizations
Reviewed-by: sviswanathan, ascarpino, jnimeh
This commit is contained in:
parent
1e468320dc
commit
203251ffc0
3 changed files with 83 additions and 19 deletions
|
@ -124,10 +124,10 @@ final class Poly1305 {
|
|||
BLOCK_LENGTH - blockOffset);
|
||||
|
||||
if (bytesToWrite >= BLOCK_LENGTH) {
|
||||
// If bytes to write == BLOCK_LENGTH, then we have no
|
||||
// left-over data from previous updates and we can create
|
||||
// the IntegerModuloP directly from the input buffer.
|
||||
processBlock(buf, bytesToWrite);
|
||||
// Have at least one full block in the buf, process all full blocks
|
||||
int blockMultipleLength = remaining & (~(BLOCK_LENGTH-1));
|
||||
processMultipleBlocks(buf, blockMultipleLength);
|
||||
remaining -= blockMultipleLength;
|
||||
} else {
|
||||
// We have some left-over data from previous updates, so
|
||||
// copy that into the holding block until we get a full block.
|
||||
|
@ -138,9 +138,8 @@ final class Poly1305 {
|
|||
processBlock(block, 0, BLOCK_LENGTH);
|
||||
blockOffset = 0;
|
||||
}
|
||||
remaining -= bytesToWrite;
|
||||
}
|
||||
|
||||
remaining -= bytesToWrite;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,6 +254,24 @@ final class Poly1305 {
|
|||
}
|
||||
}
|
||||
|
||||
private void processMultipleBlocks(ByteBuffer buf, int blockMultipleLength) {
|
||||
if (buf.hasArray()) {
|
||||
byte[] input = buf.array();
|
||||
int offset = buf.arrayOffset() + buf.position();
|
||||
long[] aLimbs = a.getLimbs();
|
||||
long[] rLimbs = r.getLimbs();
|
||||
|
||||
processMultipleBlocksCheck(input, offset, blockMultipleLength, aLimbs, rLimbs);
|
||||
processMultipleBlocks(input, offset, blockMultipleLength, aLimbs, rLimbs);
|
||||
buf.position(offset + blockMultipleLength);
|
||||
} else {
|
||||
while (blockMultipleLength >= BLOCK_LENGTH) {
|
||||
processBlock(buf, BLOCK_LENGTH);
|
||||
blockMultipleLength -= BLOCK_LENGTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void processMultipleBlocksCheck(byte[] input, int offset, int length, long[] aLimbs, long[] rLimbs) {
|
||||
Objects.checkFromIndexSize(offset, length, input.length);
|
||||
final int numLimbs = 5; // Intrinsic expects exactly 5 limbs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue