public byte[] expand(byte[] prk, byte[] info, int length)
        throws InvalidKeyException, NoSuchAlgorithmException {
        Objects.requireNonNull(prk);
        Objects.requireNonNull(info);
        Preconditions.checkArgument(length >= 0, "Negative length");
        Preconditions.checkArgument(length < 255 * getMacLength(), "Length too long");
        Mac mac = getMac(prk);
        int macLength = getMacLength();

        byte[] t = new byte[0];
        byte[] output = new byte[length];
        int outputOffset = 0;
        byte[] counter = new byte[] { 0x00 };
        while (outputOffset < length) {
            counter[0]++;
            mac.update(t);
            mac.update(info);
            t = mac.doFinal(counter);
            int size = Math.min(macLength, length - outputOffset);
            System.arraycopy(t, 0, output, outputOffset, size);
            outputOffset += size;
        }
        return output;
    }
Performs an HKDF expand operation as specified in RFC 5869.

@param prk a pseudorandom key of at least HashLen octets, usually the output from the
           extract step. Where HashLen is the key size of the underlying Mac
@param info optional context and application specific information, can be zero length
@param length length of output keying material in bytes (<= 255*HashLen)
@return output of keying material of length bytes
@throws InvalidKeyException if prk is not suitable for use as an HMAC key
@throws IllegalArgumentException if length is out of the allowed range
@throws NoSuchAlgorithmException if the Mac algorithm is no longer available
common/src/main/java/org/conscrypt/Hkdf.java