Search in sources :

Example 1 with AesCmacPrfKey

use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.

the class AesCmacPrfKeyManagerTest method validateKey_notValid_throws.

@Test
public void validateKey_notValid_throws() throws Exception {
    AesCmacPrfKeyManager manager = new AesCmacPrfKeyManager();
    AesCmacPrfKey validKey = manager.keyFactory().createKey(makeAesCmacPrfKeyFormat(32));
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacPrfKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(16))).build()));
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacPrfKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(64))).build()));
}
Also used : AesCmacPrfKey(com.google.crypto.tink.proto.AesCmacPrfKey) Test(org.junit.Test)

Example 2 with AesCmacPrfKey

use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.

the class AesCmacPrfKeyManagerTest method getPrimitive_works.

@Test
public void getPrimitive_works() throws Exception {
    AesCmacPrfKeyManager manager = new AesCmacPrfKeyManager();
    AesCmacPrfKey validKey = manager.keyFactory().createKey(makeAesCmacPrfKeyFormat(32));
    Prf managerPrf = manager.getPrimitive(validKey, Prf.class);
    Prf directPrf = new PrfAesCmac(validKey.getKeyValue().toByteArray());
    byte[] message = Random.randBytes(50);
    assertThat(managerPrf.compute(message, 16)).isEqualTo(directPrf.compute(message, 16));
}
Also used : PrfAesCmac(com.google.crypto.tink.subtle.PrfAesCmac) AesCmacPrfKey(com.google.crypto.tink.proto.AesCmacPrfKey) Test(org.junit.Test)

Example 3 with AesCmacPrfKey

use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.

the class AesCmacPrfKeyManagerTest method createKey_checkValues.

@Test
public void createKey_checkValues() throws Exception {
    AesCmacPrfKeyFormat keyFormat = makeAesCmacPrfKeyFormat(32);
    AesCmacPrfKey key = new AesCmacPrfKeyManager().keyFactory().createKey(keyFormat);
    assertThat(key.getKeyValue()).hasSize(keyFormat.getKeySize());
}
Also used : AesCmacPrfKey(com.google.crypto.tink.proto.AesCmacPrfKey) AesCmacPrfKeyFormat(com.google.crypto.tink.proto.AesCmacPrfKeyFormat) Test(org.junit.Test)

Example 4 with AesCmacPrfKey

use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.

the class AesCmacPrfKeyManagerTest method validateKey_wrongVersion_throws.

@Test
public void validateKey_wrongVersion_throws() throws Exception {
    AesCmacPrfKeyManager manager = new AesCmacPrfKeyManager();
    AesCmacPrfKey validKey = manager.keyFactory().createKey(makeAesCmacPrfKeyFormat(32));
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacPrfKey.newBuilder(validKey).setVersion(1).build()));
}
Also used : AesCmacPrfKey(com.google.crypto.tink.proto.AesCmacPrfKey) Test(org.junit.Test)

Aggregations

AesCmacPrfKey (com.google.crypto.tink.proto.AesCmacPrfKey)4 Test (org.junit.Test)4 AesCmacPrfKeyFormat (com.google.crypto.tink.proto.AesCmacPrfKeyFormat)1 PrfAesCmac (com.google.crypto.tink.subtle.PrfAesCmac)1