Search in sources :

Example 11 with AesCtrHmacStreamingKeyFormat

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));
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) Test(org.junit.Test)

Example 12 with AesCtrHmacStreamingKeyFormat

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());
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 13 with AesCtrHmacStreamingKeyFormat

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());
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 14 with AesCtrHmacStreamingKeyFormat

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));
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) Test(org.junit.Test)

Example 15 with AesCtrHmacStreamingKeyFormat

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());
}
Also used : ByteString(com.google.protobuf.ByteString) TreeSet(java.util.TreeSet) AesCtrHmacStreamingKey(com.google.crypto.tink.proto.AesCtrHmacStreamingKey) AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) ByteString(com.google.protobuf.ByteString) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Aggregations

AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)28 Test (org.junit.Test)25 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)7 AesCtrHmacStreamingKey (com.google.crypto.tink.proto.AesCtrHmacStreamingKey)5 KeyTemplate (com.google.crypto.tink.KeyTemplate)4 ByteString (com.google.protobuf.ByteString)3 StreamingAead (com.google.crypto.tink.StreamingAead)2 AesCtrHmacStreamingParams (com.google.crypto.tink.proto.AesCtrHmacStreamingParams)2 TreeSet (java.util.TreeSet)2 HashType (com.google.crypto.tink.proto.HashType)1 HmacParams (com.google.crypto.tink.proto.HmacParams)1 KeyData (com.google.crypto.tink.proto.KeyData)1 GeneralSecurityException (java.security.GeneralSecurityException)1