diff options
author | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-15 01:38:01 +0400 |
---|---|---|
committer | Roberto Tyley <roberto.tyley@gmail.com> | 2014-07-26 11:23:17 +0400 |
commit | 7cb752aaf746dc0b473afeb9e892b7fbc12666c5 (patch) | |
tree | cc4f91ddc18332b5adbe82e3fcb040d976c90105 /core/src/main/java/org/spongycastle/crypto/modes/gcm/Tables64kGCMMultiplier.java | |
parent | 551830f8ea5177042af2c7dd1fc90888bc67387d (diff) |
Execute become-spongy.sh
https://github.com/rtyley/spongycastle/blob/3040af/become-spongy.sh
Diffstat (limited to 'core/src/main/java/org/spongycastle/crypto/modes/gcm/Tables64kGCMMultiplier.java')
-rw-r--r-- | core/src/main/java/org/spongycastle/crypto/modes/gcm/Tables64kGCMMultiplier.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/core/src/main/java/org/spongycastle/crypto/modes/gcm/Tables64kGCMMultiplier.java b/core/src/main/java/org/spongycastle/crypto/modes/gcm/Tables64kGCMMultiplier.java new file mode 100644 index 00000000..352ffc58 --- /dev/null +++ b/core/src/main/java/org/spongycastle/crypto/modes/gcm/Tables64kGCMMultiplier.java @@ -0,0 +1,73 @@ +package org.spongycastle.crypto.modes.gcm; + +import org.spongycastle.util.Arrays; +import org.spongycastle.util.Pack; + +public class Tables64kGCMMultiplier implements GCMMultiplier +{ + private byte[] H; + private int[][][] M; + + public void init(byte[] H) + { + if (M == null) + { + M = new int[16][256][4]; + } + else if (Arrays.areEqual(this.H, H)) + { + return; + } + + this.H = Arrays.clone(H); + + // M[0][0] is ZEROES; + GCMUtil.asInts(H, M[0][128]); + + for (int j = 64; j >= 1; j >>= 1) + { + GCMUtil.multiplyP(M[0][j + j], M[0][j]); + } + + int i = 0; + for (;;) + { + for (int j = 2; j < 256; j += j) + { + for (int k = 1; k < j; ++k) + { + GCMUtil.xor(M[i][j], M[i][k], M[i][j + k]); + } + } + + if (++i == 16) + { + return; + } + + // M[i][0] is ZEROES; + for (int j = 128; j > 0; j >>= 1) + { + GCMUtil.multiplyP8(M[i - 1][j], M[i][j]); + } + } + } + + public void multiplyH(byte[] x) + { +// assert x.Length == 16; + + int[] z = new int[4]; + for (int i = 15; i >= 0; --i) + { +// GCMUtil.xor(z, M[i][x[i] & 0xff]); + int[] m = M[i][x[i] & 0xff]; + z[0] ^= m[0]; + z[1] ^= m[1]; + z[2] ^= m[2]; + z[3] ^= m[3]; + } + + Pack.intToBigEndian(z, x, 0); + } +} |