@Test public void getPrimitive_works() throws Exception { AesCmacPrfKeyManager manager = new AesCmacPrfKeyManager(); AesCmacPrfKey validKey = manager.keyFactory().createKey(makeAesCmacPrfKeyFormat(32)); PrfSet managerPrf = manager.getPrimitive(validKey, PrfSet.class); Prf directPrf = new PrfAesCmac(validKey.getKeyValue().toByteArray()); byte[] message = Random.randBytes(50); assertThat(managerPrf.computePrimary(message, 16)).isEqualTo(directPrf.compute(message, 16)); }
@Override public KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey> keyFactory() { return new KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey>(AesCmacPrfKeyFormat.class) { @Override public void validateKeyFormat(AesCmacPrfKeyFormat format) throws GeneralSecurityException { validateSize(format.getKeySize()); } @Override public AesCmacPrfKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacPrfKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacPrfKey createKey(AesCmacPrfKeyFormat format) { return AesCmacPrfKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .build(); } }; }
AesCmacPrfKeyManager extends KeyTypeManager<AesCmacPrfKey> { @Override public KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey> keyFactory() { return new KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey>(AesCmacPrfKeyFormat.class) { @Override public void validateKeyFormat(AesCmacPrfKeyFormat format) throws GeneralSecurityException { validateSize(format.getKeySize()); } @Override public AesCmacPrfKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacPrfKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacPrfKey createKey(AesCmacPrfKeyFormat format) { return AesCmacPrfKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .build(); } }; } }
AesCmacPrfKeyManager extends KeyTypeManager<AesCmacPrfKey> { @Override public KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey> keyFactory() { return new KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey>(AesCmacPrfKeyFormat.class) { @Override public void validateKeyFormat(AesCmacPrfKeyFormat format) throws GeneralSecurityException { validateSize(format.getKeySize()); } @Override public AesCmacPrfKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacPrfKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacPrfKey createKey(AesCmacPrfKeyFormat format) { return AesCmacPrfKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .build(); } }; } AesCmacPrfKeyManager(); }
AesCmacPrfKeyManager extends KeyTypeManager<AesCmacPrfKey> { @Override public KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey> keyFactory() { return new KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey>(AesCmacPrfKeyFormat.class) { @Override public void validateKeyFormat(AesCmacPrfKeyFormat format) throws GeneralSecurityException { validateSize(format.getKeySize()); } @Override public AesCmacPrfKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacPrfKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacPrfKey createKey(AesCmacPrfKeyFormat format) { return AesCmacPrfKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .build(); } }; } AesCmacPrfKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(AesCmacPrfKey key); @Override AesCmacPrfKey parseKey(ByteString byteString); @Override KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate aes256CmacTemplate(); }
AesCmacPrfKeyManager extends KeyTypeManager<AesCmacPrfKey> { @Override public KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey> keyFactory() { return new KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey>(AesCmacPrfKeyFormat.class) { @Override public void validateKeyFormat(AesCmacPrfKeyFormat format) throws GeneralSecurityException { validateSize(format.getKeySize()); } @Override public AesCmacPrfKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacPrfKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacPrfKey createKey(AesCmacPrfKeyFormat format) { return AesCmacPrfKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .build(); } }; } AesCmacPrfKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(AesCmacPrfKey key); @Override AesCmacPrfKey parseKey(ByteString byteString); @Override KeyFactory<AesCmacPrfKeyFormat, AesCmacPrfKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate aes256CmacTemplate();  }