Search in sources :

Example 16 with EciesHkdfKemParams

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

the class HybridKeyTemplatesTest method testCreateEciesAeadHkdfKeyTemplate.

@Test
public void testCreateEciesAeadHkdfKeyTemplate() throws Exception {
    // Intentionally using "weird" or invalid values for parameters,
    // to test that the function correctly puts them in the resulting template.
    EllipticCurveType curveType = EllipticCurveType.NIST_P384;
    HashType hashType = HashType.SHA512;
    EcPointFormat ecPointFormat = EcPointFormat.COMPRESSED;
    KeyTemplate demKeyTemplate = AeadKeyTemplates.AES256_EAX;
    String salt = "some salt";
    KeyTemplate template = HybridKeyTemplates.createEciesAeadHkdfKeyTemplate(curveType, hashType, ecPointFormat, demKeyTemplate, OutputPrefixType.TINK, salt.getBytes(UTF_8));
    assertEquals(new EciesAeadHkdfPrivateKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    EciesAeadHkdfKeyFormat format = EciesAeadHkdfKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertTrue(format.hasParams());
    assertTrue(format.getParams().hasKemParams());
    assertTrue(format.getParams().hasDemParams());
    assertTrue(format.getParams().getDemParams().hasAeadDem());
    assertEquals(ecPointFormat, format.getParams().getEcPointFormat());
    EciesHkdfKemParams kemParams = format.getParams().getKemParams();
    assertEquals(curveType, kemParams.getCurveType());
    assertEquals(hashType, kemParams.getHkdfHashType());
    assertEquals(salt, kemParams.getHkdfSalt().toStringUtf8());
    assertEquals(AeadKeyTemplates.AES256_EAX.toString(), format.getParams().getDemParams().getAeadDem().toString());
}
Also used : EciesAeadHkdfKeyFormat(com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat) HashType(com.google.crypto.tink.proto.HashType) EcPointFormat(com.google.crypto.tink.proto.EcPointFormat) EllipticCurveType(com.google.crypto.tink.proto.EllipticCurveType) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 17 with EciesHkdfKemParams

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

the class HybridKeyTemplatesTest method eciesP256HkdfHmacSha256Aes128CtrHmacSha256.

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

Example 18 with EciesHkdfKemParams

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

the class HybridKeyTemplatesTest method eciesP256HkdfHmaSha256Aes128Gcm.

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

Aggregations

EciesHkdfKemParams (com.google.crypto.tink.proto.EciesHkdfKemParams)18 EciesAeadHkdfKeyFormat (com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat)12 Test (org.junit.Test)11 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)6 KeyTemplate (com.google.crypto.tink.KeyTemplate)4 EciesAeadHkdfParams (com.google.crypto.tink.proto.EciesAeadHkdfParams)4 ECPublicKey (java.security.interfaces.ECPublicKey)4 EciesAeadDemParams (com.google.crypto.tink.proto.EciesAeadDemParams)3 EciesAeadHkdfPublicKey (com.google.crypto.tink.proto.EciesAeadHkdfPublicKey)3 EciesAeadHkdfDemHelper (com.google.crypto.tink.subtle.EciesAeadHkdfDemHelper)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ECPrivateKey (java.security.interfaces.ECPrivateKey)3 EciesAeadHkdfPrivateKey (com.google.crypto.tink.proto.EciesAeadHkdfPrivateKey)2 EciesAeadHkdfHybridEncrypt (com.google.crypto.tink.subtle.EciesAeadHkdfHybridEncrypt)2 KeyPair (java.security.KeyPair)2 ECPoint (java.security.spec.ECPoint)2 HybridDecrypt (com.google.crypto.tink.HybridDecrypt)1 HybridEncrypt (com.google.crypto.tink.HybridEncrypt)1 EcPointFormat (com.google.crypto.tink.proto.EcPointFormat)1 EllipticCurveType (com.google.crypto.tink.proto.EllipticCurveType)1