I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit c1fef302 authored by zzz's avatar zzz
Browse files

Crypto: ChaCha small initialization speedup

parent bd370cf4
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,11 @@ package com.southernstorm.noise.crypto.chacha20; ...@@ -27,6 +27,11 @@ package com.southernstorm.noise.crypto.chacha20;
*/ */
public final class ChaChaCore { public final class ChaChaCore {
private static final int INIT0 = char4('e', 'x', 'p', 'a');
private static final int INIT1 = char4('n', 'd', ' ', '3');
private static final int INIT2 = char4('2', '-', 'b', 'y');
private static final int INIT3 = char4('t', 'e', ' ', 'k');
private ChaChaCore() {} private ChaChaCore() {}
/** /**
...@@ -42,8 +47,7 @@ public final class ChaChaCore { ...@@ -42,8 +47,7 @@ public final class ChaChaCore {
int index; int index;
// Copy the input to the output to start with. // Copy the input to the output to start with.
for (index = 0; index < 16; ++index) System.arraycopy(input, 0, output, 0, 16);
output[index] = input[index];
// Perform the 20 ChaCha rounds in groups of two. // Perform the 20 ChaCha rounds in groups of two.
for (index = 0; index < 20; index += 2) { for (index = 0; index < 20; index += 2) {
...@@ -85,10 +89,10 @@ public final class ChaChaCore { ...@@ -85,10 +89,10 @@ public final class ChaChaCore {
*/ */
public static void initKey256(int[] output, byte[] key, int offset) public static void initKey256(int[] output, byte[] key, int offset)
{ {
output[0] = char4('e', 'x', 'p', 'a'); output[0] = INIT0;
output[1] = char4('n', 'd', ' ', '3'); output[1] = INIT1;
output[2] = char4('2', '-', 'b', 'y'); output[2] = INIT2;
output[3] = char4('t', 'e', ' ', 'k'); output[3] = INIT3;
output[4] = fromLittleEndian(key, offset); output[4] = fromLittleEndian(key, offset);
output[5] = fromLittleEndian(key, offset + 4); output[5] = fromLittleEndian(key, offset + 4);
output[6] = fromLittleEndian(key, offset + 8); output[6] = fromLittleEndian(key, offset + 8);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment