/** * Pack nibbles to binary * * @param nibbles sequence. may have a terminator * @return hex-encoded byte array */ public static byte[] packNibbles(byte[] nibbles) { int terminator = 0; if (nibbles[nibbles.length - 1] == TERMINATOR) { terminator = 1; nibbles = copyOf(nibbles, nibbles.length - 1); } int oddlen = nibbles.length % 2; int flag = 2 * terminator + oddlen; if (oddlen != 0) { byte[] flags = new byte[]{(byte) flag}; nibbles = concatenate(flags, nibbles); } else { byte[] flags = new byte[]{(byte) flag, 0}; nibbles = concatenate(flags, nibbles); } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); for (int i = 0; i < nibbles.length; i += 2) { buffer.write(16 * nibbles[i] + nibbles[i + 1]); } return buffer.toByteArray(); }
byte[] T1 = Arrays.copyOfRange(in_enc, end - mac.getMacSize(), end); if (!Arrays.constantTimeAreEqual(T1, T2)) return Arrays.copyOfRange(M, 0, len);
private static BlockInfo getBlockInfoForHash(List<BlockInfo> blocks, byte[] hash){ for (BlockInfo blockInfo : blocks) if (areEqual(hash, blockInfo.getHash())) return blockInfo; return null; }
public byte[] calcPowValue() { // nonce bytes are expected in Little Endian order, reverting byte[] nonceReverted = Arrays.reverse(nonce); byte[] hashWithoutNonce = HashUtil.sha3(getEncodedWithoutNonce()); byte[] seed = Arrays.concatenate(hashWithoutNonce, nonceReverted); byte[] seedHash = HashUtil.sha512(seed); byte[] concat = Arrays.concatenate(seedHash, mixHash); return HashUtil.sha3(concat); }
protected static byte[] derForm(byte[] data, int padBits) { byte[] rv = Arrays.clone(data); // DER requires pad bits be zero if (padBits > 0) { rv[data.length - 1] &= 0xff << padBits; } return rv; }
public final int[] calcDatasetItem(final int[] cache, final int i) { final int r = params.getHASH_BYTES() / params.getWORD_BYTES(); final int n = cache.length / r; int[] mix = Arrays.copyOfRange(cache, i % n * r, (i % n + 1) * r); mix[0] = i ^ mix[0]; mix = sha512(mix, false); final int dsParents = (int) params.getDATASET_PARENTS(); final int mixLen = mix.length; for (int j = 0; j < dsParents; j++) { int cacheIdx = fnv(i ^ j, mix[j % r]); cacheIdx = remainderUnsigned(cacheIdx, n); int off = cacheIdx * r; for (int k = 0; k < mixLen; k++) { mix[k] = fnv(mix[k], cache[off + k]); } } return sha512(mix, false); }
@Override public int hashCode() { return Arrays.hashCode(getHash()); } }
private boolean checkCMSKeyChecksum( byte[] key, byte[] checksum) { return Arrays.constantTimeAreEqual(calculateCMSKeyChecksum(key), checksum); } }
public static ECField convertField(FiniteField field) { if (ECAlgorithms.isFpField(field)) { return new ECFieldFp(field.getCharacteristic()); } else //if (ECAlgorithms.isF2mField(curveField)) { Polynomial poly = ((PolynomialExtensionField)field).getMinimalPolynomial(); int[] exponents = poly.getExponentsPresent(); int[] ks = Arrays.reverse(Arrays.copyOfRange(exponents, 1, exponents.length - 1)); return new ECFieldF2m(poly.getDegree(), ks); } }
protected byte[] truncate(byte[] bs) { if (bs.length <= macLength) { return bs; } return Arrays.copyOf(bs, macLength); } }
/** * Return the current state of the initialisation vector. * * @return current IV */ public byte[] getCurrentIV() { return Arrays.clone(cfbV); }
this.V = Arrays.copyOfRange(in, inOff, inOff + encLength);
public int hashCode() { return Arrays.hashCode(exponents); } }
/** * For details see http://www.w3.org/TR/xmlenc-core/#sec-CMSKeyChecksum * * @param key key to be validated. * @param checksum the checksum. * @return true if okay, false otherwise. */ private boolean checkCMSKeyChecksum( byte[] key, byte[] checksum) { return Arrays.constantTimeAreEqual(calculateCMSKeyChecksum(key), checksum); }
public void clear() { if (this.masterSecret != null) { Arrays.fill(this.masterSecret, (byte)0); } }
public BigInteger[] getKnowledgeProofForX2() { return Arrays.copyOf(knowledgeProofForX2, knowledgeProofForX2.length); }
public PopLinkWitnessV2(AlgorithmIdentifier keyGenAlgorithm, AlgorithmIdentifier macAlgorithm, byte[] witness) { this.keyGenAlgorithm = keyGenAlgorithm; this.macAlgorithm = macAlgorithm; this.witness = Arrays.clone(witness); }
/** * Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTH */ public static byte[] encodeLength(int length, int offset) { if (length < SIZE_THRESHOLD) { byte firstByte = (byte) (length + offset); return new byte[]{firstByte}; } else if (length < MAX_ITEM_LENGTH) { byte[] binaryLength; if (length > 0xFF) binaryLength = intToBytesNoLeadZeroes(length); else binaryLength = new byte[]{(byte) length}; byte firstByte = (byte) (binaryLength.length + offset + SIZE_THRESHOLD - 1); return concatenate(new byte[]{firstByte}, binaryLength); } else { throw new RuntimeException("Input too long"); } }