private void packBlock(byte[] bytes, int off) { Pack.intToLittleEndian(this.C0, bytes, off); Pack.intToLittleEndian(this.C1, bytes, off + 4); Pack.intToLittleEndian(this.C2, bytes, off + 8); Pack.intToLittleEndian(this.C3, bytes, off + 12); }
private void packBlock(byte[] bytes, int off) { Pack.intToLittleEndian(this.C0, bytes, off); Pack.intToLittleEndian(this.C1, bytes, off + 4); Pack.intToLittleEndian(this.C2, bytes, off + 8); Pack.intToLittleEndian(this.C3, bytes, off + 12); }
public static void intToLittleEndian(int[] ns, byte[] bs, int off) { for (int i = 0; i < ns.length; ++i) { intToLittleEndian(ns[i], bs, off); off += 4; } }
public static void longToLittleEndian(long n, byte[] bs, int off) { intToLittleEndian((int)(n & 0xffffffffL), bs, off); intToLittleEndian((int)(n >>> 32), bs, off + 4); }
public static byte[] intToLittleEndian(int[] ns) { byte[] bs = new byte[4 * ns.length]; intToLittleEndian(ns, bs, 0); return bs; }
public static byte[] intToLittleEndian(int[] ns) { byte[] bs = new byte[4 * ns.length]; intToLittleEndian(ns, bs, 0); return bs; }
public static void longToLittleEndian(long n, byte[] bs, int off) { intToLittleEndian((int)(n & 0xffffffffL), bs, off); intToLittleEndian((int)(n >>> 32), bs, off + 4); }
public static byte[] intToLittleEndian(int n) { byte[] bs = new byte[4]; intToLittleEndian(n, bs, 0); return bs; }
public static void intToLittleEndian(int[] ns, byte[] bs, int off) { for (int i = 0; i < ns.length; ++i) { intToLittleEndian(ns[i], bs, off); off += 4; } }
public static byte[] intToLittleEndian(int n) { byte[] bs = new byte[4]; intToLittleEndian(n, bs, 0); return bs; }
protected void generateKeyStream(byte[] output) { chachaCore(rounds, engineState, x); Pack.intToLittleEndian(x, output, 0); }
protected void generateKeyStream(byte[] output) { ChaChaEngine.chachaCore(rounds, engineState, x); Pack.intToLittleEndian(x, output, 0); } }
protected void generateKeyStream(byte[] output) { chachaCore(rounds, engineState, x); Pack.intToLittleEndian(x, output, 0); }
protected void generateKeyStream(byte[] output) { salsaCore(rounds, engineState, x); Pack.intToLittleEndian(x, output, 0); }
protected void generateKeyStream(byte[] output) { salsaCore(rounds, engineState, x); Pack.intToLittleEndian(x, output, 0); }
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); } } }
/** * (H0 || 0 || i) 72 byte -> 1024 byte * (H0 || 1 || i) 72 byte -> 1024 byte */ private void fillFirstBlocks(byte[] initialHash) { final byte[] zeroBytes = {0, 0, 0, 0}; final byte[] oneBytes = {1, 0, 0, 0}; byte[] initialHashWithZeros = getInitialHashLong(initialHash, zeroBytes); byte[] initialHashWithOnes = getInitialHashLong(initialHash, oneBytes); for (int i = 0; i < parameters.getLanes(); i++) { Pack.intToLittleEndian(i, initialHashWithZeros, ARGON2_PREHASH_DIGEST_LENGTH + 4); Pack.intToLittleEndian(i, initialHashWithOnes, ARGON2_PREHASH_DIGEST_LENGTH + 4); byte[] blockhashBytes = hash(initialHashWithZeros, ARGON2_BLOCK_SIZE); memory[i * laneLength + 0].fromBytes(blockhashBytes); blockhashBytes = hash(initialHashWithOnes, ARGON2_BLOCK_SIZE); memory[i * laneLength + 1].fromBytes(blockhashBytes); } }
private byte[] padKey(byte[] in) { int paddedLen = ((in.length + engine.getByteLength() - 1) / engine.getByteLength()) * engine.getByteLength(); int extra = engine.getByteLength() - (int)(in.length % engine.getByteLength()); if (extra < 13) // terminator byte + 96 bits of length { paddedLen += engine.getByteLength(); } byte[] padded = new byte[paddedLen]; System.arraycopy(in, 0, padded, 0, in.length); padded[in.length] = (byte)0x80; // Defined in standard; Pack.intToLittleEndian(in.length * BITS_IN_BYTE, padded, padded.length - 12); // Defined in standard; return padded; } }
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); } }
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; }