@Test public void testDoPrfProducesDataOfCorrectLength() { SecretKey secret = new SecretKeySpec("secret".getBytes(), "MAC"); byte[] seed = "seed".getBytes(); byte[] data = PseudoRandomFunction.doPRF(hmac, secret, Label.MASTER_SECRET_LABEL, seed); assertThat(data.length, is(Label.MASTER_SECRET_LABEL.length())); data = PseudoRandomFunction.doPRF(hmac, secret, Label.KEY_EXPANSION_LABEL, seed); assertThat(data.length, is(Label.KEY_EXPANSION_LABEL.length())); data = PseudoRandomFunction.doPRF(hmac, secret, Label.CLIENT_FINISHED_LABEL, seed); assertThat(data.length, is(Label.CLIENT_FINISHED_LABEL.length())); data = PseudoRandomFunction.doPRF(hmac, secret, Label.SERVER_FINISHED_LABEL, seed); assertThat(data.length, is(Label.SERVER_FINISHED_LABEL.length())); }
static byte[] doPRF(Mac hmac, SecretKey secret, byte[] label, byte[] seed, int length) { try { hmac.init(secret); byte[] prf = doExpansion(hmac, label, seed, length); hmac.reset(); return prf; } catch (InvalidKeyException e) { throw new IllegalArgumentException("Cannot run Pseudo Random Function with invalid key", e); } }
PseudoRandomFunction { static byte[] doPRF(Mac hmac, SecretKey secret, byte[] label, byte[] seed, int length) { try { hmac.init(secret); byte[] prf = doExpansion(hmac, label, seed, length); hmac.reset(); return prf; } catch (InvalidKeyException e) { throw new IllegalArgumentException("Cannot run Pseudo Random Function with invalid key", e); } } }
PseudoRandomFunction { static byte[] doPRF(Mac hmac, SecretKey secret, byte[] label, byte[] seed, int length) { try { hmac.init(secret); byte[] prf = doExpansion(hmac, label, seed, length); hmac.reset(); return prf; } catch (InvalidKeyException e) { throw new IllegalArgumentException("Cannot run Pseudo Random Function with invalid key", e); } } private  PseudoRandomFunction(); }
PseudoRandomFunction { static byte[] doPRF(Mac hmac, SecretKey secret, byte[] label, byte[] seed, int length) { try { hmac.init(secret); byte[] prf = doExpansion(hmac, label, seed, length); hmac.reset(); return prf; } catch (InvalidKeyException e) { throw new IllegalArgumentException("Cannot run Pseudo Random Function with invalid key", e); } } private  PseudoRandomFunction(); static final byte[] doPRF(Mac hmac, SecretKey secret, Label label, byte[] seed); static final byte[] doPRF(Mac hmac, SecretKey secret, Label label, byte[] seed, int length); static SecretKey generateMasterSecret(Mac hmac, SecretKey premasterSecret, byte[] seed); static SecretKey generatePremasterSecretFromPSK(SecretKey otherSecret, SecretKey pskSecret); }
PseudoRandomFunction { static byte[] doPRF(Mac hmac, SecretKey secret, byte[] label, byte[] seed, int length) { try { hmac.init(secret); byte[] prf = doExpansion(hmac, label, seed, length); hmac.reset(); return prf; } catch (InvalidKeyException e) { throw new IllegalArgumentException("Cannot run Pseudo Random Function with invalid key", e); } } private  PseudoRandomFunction(); static final byte[] doPRF(Mac hmac, SecretKey secret, Label label, byte[] seed); static final byte[] doPRF(Mac hmac, SecretKey secret, Label label, byte[] seed, int length); static SecretKey generateMasterSecret(Mac hmac, SecretKey premasterSecret, byte[] seed); static SecretKey generatePremasterSecretFromPSK(SecretKey otherSecret, SecretKey pskSecret);  }