use of com.google.crypto.tink.proto.AesCmacKey in project tink by google.
the class AesCmacKeyManagerTest method validateKey_notValid_throws.
@Test
public void validateKey_notValid_throws() throws Exception {
AesCmacKeyManager manager = new AesCmacKeyManager();
AesCmacKey validKey = manager.keyFactory().createKey(makeAesCmacKeyFormat(32, 16));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(16))).build()));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(64))).build()));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacKey.newBuilder(validKey).setParams(AesCmacParams.newBuilder(validKey.getParams()).setTagSize(0).build()).build()));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacKey.newBuilder(validKey).setParams(AesCmacParams.newBuilder(validKey.getParams()).setTagSize(9).build()).build()));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacKey.newBuilder(validKey).setParams(AesCmacParams.newBuilder(validKey.getParams()).setTagSize(17).build()).build()));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacKey.newBuilder(validKey).setParams(AesCmacParams.newBuilder(validKey.getParams()).setTagSize(32).build()).build()));
}
use of com.google.crypto.tink.proto.AesCmacKey in project tink by google.
the class AesCmacKeyManagerTest method createKey_checkValues.
@Test
public void createKey_checkValues() throws Exception {
AesCmacKeyFormat keyFormat = makeAesCmacKeyFormat(32, 16);
AesCmacKey key = new AesCmacKeyManager().keyFactory().createKey(keyFormat);
assertThat(key.getKeyValue()).hasSize(keyFormat.getKeySize());
assertThat(key.getParams().getTagSize()).isEqualTo(keyFormat.getParams().getTagSize());
}
use of com.google.crypto.tink.proto.AesCmacKey in project tink by google.
the class AesCmacKeyManagerTest method getPrimitive_works.
@Test
public void getPrimitive_works() throws Exception {
AesCmacKeyManager manager = new AesCmacKeyManager();
AesCmacKey validKey = manager.keyFactory().createKey(makeAesCmacKeyFormat(32, 16));
Mac managerMac = manager.getPrimitive(validKey, Mac.class);
Mac directMac = new PrfMac(new PrfAesCmac(validKey.getKeyValue().toByteArray()), validKey.getParams().getTagSize());
byte[] message = Random.randBytes(50);
managerMac.verifyMac(directMac.computeMac(message), message);
}
use of com.google.crypto.tink.proto.AesCmacKey in project tink by google.
the class AesCmacKeyManagerTest method validateKey_wrongVersion_throws.
@Test
public void validateKey_wrongVersion_throws() throws Exception {
AesCmacKeyManager manager = new AesCmacKeyManager();
AesCmacKey validKey = manager.keyFactory().createKey(makeAesCmacKeyFormat(32, 16));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacKey.newBuilder(validKey).setVersion(1).build()));
}
Aggregations