Search in sources :

Example 1 with AesGcmHkdfStreamingKeyFormat

use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.

the class StreamingAeadKeyTemplatesTest method testAES128_GCM_HKDF_4KB.

@Test
public void testAES128_GCM_HKDF_4KB() throws Exception {
    KeyTemplate template = StreamingAeadKeyTemplates.AES128_GCM_HKDF_4KB;
    assertEquals(AesGcmHkdfStreamingKeyManager.TYPE_URL, template.getTypeUrl());
    assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
    AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue());
    assertEquals(16, format.getKeySize());
    assertEquals(16, format.getParams().getDerivedKeySize());
    assertEquals(HashType.SHA256, format.getParams().getHkdfHashType());
    assertEquals(4096, format.getParams().getCiphertextSegmentSize());
}
Also used : AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 2 with AesGcmHkdfStreamingKeyFormat

use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.

the class AesGcmHkdfStreamingKeyManager method newKey.

/**
 * @param keyFormat {@code AesGcmHkdfStreamingKeyFormat} proto
 * @return new {@code AesGcmHkdfStreamingKey} proto
 */
@Override
public MessageLite newKey(MessageLite keyFormat) throws GeneralSecurityException {
    if (!(keyFormat instanceof AesGcmHkdfStreamingKeyFormat)) {
        throw new GeneralSecurityException("expected AesGcmHkdfStreamingKeyFormat proto");
    }
    AesGcmHkdfStreamingKeyFormat format = (AesGcmHkdfStreamingKeyFormat) keyFormat;
    validate(format);
    return AesGcmHkdfStreamingKey.newBuilder().setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))).setParams(format.getParams()).setVersion(VERSION).build();
}
Also used : AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat) GeneralSecurityException(java.security.GeneralSecurityException)

Example 3 with AesGcmHkdfStreamingKeyFormat

use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.

the class StreamingAeadKeyTemplatesTest method testAes256GcmHkdf_1MB.

@Test
public void testAes256GcmHkdf_1MB() throws Exception {
    KeyTemplate template = StreamingAeadKeyTemplates.AES256_GCM_HKDF_1MB;
    assertEquals(new AesGcmHkdfStreamingKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
    AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.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());
}
Also used : AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 4 with AesGcmHkdfStreamingKeyFormat

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

Example 5 with AesGcmHkdfStreamingKeyFormat

use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.

the class AesGcmHkdfStreamingKeyManagerTest method testAes128GcmHkdf1MBTemplate.

@Test
public void testAes128GcmHkdf1MBTemplate() throws Exception {
    KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes128GcmHkdf1MBTemplate();
    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(1 << 20);
}
Also used : AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Aggregations

AesGcmHkdfStreamingKeyFormat (com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat)22 Test (org.junit.Test)19 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)7 AesGcmHkdfStreamingKey (com.google.crypto.tink.proto.AesGcmHkdfStreamingKey)5 KeyTemplate (com.google.crypto.tink.KeyTemplate)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteString (com.google.protobuf.ByteString)3 GeneralSecurityException (java.security.GeneralSecurityException)3 AesGcmHkdfStreamingParams (com.google.crypto.tink.proto.AesGcmHkdfStreamingParams)2 StreamingAead (com.google.crypto.tink.StreamingAead)1 HashType (com.google.crypto.tink.proto.HashType)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1