private static void validate(final int[] wordIndexes) throws InvalidWordCountException, InvalidChecksumException { final int ms = wordIndexes.length; final int entPlusCs = ms * 11; final int ent = (entPlusCs * 32) / 33; final int cs = ent / 32; if (entPlusCs != ent + cs) throw new InvalidWordCountException(); final byte[] entropyWithChecksum = new byte[(entPlusCs + 7) / 8]; wordIndexesToEntropyWithCheckSum(wordIndexes, entropyWithChecksum); Arrays.fill(wordIndexes, 0); final byte[] entropy = Arrays.copyOf(entropyWithChecksum, entropyWithChecksum.length - 1); final byte lastByte = entropyWithChecksum[entropyWithChecksum.length - 1]; Arrays.fill(entropyWithChecksum, (byte) 0); final byte sha = firstByteOfSha256(entropy); final byte mask = maskOfFirstNBits(cs); if (((sha ^ lastByte) & mask) != 0) throw new InvalidChecksumException(); }
private static void validate(final int[] wordIndexes) throws InvalidWordCountException, InvalidChecksumException { final int ms = wordIndexes.length; final int entPlusCs = ms * 11; final int ent = (entPlusCs * 32) / 33; final int cs = ent / 32; if (entPlusCs != ent + cs) throw new InvalidWordCountException(); final byte[] entropyWithChecksum = new byte[(entPlusCs + 7) / 8]; wordIndexesToEntropyWithCheckSum(wordIndexes, entropyWithChecksum); Arrays.fill(wordIndexes, 0); final byte[] entropy = Arrays.copyOf(entropyWithChecksum, entropyWithChecksum.length - 1); final byte lastByte = entropyWithChecksum[entropyWithChecksum.length - 1]; Arrays.fill(entropyWithChecksum, (byte) 0); final byte sha = firstByteOfSha256(entropy); final byte mask = maskOfFirstNBits(cs); if (((sha ^ lastByte) & mask) != 0) throw new InvalidChecksumException(); }