use of com.google.crypto.tink.proto.AesGcmSivKeyFormat in project tink by google.
the class AesGcmSivKeyManagerTest method testAes128GcmSivTemplate.
@Test
public void testAes128GcmSivTemplate() throws Exception {
KeyTemplate template = AesGcmSivKeyManager.aes128GcmSivTemplate();
assertEquals(new AesGcmSivKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(KeyTemplate.OutputPrefixType.TINK, template.getOutputPrefixType());
AesGcmSivKeyFormat format = AesGcmSivKeyFormat.parseFrom(ByteString.copyFrom(template.getValue()), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(16, format.getKeySize());
}
use of com.google.crypto.tink.proto.AesGcmSivKeyFormat in project tink by google.
the class AesGcmSivKeyManagerTest method testDeriveKey_notEnoughKeyMaterial_throws.
@Test
public void testDeriveKey_notEnoughKeyMaterial_throws() throws Exception {
byte[] keyMaterial = Random.randBytes(31);
AesGcmSivKeyFormat format = AesGcmSivKeyFormat.newBuilder().setVersion(0).setKeySize(32).build();
assertThrows(GeneralSecurityException.class, () -> factory.deriveKey(format, new ByteArrayInputStream(keyMaterial)));
}
use of com.google.crypto.tink.proto.AesGcmSivKeyFormat in project tink by google.
the class AesGcmSivKeyManagerTest method testDeriveKey_badVersion_throws.
@Test
public void testDeriveKey_badVersion_throws() throws Exception {
final int keySize = 32;
byte[] keyMaterial = Random.randBytes(100);
AesGcmSivKeyFormat format = AesGcmSivKeyFormat.newBuilder().setVersion(1).setKeySize(keySize).build();
assertThrows(GeneralSecurityException.class, () -> factory.deriveKey(format, new ByteArrayInputStream(keyMaterial)));
}
use of com.google.crypto.tink.proto.AesGcmSivKeyFormat in project tink by google.
the class AesGcmSivKeyManagerTest method createKey_multipleTimes.
@Test
public void createKey_multipleTimes() throws Exception {
AesGcmSivKeyFormat format = AesGcmSivKeyFormat.newBuilder().setKeySize(16).build();
Set<String> keys = new TreeSet<>();
// Calls newKey multiple times and make sure that they generate different keys.
int numTests = 50;
for (int i = 0; i < numTests; i++) {
keys.add(TestUtil.hexEncode(factory.createKey(format).getKeyValue().toByteArray()));
}
assertThat(keys).hasSize(numTests);
}
use of com.google.crypto.tink.proto.AesGcmSivKeyFormat in project tink by google.
the class AesGcmSivKeyManagerTest method testRawAes128GcmSivTemplate.
@Test
public void testRawAes128GcmSivTemplate() throws Exception {
KeyTemplate template = AesGcmSivKeyManager.rawAes128GcmSivTemplate();
assertEquals(new AesGcmSivKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(KeyTemplate.OutputPrefixType.RAW, template.getOutputPrefixType());
AesGcmSivKeyFormat format = AesGcmSivKeyFormat.parseFrom(ByteString.copyFrom(template.getValue()), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(16, format.getKeySize());
}
Aggregations