byte[] toBytes() { byte[] result = new byte[ARGON2_BLOCK_SIZE]; for (int i = 0; i < v.length; i++) { Pack.longToLittleEndian(v[i], result, i * 8); } return result; }
protected byte[] toByteArray() { byte[] byteRepresentation = new byte[32]; Pack.intToBigEndian(layerAddress, byteRepresentation, 0); Pack.longToBigEndian(treeAddress, byteRepresentation, 4); Pack.intToBigEndian(type, byteRepresentation, 12); Pack.intToBigEndian(keyAndMask, byteRepresentation, 28); return byteRepresentation; }
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); }
XTSTweak next() { long lo = Pack.littleEndianToLong(tweak, 0); long hi = Pack.littleEndianToLong(tweak, 8); long fdbk = (hi & MSB) == 0 ? 0L : FDBK; hi = (hi << 1) | (lo >>> 63); lo = (lo << 1) ^ fdbk; Pack.longToLittleEndian(lo, tweak, 0); Pack.longToLittleEndian(hi, tweak, 8); return this; } }
protected GeneralDigest(byte[] encodedState) { System.arraycopy(encodedState, 0, xBuf, 0, xBuf.length); xBufOff = Pack.bigEndianToInt(encodedState, 4); byteCount = Pack.bigEndianToLong(encodedState, 8); }
public static void longToBigEndian(long n, byte[] bs, int off) { intToBigEndian((int)(n >>> 32), bs, off); intToBigEndian((int)(n & 0xffffffffL), bs, off + 4); }
public static byte[] longToBigEndian(long n) { byte[] bs = new byte[8]; longToBigEndian(n, bs, 0); return bs; }
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; } }
private static void xorWithInput(long[] z, byte[] buf, int off) { for (int i = 0; i < z.length; ++i) { z[i] ^= Pack.littleEndianToLong(buf, off); off += 8; } }
public static int[] asInts(byte[] x) { int[] z = new int[4]; Pack.bigEndianToInt(x, 0, z); return z; }
public static long[] asLongs(byte[] x) { long[] z = new long[2]; Pack.bigEndianToLong(x, 0, z); return z; }
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); } } }
public static byte[] intToBigEndian(int[] ns) { byte[] bs = new byte[4 * ns.length]; intToBigEndian(ns, bs, 0); return bs; }
public static void longToBigEndian(long[] ns, byte[] bs, int off) { for (int i = 0; i < ns.length; ++i) { longToBigEndian(ns[i], bs, off); off += 8; } }
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; } }
public static void littleEndianToLong(byte[] bs, int off, long[] ns) { for (int i = 0; i < ns.length; ++i) { ns[i] = littleEndianToLong(bs, off); off += 8; } }
protected GeneralDigest(byte[] encodedState) { System.arraycopy(encodedState, 0, xBuf, 0, xBuf.length); xBufOff = Pack.bigEndianToInt(encodedState, 4); byteCount = Pack.bigEndianToLong(encodedState, 8); }
public static long bigEndianToLong(byte[] bs, int off) { int hi = bigEndianToInt(bs, off); int lo = bigEndianToInt(bs, off + 4); return ((long)(hi & 0xffffffffL) << 32) | (long)(lo & 0xffffffffL); }
public static void bigEndianToLong(byte[] bs, int off, long[] ns) { for (int i = 0; i < ns.length; ++i) { ns[i] = bigEndianToLong(bs, off); off += 8; } }
public static void longToLittleEndian(long[] ns, byte[] bs, int off) { for (int i = 0; i < ns.length; ++i) { longToLittleEndian(ns[i], bs, off); off += 8; } }