@Test public void testComputeForTls11() throws CryptoException { byte[] secret = new byte[48]; String label = "master secret"; byte[] seed = new byte[60]; Random r = new Random(); r.nextBytes(seed); int size = 48; byte[] result1 = TlsUtils.PRF_legacy(secret, label, seed, size); byte[] result2 = PseudoRandomFunction.compute(PRFAlgorithm.TLS_PRF_LEGACY, secret, label, seed, size); assertArrayEquals(result1, result2); }
public static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size) throws CryptoException { if (prfAlgorithm == null) { LOGGER.warn("Trying to compute PRF without specified PRF algorithm. Using TLS 1.0/TLS 1.1 as default."); prfAlgorithm = PRFAlgorithm.TLS_PRF_LEGACY; } switch (prfAlgorithm) { case TLS_PRF_SHA256: case TLS_PRF_SHA384: case TLS_PRF_GOSTR3411: case TLS_PRF_GOSTR3411_2012_256: return computeTls12(secret, label, seed, size, prfAlgorithm.getMacAlgorithm().getJavaName()); case TLS_PRF_LEGACY: return TlsUtils.PRF_legacy(secret, label, seed, size); default: throw new UnsupportedOperationException("PRF computation for different" + " protocol versions is not supported yet"); } }
PseudoRandomFunction { public static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size) throws CryptoException { if (prfAlgorithm == null) { LOGGER.warn("Trying to compute PRF without specified PRF algorithm. Using TLS 1.0/TLS 1.1 as default."); prfAlgorithm = PRFAlgorithm.TLS_PRF_LEGACY; } switch (prfAlgorithm) { case TLS_PRF_SHA256: case TLS_PRF_SHA384: case TLS_PRF_GOSTR3411: case TLS_PRF_GOSTR3411_2012_256: return computeTls12(secret, label, seed, size, prfAlgorithm.getMacAlgorithm().getJavaName()); case TLS_PRF_LEGACY: return TlsUtils.PRF_legacy(secret, label, seed, size); default: throw new UnsupportedOperationException("PRF computation for different" + " protocol versions is not supported yet"); } } }
PseudoRandomFunction { public static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size) throws CryptoException { if (prfAlgorithm == null) { LOGGER.warn("Trying to compute PRF without specified PRF algorithm. Using TLS 1.0/TLS 1.1 as default."); prfAlgorithm = PRFAlgorithm.TLS_PRF_LEGACY; } switch (prfAlgorithm) { case TLS_PRF_SHA256: case TLS_PRF_SHA384: case TLS_PRF_GOSTR3411: case TLS_PRF_GOSTR3411_2012_256: return computeTls12(secret, label, seed, size, prfAlgorithm.getMacAlgorithm().getJavaName()); case TLS_PRF_LEGACY: return TlsUtils.PRF_legacy(secret, label, seed, size); default: throw new UnsupportedOperationException("PRF computation for different" + " protocol versions is not supported yet"); } } private  PseudoRandomFunction(); }
PseudoRandomFunction { public static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size) throws CryptoException { if (prfAlgorithm == null) { LOGGER.warn("Trying to compute PRF without specified PRF algorithm. Using TLS 1.0/TLS 1.1 as default."); prfAlgorithm = PRFAlgorithm.TLS_PRF_LEGACY; } switch (prfAlgorithm) { case TLS_PRF_SHA256: case TLS_PRF_SHA384: case TLS_PRF_GOSTR3411: case TLS_PRF_GOSTR3411_2012_256: return computeTls12(secret, label, seed, size, prfAlgorithm.getMacAlgorithm().getJavaName()); case TLS_PRF_LEGACY: return TlsUtils.PRF_legacy(secret, label, seed, size); default: throw new UnsupportedOperationException("PRF computation for different" + " protocol versions is not supported yet"); } } private  PseudoRandomFunction(); static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size); }
PseudoRandomFunction { public static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size) throws CryptoException { if (prfAlgorithm == null) { LOGGER.warn("Trying to compute PRF without specified PRF algorithm. Using TLS 1.0/TLS 1.1 as default."); prfAlgorithm = PRFAlgorithm.TLS_PRF_LEGACY; } switch (prfAlgorithm) { case TLS_PRF_SHA256: case TLS_PRF_SHA384: case TLS_PRF_GOSTR3411: case TLS_PRF_GOSTR3411_2012_256: return computeTls12(secret, label, seed, size, prfAlgorithm.getMacAlgorithm().getJavaName()); case TLS_PRF_LEGACY: return TlsUtils.PRF_legacy(secret, label, seed, size); default: throw new UnsupportedOperationException("PRF computation for different" + " protocol versions is not supported yet"); } } private  PseudoRandomFunction(); static byte[] compute(PRFAlgorithm prfAlgorithm, byte[] secret, String label, byte[] seed, int size); static final String MASTER_SECRET_LABEL; static final String CLIENT_FINISHED_LABEL; static final String SERVER_FINISHED_LABEL; static final String KEY_EXPANSION_LABEL; static final String EXTENDED_MASTER_SECRET_LABEL; static final String CLIENT_WRITE_KEY_LABEL; static final String SERVER_WRITE_KEY_LABEL; static final String IV_BLOCK_LABEL; }