/** * Creates a new {@code HKDF} instance. * * @param algorithm the MAC algorithm to use. * @param info optional context and application specific information, may be {@code null} or * empty. * @param dkLen the desired length for derived keys, in bytes. * @throws NullPointerException if {@code algorithm} is {@code null}. * @throws IllegalArgumentException if {@code dkLen} is negative, or if the MAC algorithm is * unknown, or if {@code dkLen} is greater than 255 * MAC algorithm's output length. */ HKDF(Algorithm<MAC> algorithm, byte[] info, int dkLen) { Parameters.checkCondition(dkLen > 0); MAC mac = Factory.newMAC(algorithm, new byte[0]); Parameters.checkCondition(dkLen <= 255 * mac.length()); this.algorithm = algorithm; this.dkLen = dkLen; this.info = info == null ? new byte[0] : XArrays.copyOf(info); }
@Override public long skip(long n) { Parameters.checkCondition(n >= 0); if (finished()) { return 0; } long skipped = n; if (n > in.length() - index) { skipped = in.length() - index; } index += skipped; return skipped; }
/** * Marks the current position in the stream. Subsequent calls to reset() will reposition the * stream to this point. * * @param readLimit limit on the number of characters that may be read while still preserving the * mark. Because the stream's input comes from {@code String}s, there is no actual limit, so * this argument must not be negative, but is otherwise ignored. * @throws IllegalArgumentException if {@code readLimit} is negative. */ @Override public void mark(int readLimit) { Parameters.checkCondition(readLimit >= 0); mark = index; }