HKDFunction { public static byte[] deriveSecret(HKDFAlgorithm hkdfAlgortihm, String hashAlgorithm, byte[] prk, String labelIn, byte[] toHash) throws CryptoException { try { MessageDigest hashFunction = MessageDigest.getInstance(hashAlgorithm); hashFunction.update(toHash); byte[] hashValue = hashFunction.digest(); int outLen = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName()).getMacLength(); return expandLabel(hkdfAlgortihm, prk, labelIn, hashValue, outLen); } catch (NoSuchAlgorithmException ex) { throw new CryptoException("Could not initialize HKDF", ex); } } private  HKDFunction(); static byte[] extract(HKDFAlgorithm hkdfAlgortihm, byte[] salt, byte[] ikm); static byte[] expand(HKDFAlgorithm hkdfAlgortihm, byte[] prk, byte[] info, int outLen); static byte[] deriveSecret(HKDFAlgorithm hkdfAlgortihm, String hashAlgorithm, byte[] prk, String labelIn,
            byte[] toHash); static byte[] expandLabel(HKDFAlgorithm hkdfAlgortihm, byte[] prk, String labelIn, byte[] hashValue,
            int outLen); static final String KEY; static final String IV; static final String FINISHED; static final String DERIVED; static final String BINDER_KEY_EXT; static final String BINDER_KEY_RES; static final String CLIENT_EARLY_TRAFFIC_SECRET; static final String EARLY_EXPORTER_MASTER_SECRET; static final String CLIENT_HANDSHAKE_TRAFFIC_SECRET; static final String SERVER_HANDSHAKE_TRAFFIC_SECRET; static final String CLIENT_APPLICATION_TRAFFIC_SECRET; static final String SERVER_APPLICATION_TRAFFIC_SECRET; static final String EXPORTER_MASTER_SECRET; static final String ESNI_IV; static final String ESNI_KEY; static final String RESUMPTION_MASTER_SECRET; static final String RESUMPTION; }
@Test public void testDeriveSecret() throws CryptoException { HKDFAlgorithm hkdfAlgorithm = HKDFAlgorithm.TLS_HKDF_SHA256; String hashAlgorithm = DigestAlgorithm.SHA256.getJavaName(); byte[] prk = ArrayConverter .hexStringToByteArray("33AD0A1C607EC03B09E6CD9893680CE210ADF300AA1F2660E1B22E10F170F92A"); byte[] toHash = ArrayConverter.hexStringToByteArray(""); String labelIn = HKDFunction.DERIVED; byte[] result = HKDFunction.deriveSecret(hkdfAlgorithm, hashAlgorithm, prk, labelIn, toHash); byte[] resultCorrect = ArrayConverter .hexStringToByteArray("6F2615A108C702C5678F54FC9DBAB69716C076189C48250CEBEAC3576C3611BA"); assertArrayEquals(result, resultCorrect); }