use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_tagSizeTooBigSha1_throws.
@Test
public void validateKeyFormat_tagSizeTooBigSha1_throws() throws Exception {
AesCtrHmacStreamingKeyFormat format = createKeyFormat().setParams(createParams().setHmacParams(createHmacParams().setHash(HashType.SHA1).setTagSize(21))).build();
assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAes256CtrHmacSha256_1MB.
@Test
public void testAes256CtrHmacSha256_1MB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES256_CTR_HMAC_SHA256_1MB;
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(1048576, format.getParams().getCiphertextSegmentSize());
assertEquals(HashType.SHA256, format.getParams().getHmacParams().getHash());
assertEquals(32, format.getParams().getHmacParams().getTagSize());
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat 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.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_unkownHmacHash_throws.
@Test
public void validateKeyFormat_unkownHmacHash_throws() throws Exception {
AesCtrHmacStreamingKeyFormat format = createKeyFormat().setParams(createParams().setHmacParams(createHmacParams().setHash(HashType.UNKNOWN_HASH))).build();
assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method testNewKeyMultipleTimes.
@Test
public void testNewKeyMultipleTimes() throws Exception {
AesCtrHmacStreamingKeyFormat keyFormat = AesCtrHmacStreamingKeyFormat.newBuilder().setParams(keyParams).setKeySize(16).build();
ByteString serializedKeyFormat = ByteString.copyFrom(keyFormat.toByteArray());
Set<String> keys = new TreeSet<String>();
// Calls newKey multiple times and make sure that they generate different keys.
int numTests = 27;
for (int i = 0; i < numTests / 3; i++) {
AesCtrHmacStreamingKey key = (AesCtrHmacStreamingKey) keyManager.newKey(keyFormat);
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(16, key.getKeyValue().toByteArray().length);
key = (AesCtrHmacStreamingKey) keyManager.newKey(serializedKeyFormat);
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(16, key.getKeyValue().toByteArray().length);
KeyData keyData = keyManager.newKeyData(serializedKeyFormat);
key = AesCtrHmacStreamingKey.parseFrom(keyData.getValue());
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(16, key.getKeyValue().toByteArray().length);
}
assertEquals(numTests, keys.size());
}
Aggregations