Search in sources :

Example 26 with AesCtrHmacStreamingKeyFormat

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

the class StreamingAeadKeyTemplatesTest method testAes128CtrHmacSha256_1MB.

@Test
public void testAes128CtrHmacSha256_1MB() throws Exception {
    KeyTemplate template = StreamingAeadKeyTemplates.AES128_CTR_HMAC_SHA256_1MB;
    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(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 27 with AesCtrHmacStreamingKeyFormat

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

the class StreamingAeadKeyTemplatesTest method testCreateAesCtrHmacStreamingKeyTemplate.

@Test
public void testCreateAesCtrHmacStreamingKeyTemplate() throws Exception {
    // Intentionally using "weird" or invalid values for parameters,
    // to test that the function correctly puts them in the resulting template.
    int mainKeySize = 42;
    int derivedKeySize = 24;
    int tagSize = 45;
    int ciphertextSegmentSize = 12345;
    HashType hkdfHashType = HashType.SHA512;
    HashType macHashType = HashType.UNKNOWN_HASH;
    KeyTemplate template = StreamingAeadKeyTemplates.createAesCtrHmacStreamingKeyTemplate(mainKeySize, hkdfHashType, derivedKeySize, macHashType, tagSize, ciphertextSegmentSize);
    assertEquals(new AesCtrHmacStreamingKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
    AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(mainKeySize, format.getKeySize());
    assertEquals(derivedKeySize, format.getParams().getDerivedKeySize());
    assertEquals(hkdfHashType, format.getParams().getHkdfHashType());
    assertEquals(ciphertextSegmentSize, format.getParams().getCiphertextSegmentSize());
    assertEquals(macHashType, format.getParams().getHmacParams().getHash());
    assertEquals(tagSize, format.getParams().getHmacParams().getTagSize());
}
Also used : HashType(com.google.crypto.tink.proto.HashType) AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 28 with AesCtrHmacStreamingKeyFormat

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

the class StreamingAeadKeyTemplates method createAesCtrHmacStreamingKeyTemplate.

/**
 * @return a {@link KeyTemplate} containing a {@link AesCtrHmacStreamingKeyFormat} with some
 *     specified parameters.
 */
public static KeyTemplate createAesCtrHmacStreamingKeyTemplate(int mainKeySize, HashType hkdfHashType, int derivedKeySize, HashType macHashType, int tagSize, int ciphertextSegmentSize) {
    HmacParams hmacParams = HmacParams.newBuilder().setHash(macHashType).setTagSize(tagSize).build();
    AesCtrHmacStreamingParams params = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(ciphertextSegmentSize).setDerivedKeySize(derivedKeySize).setHkdfHashType(hkdfHashType).setHmacParams(hmacParams).build();
    AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.newBuilder().setParams(params).setKeySize(mainKeySize).build();
    return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(new AesCtrHmacStreamingKeyManager().getKeyType()).setOutputPrefixType(OutputPrefixType.RAW).build();
}
Also used : AesCtrHmacStreamingParams(com.google.crypto.tink.proto.AesCtrHmacStreamingParams) HmacParams(com.google.crypto.tink.proto.HmacParams) AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)

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