use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_unkownHash_throws.
@Test
public void validateKeyFormat_unkownHash_throws() throws Exception {
AesCtrHmacStreamingKeyFormat format = createKeyFormat().setParams(createParams().setHkdfHashType(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 testAes128CtrHmacSha2561MBTemplate.
@Test
public void testAes128CtrHmacSha2561MBTemplate() throws Exception {
KeyTemplate template = AesCtrHmacStreamingKeyManager.aes128CtrHmacSha2561MBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesCtrHmacStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.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().getHmacParams().getHash()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getHmacParams().getTagSize()).isEqualTo(32);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(1 << 20);
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method createKey_values.
@Test
public void createKey_values() throws Exception {
AesCtrHmacStreamingKeyFormat format = createKeyFormat().build();
AesCtrHmacStreamingKey key = factory.createKey(format);
assertThat(key.getVersion()).isEqualTo(0);
assertThat(key.getKeyValue()).hasSize(format.getKeySize());
assertThat(key.getParams()).isEqualTo(format.getParams());
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method createKey_multipleTimes_differentValues.
@Test
public void createKey_multipleTimes_differentValues() throws Exception {
AesCtrHmacStreamingKeyFormat keyFormat = createKeyFormat().build();
Set<String> keys = new TreeSet<>();
// Calls newKey multiple times and make sure that they generate different keys.
int numTests = 100;
for (int i = 0; i < numTests; i++) {
keys.add(TestUtil.hexEncode(factory.createKey(keyFormat).getKeyValue().toByteArray()));
}
assertThat(keys).hasSize(numTests);
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAes128CtrHmacSha256_4KB.
@Test
public void testAes128CtrHmacSha256_4KB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES128_CTR_HMAC_SHA256_4KB;
assertEquals(new AesCtrHmacStreamingKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(16, format.getKeySize());
assertEquals(16, 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());
}
Aggregations