private void KeccakExtract() { Pack.longToLittleEndian(state, 0, rate >> 6, dataQueue, 0); }
public static byte[] longToLittleEndian(long[] ns) { byte[] bs = new byte[8 * ns.length]; longToLittleEndian(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; } }
public static void longToLittleEndian(long[] ns, int nsOff, int nsLen, byte[] bs, int bsOff) { for (int i = 0; i < nsLen; ++i) { longToLittleEndian(ns[nsOff + i], bs, bsOff); bsOff += 8; } } }
public static byte[] longToLittleEndian(long n) { byte[] bs = new byte[8]; longToLittleEndian(n, bs, 0); return bs; }
private byte[] pad(byte[] in, int inOff, int len) { byte[] padded; if (blockSize - len < 13) // terminator byte + 96 bits of length { padded = new byte[2 * blockSize]; } else { padded = new byte[blockSize]; } System.arraycopy(in, inOff, padded, 0, len); padded[len] = (byte)0x80; // Defined in standard; // Defined in standard; Pack.longToLittleEndian(inputLength * BITS_IN_BYTE, padded, padded.length - 12); return padded; }
protected void updateRecordMACLength(Mac mac, int len) { byte[] longLen = Pack.longToLittleEndian(len & 0xFFFFFFFFL); mac.update(longLen, 0, longLen.length); }
private static byte[] generateNonceIVPersonalizationString(byte[] seed) { return Arrays.concatenate(Strings.toByteArray("Nonce"), seed, Pack.longToLittleEndian(Thread.currentThread().getId()), Pack.longToLittleEndian(System.currentTimeMillis())); }
private void RotateLeft(long[] value) { int rotateBytesLength = 2 * value.length + 3; int bytesLength = value.length * (BITS_IN_WORD / BITS_IN_BYTE); byte[] bytes = new byte[value.length * BITS_IN_LONG / BITS_IN_BYTE]; Pack.longToLittleEndian(value, bytes, 0); byte[] buffer = new byte[rotateBytesLength]; System.arraycopy(bytes, 0, buffer, 0, rotateBytesLength); System.arraycopy(bytes, rotateBytesLength, bytes, 0, bytesLength - rotateBytesLength); System.arraycopy(buffer, 0, bytes, bytesLength - rotateBytesLength, rotateBytesLength); Pack.littleEndianToLong(bytes, 0, value); }
public int doFinal(byte[] out, int outOff) throws DataLengthException, IllegalStateException { long result = doFinal(); Pack.longToLittleEndian(result, out, outOff); return 8; }
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); }
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); }
static void get_seed(HashFunctions hs, byte[] seed, int seedOff, byte[] sk, Tree.leafaddr a) { byte[] buffer = new byte[SPHINCS256Config.SEED_BYTES + 8]; long t; int i; for (i = 0; i < SPHINCS256Config.SEED_BYTES; i++) { buffer[i] = sk[i]; } //4 bits to encode level t = a.level; //55 bits to encode subtree t |= a.subtree << 4; //5 bits to encode leaf t |= a.subleaf << 59; Pack.longToLittleEndian(t, buffer, SPHINCS256Config.SEED_BYTES); hs.varlen_hash(seed, seedOff, buffer, buffer.length); }
private void MixColumns(byte[][] matrix) { int col, row, b; byte product; long result; Pack.longToLittleEndian(internalState, internalStateBytes, 0); long shift; for (col = 0; col < wordsInBlock; ++col) { result = 0; shift = 0xFF00000000000000L; for (row = BITS_IN_LONG / BITS_IN_BYTE - 1; row >= 0; --row) { product = 0; for (b = BITS_IN_LONG / BITS_IN_BYTE - 1; b >= 0; --b) { product ^= MultiplyGF(internalStateBytes[b + col * BITS_IN_LONG / BITS_IN_BYTE], matrix[row][b]); } result |= ((long)product << (row * BITS_IN_LONG / BITS_IN_BYTE) & shift); shift >>>= 8; } internalState[col] = result; } }
private void processBlock(byte[] input, int inOff, byte[] output, int outOff) { /* * A somewhat arbitrary limit of 2^32 - 1 blocks */ if (counter == -1) { throw new IllegalStateException("Attempt to process too many blocks"); } ++counter; /* * Multiply tweak by 'alpha', which is just 2 */ GF_double(reductionPolynomial, tw_current); byte[] tweak = new byte[blockSize]; Pack.longToLittleEndian(tw_current, tweak, 0); byte[] buffer = new byte[blockSize]; System.arraycopy(tweak, 0, buffer, 0, blockSize); for (int i = 0; i < blockSize; ++i) { buffer[i] ^= input[inOff + i]; } cipher.processBlock(buffer, 0, buffer, 0); for (int i = 0; i < blockSize; ++i) { output[outOff + i] = (byte)(buffer[i] ^ tweak[i]); } }
private void finish() { Pack.longToLittleEndian(byteCount * 8, L, 0); // get length into L (byteCount * 8 = bitCount) while (xBufOff != 0) { update((byte)0); } processBlock(L, 0); processBlock(Sum, 0); }
Pack.longToLittleEndian(additionalData.length & 0xFFFFFFFFL, lengths, 0); Pack.longToLittleEndian(ciphertextLength & 0xFFFFFFFFL, lengths, 8); mac.update(lengths, 0, 16); Pack.longToLittleEndian(additionalData.length & 0xFFFFFFFFL, calculatedMAC, 0); Pack.longToLittleEndian(ciphertextLength & 0xFFFFFFFFL, calculatedMAC, 8); mac.update(calculatedMAC, 0, 16); mac.doFinal(calculatedMAC, 0);
Pack.longToLittleEndian(additionalDataLength & 0xFFFFFFFFL, lengths, 0); Pack.longToLittleEndian(ciphertextLength & 0xFFFFFFFFL, lengths, 8); mac.update(lengths, 0, 16); Pack.longToLittleEndian(additionalDataLength & 0xFFFFFFFFL, calculatedMAC, 0); Pack.longToLittleEndian(ciphertextLength & 0xFFFFFFFFL, calculatedMAC, 8); mac.update(calculatedMAC, 0, 16); mac.doFinal(calculatedMAC, 0);
private void pad() { int extra = engine.getByteLength() - (int)(inputLength % engine.getByteLength()); if (extra < 13) // terminator byte + 96 bits of length { extra += engine.getByteLength(); } byte[] padded = new byte[extra]; padded[0] = (byte)0x80; // Defined in standard; // Defined in standard; Pack.longToLittleEndian(inputLength * BITS_IN_BYTE, padded, padded.length - 12); engine.update(padded, 0, padded.length); }
Pack.longToLittleEndian(tempLongBuffer[columnIndex], tempState2[columnIndex], 0);