use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testAes128GcmHkdf4KBTemplate.
@Test
public void testAes128GcmHkdf4KBTemplate() throws Exception {
KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes128GcmHkdf4KBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesGcmHkdfStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(16);
assertThat(format.getParams().getDerivedKeySize()).isEqualTo(16);
assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method createKey_checkValues.
@Test
public void createKey_checkValues() throws Exception {
AesGcmHkdfStreamingKeyFormat format = createKeyFormat(32, 32, HashType.SHA256, 1024);
AesGcmHkdfStreamingKey key = factory.createKey(format);
assertThat(key.getParams()).isEqualTo(format.getParams());
assertThat(key.getVersion()).isEqualTo(0);
assertThat(key.getKeyValue()).hasSize(format.getKeySize());
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testAes256GcmHkdf4KBTemplate.
@Test
public void testAes256GcmHkdf4KBTemplate() throws Exception {
KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes256GcmHkdf4KBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesGcmHkdfStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(32);
assertThat(format.getParams().getDerivedKeySize()).isEqualTo(32);
assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testDeriveKey_justEnoughKeyMaterial_works.
@Test
public void testDeriveKey_justEnoughKeyMaterial_works() throws Exception {
final int keySize = 32;
final int derivedKeySize = 16;
AesGcmHkdfStreamingKeyFormat format = createKeyFormat(keySize, derivedKeySize, HashType.SHA256, 1024);
byte[] keyMaterial = Random.randBytes(32);
AesGcmHkdfStreamingKey key = factory.deriveKey(format, new ByteArrayInputStream(keyMaterial));
assertThat(key.getKeyValue()).hasSize(32);
for (int i = 0; i < keySize; ++i) {
assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
}
assertThat(key.getParams()).isEqualTo(format.getParams());
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testDeriveKey_notEnoughKeyMaterial_throws.
@Test
public void testDeriveKey_notEnoughKeyMaterial_throws() throws Exception {
final int keySize = 32;
final int derivedKeySize = 16;
AesGcmHkdfStreamingKeyFormat format = createKeyFormat(keySize, derivedKeySize, HashType.SHA256, 1024);
byte[] keyMaterial = Random.randBytes(31);
assertThrows(GeneralSecurityException.class, () -> factory.deriveKey(format, new ByteArrayInputStream(keyMaterial)));
}
Aggregations