use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAes256CtrHmacSha256_4KB.
@Test
public void testAes256CtrHmacSha256_4KB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES256_CTR_HMAC_SHA256_4KB;
assertEquals(new AesCtrHmacStreamingKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(32, format.getKeySize());
assertEquals(32, format.getParams().getDerivedKeySize());
assertEquals(HashType.SHA256, format.getParams().getHkdfHashType());
assertEquals(4096, format.getParams().getCiphertextSegmentSize());
assertEquals(HashType.SHA256, format.getParams().getHmacParams().getHash());
assertEquals(32, format.getParams().getHmacParams().getTagSize());
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAes128GcmHkdf_1MB.
@Test
public void testAes128GcmHkdf_1MB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES128_GCM_HKDF_1MB;
assertEquals(new AesGcmHkdfStreamingKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(16, format.getKeySize());
assertEquals(16, format.getParams().getDerivedKeySize());
assertEquals(HashType.SHA256, format.getParams().getHkdfHashType());
assertEquals(1048576, format.getParams().getCiphertextSegmentSize());
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class NoSecretKeysetHandleTest method testBasic.
@Test
public void testBasic() throws Exception {
// Create a keyset that contains a single HmacKey.
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetManager manager = KeysetManager.withEmptyKeyset().rotate(template);
Keyset keyset = manager.getKeysetHandle().getKeyset();
GeneralSecurityException e = assertThrows(GeneralSecurityException.class, () -> {
KeysetHandle unused = NoSecretKeysetHandle.parseFrom(keyset.toByteArray());
});
assertExceptionContains(e, "keyset contains secret key material");
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class CleartextKeysetHandleTest method testRead.
@Test
public void testRead() throws Exception {
// Create a keyset that contains a single HmacKey.
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetManager manager = KeysetManager.withEmptyKeyset().rotate(template);
Keyset keyset1 = manager.getKeysetHandle().getKeyset();
KeysetHandle handle1 = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(keyset1.toByteArray()));
assertEquals(keyset1, handle1.getKeyset());
KeysetHandle handle2 = KeysetHandle.generateNew(template);
Keyset keyset2 = handle2.getKeyset();
assertEquals(1, keyset2.getKeyCount());
Keyset.Key key2 = keyset2.getKey(0);
assertEquals(keyset2.getPrimaryKeyId(), key2.getKeyId());
assertEquals(template.getTypeUrl(), key2.getKeyData().getTypeUrl());
Mac unused = handle2.getPrimitive(Mac.class);
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class CleartextKeysetHandleTest method testParse.
@Test
public void testParse() throws Exception {
// Create a keyset that contains a single HmacKey.
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetHandle handle = KeysetHandle.generateNew(template);
Keyset keyset = CleartextKeysetHandle.getKeyset(handle);
handle = CleartextKeysetHandle.parseFrom(keyset.toByteArray());
assertEquals(keyset, handle.getKeyset());
handle.getPrimitive(Mac.class);
}
Aggregations