forked from I2P_Developers/i2p.i2p
Crypto: ChaChaCore microoptimizations
and some indent fixes
This commit is contained in:
@ -65,9 +65,10 @@ public final class ChaChaCore {
|
||||
}
|
||||
|
||||
// Add the input block to the output.
|
||||
for (index = 0; index < 16; ++index)
|
||||
for (index = 0; index < 16; ++index) {
|
||||
output[index] += input[index];
|
||||
}
|
||||
}
|
||||
|
||||
private static int char4(char c1, char c2, char c3, char c4)
|
||||
{
|
||||
@ -192,23 +193,21 @@ public final class ChaChaCore {
|
||||
int value;
|
||||
while (length >= 4) {
|
||||
value = block[posn++];
|
||||
output[outputOffset] = (byte)(input[inputOffset] ^ value);
|
||||
output[outputOffset + 1] = (byte)(input[inputOffset + 1] ^ (value >> 8));
|
||||
output[outputOffset + 2] = (byte)(input[inputOffset + 2] ^ (value >> 16));
|
||||
output[outputOffset + 3] = (byte)(input[inputOffset + 3] ^ (value >> 24));
|
||||
inputOffset += 4;
|
||||
outputOffset += 4;
|
||||
output[outputOffset++] = (byte)(input[inputOffset++] ^ value);
|
||||
output[outputOffset++] = (byte)(input[inputOffset++] ^ (value >> 8));
|
||||
output[outputOffset++] = (byte)(input[inputOffset++] ^ (value >> 16));
|
||||
output[outputOffset++] = (byte)(input[inputOffset++] ^ (value >> 24));
|
||||
length -= 4;
|
||||
}
|
||||
if (length == 3) {
|
||||
value = block[posn];
|
||||
output[outputOffset] = (byte)(input[inputOffset] ^ value);
|
||||
output[outputOffset + 1] = (byte)(input[inputOffset + 1] ^ (value >> 8));
|
||||
output[outputOffset + 2] = (byte)(input[inputOffset + 2] ^ (value >> 16));
|
||||
output[outputOffset++] = (byte)(input[inputOffset++] ^ value);
|
||||
output[outputOffset++] = (byte)(input[inputOffset++] ^ (value >> 8));
|
||||
output[outputOffset] = (byte)(input[inputOffset] ^ (value >> 16));
|
||||
} else if (length == 2) {
|
||||
value = block[posn];
|
||||
output[outputOffset] = (byte)(input[inputOffset] ^ value);
|
||||
output[outputOffset + 1] = (byte)(input[inputOffset + 1] ^ (value >> 8));
|
||||
output[outputOffset++] = (byte)(input[inputOffset++] ^ value);
|
||||
output[outputOffset] = (byte)(input[inputOffset] ^ (value >> 8));
|
||||
} else if (length == 1) {
|
||||
value = block[posn];
|
||||
output[outputOffset] = (byte)(input[inputOffset] ^ value);
|
||||
|
Reference in New Issue
Block a user