Pack.intToBigEndian(counterStart, C, 0); Pack.intToBigEndian(counterBase, C, 0);
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; }
public static byte[] longToLittleEndian(long[] ns) { byte[] bs = new byte[8 * ns.length]; longToLittleEndian(ns, bs, 0); return bs; }
protected byte[] getLengthTag(byte[] p2) { byte[] L2 = new byte[8]; if (p2 != null) { Pack.longToBigEndian(p2.length * 8L, L2, 0); } return L2; } }
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); } } }
private void InvShiftRows() { int row, col; int shift = -1; Pack.longToLittleEndian(internalState, internalStateBytes, 0); for (row = 0; row < BITS_IN_LONG / BITS_IN_BYTE; row++) { if (row % (BITS_IN_LONG / BITS_IN_BYTE / wordsInBlock) == 0) { shift += 1; } for (col = 0; col < wordsInBlock; col++) { tempInternalStateBytes[row + col * BITS_IN_LONG / BITS_IN_BYTE] = internalStateBytes[row + ((col + shift) % wordsInBlock) * BITS_IN_LONG / BITS_IN_BYTE]; } } Pack.littleEndianToLong(tempInternalStateBytes, 0, internalState); }
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 byte[] intToLittleEndian(int[] ns) { byte[] bs = new byte[4 * ns.length]; intToLittleEndian(ns, bs, 0); return bs; }
public static byte[] shortToLittleEndian(short n) { byte[] bs = new byte[2]; shortToLittleEndian(n, 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; } }
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); } }
private void ShiftRows() { int row, col; int shift = -1; Pack.longToLittleEndian(internalState, internalStateBytes, 0); for (row = 0; row < BITS_IN_LONG / BITS_IN_BYTE; row++) { if (row % (BITS_IN_LONG / BITS_IN_BYTE / wordsInBlock) == 0) { shift += 1; } for (col = 0; col < wordsInBlock; col++) { tempInternalStateBytes[row + ((col + shift) % wordsInBlock) * BITS_IN_LONG / BITS_IN_BYTE] = internalStateBytes[row + col * BITS_IN_LONG / BITS_IN_BYTE]; } } Pack.littleEndianToLong(tempInternalStateBytes, 0, internalState); }
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; }
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 byte[] getEncoded() { PrivateKeyInfo pki; try { AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.newHope); short[] privateKeyData = params.getSecData(); byte[] octets = new byte[privateKeyData.length * 2]; for (int i = 0; i != privateKeyData.length; i++) { Pack.shortToLittleEndian(privateKeyData[i], octets, i * 2); } pki = new PrivateKeyInfo(algorithmIdentifier, new DEROctetString(octets)); return pki.getEncoded(); } catch (IOException e) { return null; } }
Pack.intToBigEndian(P2.length * 8, L2, 0); mac.update(L2, 0, L2.length);
protected void populateState(byte[] state) { System.arraycopy(xBuf, 0, state, 0, xBufOff); Pack.intToBigEndian(xBufOff, state, 4); Pack.longToBigEndian(byteCount, state, 8); }
public static byte[] longToBigEndian(long[] ns) { byte[] bs = new byte[8 * ns.length]; longToBigEndian(ns, bs, 0); return bs; }
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; } }
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); } }