public static long littleEndianToLong(byte[] bs, int off) { int lo = littleEndianToInt(bs, off); int hi = littleEndianToInt(bs, off + 4); return ((long)(hi & 0xffffffffL) << 32) | (long)(lo & 0xffffffffL); }
public static void littleEndianToInt(byte[] bs, int off, int[] ns) { for (int i = 0; i < ns.length; ++i) { ns[i] = littleEndianToInt(bs, off); off += 4; } }
public static int[] littleEndianToInt(byte[] bs, int off, int count) { int[] ns = new int[count]; for (int i = 0; i < ns.length; ++i) { ns[i] = littleEndianToInt(bs, off); off += 4; } return ns; }
private void unpackBlock(byte[] bytes, int off) { this.C0 = Pack.littleEndianToInt(bytes, off); this.C1 = Pack.littleEndianToInt(bytes, off + 4); this.C2 = Pack.littleEndianToInt(bytes, off + 8); this.C3 = Pack.littleEndianToInt(bytes, off + 12); }
public static void littleEndianToInt(byte[] bs, int bOff, int[] ns, int nOff, int count) { for (int i = 0; i < count; ++i) { ns[nOff + i] = littleEndianToInt(bs, bOff); bOff += 4; } }
protected void setKey(byte[] keyBytes, byte[] ivBytes) { if (keyBytes != null) { if ((keyBytes.length != 16) && (keyBytes.length != 32)) { throw new IllegalArgumentException(getAlgorithmName() + " requires 128 bit or 256 bit key"); } int tsOff = (keyBytes.length - 16) / 4; engineState[0 ] = TAU_SIGMA[tsOff ]; engineState[5 ] = TAU_SIGMA[tsOff + 1]; engineState[10] = TAU_SIGMA[tsOff + 2]; engineState[15] = TAU_SIGMA[tsOff + 3]; // Key Pack.littleEndianToInt(keyBytes, 0, engineState, 1, 4); Pack.littleEndianToInt(keyBytes, keyBytes.length - 16, engineState, 11, 4); } // IV Pack.littleEndianToInt(ivBytes, 0, engineState, 6, 2); }
protected void setKey(byte[] keyBytes, byte[] ivBytes) { if (keyBytes != null) { if ((keyBytes.length != 16) && (keyBytes.length != 32)) { throw new IllegalArgumentException(getAlgorithmName() + " requires 128 bit or 256 bit key"); } packTauOrSigma(keyBytes.length, engineState, 0); // Key Pack.littleEndianToInt(keyBytes, 0, engineState, 4, 4); Pack.littleEndianToInt(keyBytes, keyBytes.length - 16, engineState, 8, 4); } // IV Pack.littleEndianToInt(ivBytes, 0, engineState, 14, 2); }
protected void setKey(byte[] keyBytes, byte[] ivBytes) { if (keyBytes != null) { if (keyBytes.length != 32) { throw new IllegalArgumentException(getAlgorithmName() + " requires 256 bit key"); } packTauOrSigma(keyBytes.length, engineState, 0); // Key Pack.littleEndianToInt(keyBytes, 0, engineState, 4, 8); } // IV Pack.littleEndianToInt(ivBytes, 0, engineState, 13, 3); }
int t0 = Pack.littleEndianToInt(key, 0); int t1 = Pack.littleEndianToInt(key, 4); int t2 = Pack.littleEndianToInt(key, 8); int t3 = Pack.littleEndianToInt(key, 12); k0 = Pack.littleEndianToInt(kBytes, kOff + 0); k1 = Pack.littleEndianToInt(kBytes, kOff + 4); k2 = Pack.littleEndianToInt(kBytes, kOff + 8); k3 = Pack.littleEndianToInt(kBytes, kOff + 12);
void chacha_permute(byte[] out, byte[] in) { int i; int[] x = new int[16]; for (i = 0; i < 16; i++) { x[i] = Pack.littleEndianToInt(in, 4 * i); } permute(CHACHA_ROUNDS, x); // for (i = 0;i < 16;++i) x[i] = PLUS(x[i],input[i]); // XXX: Bad idea if we later xor the input to the state? for (i = 0; i < 16; ++i) { Pack.intToLittleEndian(x[i], out, 4 * i); } } }
int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; int t6 = Pack.littleEndianToInt(key, 24); W[1][2] = t6; int t7 = Pack.littleEndianToInt(key, 28); W[1][3] = t7;
int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; int t0 = Pack.littleEndianToInt(key, 0); W[0][0] = t0; int t1 = Pack.littleEndianToInt(key, 4); W[0][1] = t1; int t2 = Pack.littleEndianToInt(key, 8); W[0][2] = t2; int t3 = Pack.littleEndianToInt(key, 12); W[0][3] = t3; int t4 = Pack.littleEndianToInt(key, 16); W[1][0] = t4; int t5 = Pack.littleEndianToInt(key, 20); W[1][1] = t5; int t6 = Pack.littleEndianToInt(key, 24); W[1][2] = t6; int t7 = Pack.littleEndianToInt(key, 28); W[1][3] = t7;
Pack.littleEndianToInt(ivBytes, 8, engineState, 8, 2); Pack.littleEndianToInt(ivBytes, 16, engineState, 6, 2);
private static byte[] mfcrypt(byte[] P, byte[] S, final int N, final int r, int p, int dkLen) throws InterruptedException, ExecutionException { int MFLenBytes = r * 128; byte[] bytes = singleIterationPBKDF2(P, S, p * MFLenBytes); int[] B = null; try { int BLen = bytes.length >>> 2; B = new int[BLen]; Pack.littleEndianToInt(bytes, 0, B); int MFLenWords = MFLenBytes >>> 2; ArrayList<Future<int[]>> futures = new ArrayList<>(); final int BCount = r * 32; for (int BOff = 0; BOff < BLen; BOff += MFLenWords) { final int[] X = new int[BCount]; System.arraycopy(B, BOff, X, 0, BCount); futures.add(THREAD_POOL_EXECUTOR.submit(() -> { sMix(X, N, r); return X; })); } for (int BOff = 0, i = 0; BOff < BLen; BOff += MFLenWords, i++) { System.arraycopy(futures.get(i).get(), 0, B, BOff, BCount); } Pack.intToLittleEndian(B, bytes, 0); return singleIterationPBKDF2(P, bytes, dkLen); } finally { clear(bytes); clear(B); } }
for (i = 0; i < t.length; i+=4) results[i >>> 2] = Pack.littleEndianToInt(t, i);
private static byte[] MFcrypt(byte[] P, byte[] S, int N, int r, int p, int dkLen) { int MFLenBytes = r * 128; byte[] bytes = SingleIterationPBKDF2(P, S, p * MFLenBytes); int[] B = null; try { int BLen = bytes.length >>> 2; B = new int[BLen]; Pack.littleEndianToInt(bytes, 0, B); int MFLenWords = MFLenBytes >>> 2; for (int BOff = 0; BOff < BLen; BOff += MFLenWords) { // TODO These can be done in parallel threads SMix(B, BOff, N, r); } Pack.intToLittleEndian(B, bytes, 0); return SingleIterationPBKDF2(P, bytes, dkLen); } finally { Clear(bytes); Clear(B); } }
final long t0 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 0); final long t1 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 4); final long t2 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 8); final long t3 = 0xffffffffL & Pack.littleEndianToInt(currentBlock, 12);
private static byte[] cryptoProDiversify(byte[] K, byte[] ukm, byte[] sBox) { for (int i = 0; i != 8; i++) { int sOn = 0; int sOff = 0; for (int j = 0; j != 8; j++) { int kj = Pack.littleEndianToInt(K, j * 4); if (bitSet(ukm[i], j)) { sOn += kj; } else { sOff += kj; } } byte[] s = new byte[8]; Pack.intToLittleEndian(sOn, s, 0); Pack.intToLittleEndian(sOff, s, 4); GCFBBlockCipher c = new GCFBBlockCipher(new GOST28147Engine()); c.init(true, new ParametersWithIV(new ParametersWithSBox(new KeyParameter(K), sBox), s)); c.processBlock(K, 0, K, 0); c.processBlock(K, 8, K, 8); c.processBlock(K, 16, K, 16); c.processBlock(K, 24, K, 24); } return K; }
int outOff) X0 = Pack.littleEndianToInt(input, inOff); X1 = Pack.littleEndianToInt(input, inOff + 4); X2 = Pack.littleEndianToInt(input, inOff + 8); X3 = Pack.littleEndianToInt(input, inOff + 12);
int outOff) X0 = wKey[128] ^ Pack.littleEndianToInt(input, inOff); X1 = wKey[129] ^ Pack.littleEndianToInt(input, inOff + 4); X2 = wKey[130] ^ Pack.littleEndianToInt(input, inOff + 8); X3 = wKey[131] ^ Pack.littleEndianToInt(input, inOff + 12);