Search in sources :

Example 16 with AesCtrHmacStreamingKeyFormat

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

the class StreamingAeadKeyTemplatesTest method testAES256_CTR_HMAC_SHA256_4KB.

@Test
public void testAES256_CTR_HMAC_SHA256_4KB() throws Exception {
    KeyTemplate template = StreamingAeadKeyTemplates.AES256_CTR_HMAC_SHA256_4KB;
    assertEquals(AesCtrHmacStreamingKeyManager.TYPE_URL, template.getTypeUrl());
    assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
    AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.parseFrom(template.getValue());
    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 17 with AesCtrHmacStreamingKeyFormat

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

the class AesCtrHmacStreamingKeyManager method newKey.

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

Example 18 with AesCtrHmacStreamingKeyFormat

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

the class AesCtrHmacStreamingKeyManagerTest method testAes128CtrHmacSha2564KBTemplate.

@Test
public void testAes128CtrHmacSha2564KBTemplate() throws Exception {
    KeyTemplate template = AesCtrHmacStreamingKeyManager.aes128CtrHmacSha2564KBTemplate();
    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(4096);
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 19 with AesCtrHmacStreamingKeyFormat

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

the class AesCtrHmacStreamingKeyManagerTest method testAes256CtrHmacSha2564KBTemplate.

@Test
public void testAes256CtrHmacSha2564KBTemplate() throws Exception {
    KeyTemplate template = AesCtrHmacStreamingKeyManager.aes256CtrHmacSha2564KBTemplate();
    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(32);
    assertThat(format.getParams().getDerivedKeySize()).isEqualTo(32);
    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(4096);
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 20 with AesCtrHmacStreamingKeyFormat

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

the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_valid.

@Test
public void validateKeyFormat_valid() throws Exception {
    AesCtrHmacStreamingKeyFormat format = createKeyFormat().build();
    factory.validateKeyFormat(format);
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) 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