Search in sources :

Example 1 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class AesSivKeyManagerTest method testAes256SivTemplate.

@Test
public void testAes256SivTemplate() throws Exception {
    KeyTemplate template = AesSivKeyManager.aes256SivTemplate();
    assertThat(template.getTypeUrl()).isEqualTo(new AesSivKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.TINK);
    AesSivKeyFormat format = AesSivKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getKeySize()).isEqualTo(format.getKeySize());
}
Also used : AesSivKeyFormat(com.google.crypto.tink.proto.AesSivKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 2 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class EciesAeadHkdfPrivateKeyManagerTest method testRawEciesP256HkdfHmacSha256Aes128GcmCompressedTemplate.

@Test
public void testRawEciesP256HkdfHmacSha256Aes128GcmCompressedTemplate() throws Exception {
    KeyTemplate template = EciesAeadHkdfPrivateKeyManager.rawEciesP256HkdfHmacSha256Aes128GcmCompressedTemplate();
    assertEquals(new EciesAeadHkdfPrivateKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(KeyTemplate.OutputPrefixType.RAW, template.getOutputPrefixType());
    EciesAeadHkdfKeyFormat format = EciesAeadHkdfKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.hasParams()).isTrue();
    assertThat(format.getParams().hasKemParams()).isTrue();
    assertThat(format.getParams().hasDemParams()).isTrue();
    assertThat(format.getParams().getDemParams().hasAeadDem()).isTrue();
    assertThat(format.getParams().getEcPointFormat()).isEqualTo(EcPointFormat.COMPRESSED);
    EciesHkdfKemParams kemParams = format.getParams().getKemParams();
    assertThat(kemParams.getCurveType()).isEqualTo(EllipticCurveType.NIST_P256);
    assertThat(kemParams.getHkdfHashType()).isEqualTo(HashType.SHA256);
    assertThat(kemParams.getHkdfSalt()).isEmpty();
    assertThat(format.getParams().getDemParams().getAeadDem().toString()).isEqualTo(AeadKeyTemplates.AES128_GCM.toString());
}
Also used : EciesAeadHkdfKeyFormat(com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 3 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class EciesAeadHkdfPrivateKeyManagerTest method testEciesP256HkdfHmacSha256Aes128GcmTemplate.

@Test
public void testEciesP256HkdfHmacSha256Aes128GcmTemplate() throws Exception {
    KeyTemplate template = EciesAeadHkdfPrivateKeyManager.eciesP256HkdfHmacSha256Aes128GcmTemplate();
    assertEquals(new EciesAeadHkdfPrivateKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(KeyTemplate.OutputPrefixType.TINK, template.getOutputPrefixType());
    EciesAeadHkdfKeyFormat format = EciesAeadHkdfKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.hasParams()).isTrue();
    assertThat(format.getParams().hasKemParams()).isTrue();
    assertThat(format.getParams().hasDemParams()).isTrue();
    assertThat(format.getParams().getDemParams().hasAeadDem()).isTrue();
    assertThat(format.getParams().getEcPointFormat()).isEqualTo(EcPointFormat.UNCOMPRESSED);
    EciesHkdfKemParams kemParams = format.getParams().getKemParams();
    assertThat(kemParams.getCurveType()).isEqualTo(EllipticCurveType.NIST_P256);
    assertThat(kemParams.getHkdfHashType()).isEqualTo(HashType.SHA256);
    assertThat(kemParams.getHkdfSalt()).isEmpty();
    assertThat(format.getParams().getDemParams().getAeadDem().toString()).isEqualTo(AeadKeyTemplates.AES128_GCM.toString());
}
Also used : EciesAeadHkdfKeyFormat(com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 4 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class EciesAeadHkdfPrivateKeyManagerTest method testEciesP256HkdfHmacSha256Aes128CtrHmacSha256Template.

@Test
public void testEciesP256HkdfHmacSha256Aes128CtrHmacSha256Template() throws Exception {
    KeyTemplate template = EciesAeadHkdfPrivateKeyManager.eciesP256HkdfHmacSha256Aes128CtrHmacSha256Template();
    assertEquals(new EciesAeadHkdfPrivateKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(KeyTemplate.OutputPrefixType.TINK, template.getOutputPrefixType());
    EciesAeadHkdfKeyFormat format = EciesAeadHkdfKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.hasParams()).isTrue();
    assertThat(format.getParams().hasKemParams()).isTrue();
    assertThat(format.getParams().hasDemParams()).isTrue();
    assertThat(format.getParams().getDemParams().hasAeadDem()).isTrue();
    assertThat(format.getParams().getEcPointFormat()).isEqualTo(EcPointFormat.UNCOMPRESSED);
    EciesHkdfKemParams kemParams = format.getParams().getKemParams();
    assertThat(kemParams.getCurveType()).isEqualTo(EllipticCurveType.NIST_P256);
    assertThat(kemParams.getHkdfHashType()).isEqualTo(HashType.SHA256);
    assertThat(kemParams.getHkdfSalt()).isEmpty();
    assertThat(format.getParams().getDemParams().getAeadDem().toString()).isEqualTo(AeadKeyTemplates.AES128_CTR_HMAC_SHA256.toString());
}
Also used : EciesAeadHkdfKeyFormat(com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 5 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class EciesAeadHkdfPrivateKeyManagerTest method testRawEciesP256HkdfHmacSha256Aes128CtrHmacSha256CompressedTemplate.

@Test
public void testRawEciesP256HkdfHmacSha256Aes128CtrHmacSha256CompressedTemplate() throws Exception {
    KeyTemplate template = EciesAeadHkdfPrivateKeyManager.rawEciesP256HkdfHmacSha256Aes128CtrHmacSha256CompressedTemplate();
    assertEquals(new EciesAeadHkdfPrivateKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(KeyTemplate.OutputPrefixType.RAW, template.getOutputPrefixType());
    EciesAeadHkdfKeyFormat format = EciesAeadHkdfKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.hasParams()).isTrue();
    assertThat(format.getParams().hasKemParams()).isTrue();
    assertThat(format.getParams().hasDemParams()).isTrue();
    assertThat(format.getParams().getDemParams().hasAeadDem()).isTrue();
    assertThat(format.getParams().getEcPointFormat()).isEqualTo(EcPointFormat.COMPRESSED);
    EciesHkdfKemParams kemParams = format.getParams().getKemParams();
    assertThat(kemParams.getCurveType()).isEqualTo(EllipticCurveType.NIST_P256);
    assertThat(kemParams.getHkdfHashType()).isEqualTo(HashType.SHA256);
    assertThat(kemParams.getHkdfSalt()).isEmpty();
    assertThat(format.getParams().getDemParams().getAeadDem().toString()).isEqualTo(AeadKeyTemplates.AES128_CTR_HMAC_SHA256.toString());
}
Also used : EciesAeadHkdfKeyFormat(com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Aggregations

KeyTemplate (com.google.crypto.tink.KeyTemplate)143 Test (org.junit.Test)135 KeysetHandle (com.google.crypto.tink.KeysetHandle)56 ByteString (com.google.protobuf.ByteString)39 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)37 KeyData (com.google.crypto.tink.proto.KeyData)16 Keyset (com.google.crypto.tink.proto.Keyset)12 JsonObject (com.google.gson.JsonObject)8 KeysetManager (com.google.crypto.tink.KeysetManager)7 BigInteger (java.math.BigInteger)7 Instant (java.time.Instant)7 Aead (com.google.crypto.tink.Aead)6 Enums (com.google.crypto.tink.subtle.Enums)6 Clock (java.time.Clock)6 AesEaxKeyFormat (com.google.crypto.tink.proto.AesEaxKeyFormat)5 AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)4 AesGcmHkdfStreamingKeyFormat (com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat)4 AesGcmKeyFormat (com.google.crypto.tink.proto.AesGcmKeyFormat)4 AesGcmSivKeyFormat (com.google.crypto.tink.proto.AesGcmSivKeyFormat)4 EciesAeadHkdfKeyFormat (com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat)4