PrfHmacJce implements Prf { @Override public byte[] compute(byte[] data, int outputLength) throws GeneralSecurityException { if (outputLength > maxOutputLength) { throw new InvalidAlgorithmParameterException("tag size too big"); } localMac.get().update(data); return Arrays.copyOf(localMac.get().doFinal(), outputLength); } PrfHmacJce(String algorithm, java.security.Key key); @Override byte[] compute(byte[] data, int outputLength); int getMaxOutputLength();  }
@Test public void testPrfUniformity() throws GeneralSecurityException { for (MacTestVector t : HMAC_TEST_VECTORS) { Prf prf = new PrfHmacJce(t.algName, new SecretKeySpec(t.key, "HMAC")); byte[] prBytes = prf.compute(t.tag, t.tag.length); TestUtil.ztestUniformString(prBytes); TestUtil.ztestAutocorrelationUniformString(prBytes); TestUtil.ztestCrossCorrelationUniformStrings(prBytes, t.tag); } }
@Test public void testPrfPrefixOfMac() throws Exception { for (MacTestVector t : HMAC_TEST_VECTORS) { Prf prf = new PrfHmacJce(t.algName, new SecretKeySpec(t.key, "HMAC")); Mac mac = new PrfMac(prf, t.tag.length); byte[] prBytes = prf.compute(t.message, t.tag.length - 1); byte[] tag = mac.computeMac(t.message); assertEquals(prBytes.length, t.tag.length - 1); assertArrayEquals(prBytes, Arrays.copyOf(tag, prBytes.length)); } }