Search in sources :

Example 21 with AesGcmHkdfStreamingKeyFormat

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

the class StreamingAeadKeyTemplatesTest method testAes128GcmHkdf_4KB.

@Test
public void testAes128GcmHkdf_4KB() throws Exception {
    KeyTemplate template = StreamingAeadKeyTemplates.AES128_GCM_HKDF_4KB;
    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(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 22 with AesGcmHkdfStreamingKeyFormat

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

the class StreamingAeadKeyTemplates method createAesGcmHkdfStreamingKeyTemplate.

/**
 * @return a {@code KeyTemplate} containing a {@code AesGcmHkdfStreamingKeyFormat}
 *     with some specified parameters.
 */
public static KeyTemplate createAesGcmHkdfStreamingKeyTemplate(int mainKeySize, HashType hkdfHashType, int derivedKeySize, int ciphertextSegmentSize) {
    AesGcmHkdfStreamingParams keyParams = AesGcmHkdfStreamingParams.newBuilder().setCiphertextSegmentSize(ciphertextSegmentSize).setDerivedKeySize(derivedKeySize).setHkdfHashType(hkdfHashType).build();
    AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.newBuilder().setKeySize(mainKeySize).setParams(keyParams).build();
    return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(new AesGcmHkdfStreamingKeyManager().getKeyType()).setOutputPrefixType(OutputPrefixType.RAW).build();
}
Also used : AesGcmHkdfStreamingParams(com.google.crypto.tink.proto.AesGcmHkdfStreamingParams) AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat)

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