@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)); } }
@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 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 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); }
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(); }
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();  }