Search in sources :

Example 6 with EciesHkdfKemParams

use of com.google.crypto.tink.proto.EciesHkdfKemParams 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 7 with EciesHkdfKemParams

use of com.google.crypto.tink.proto.EciesHkdfKemParams 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 8 with EciesHkdfKemParams

use of com.google.crypto.tink.proto.EciesHkdfKemParams 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)

Example 9 with EciesHkdfKemParams

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

the class HybridKeyTemplatesTest method eciesP256HkdfHmacSha256Aes128GcmCompressedWithoutPrefix.

@Test
public void eciesP256HkdfHmacSha256Aes128GcmCompressedWithoutPrefix() throws Exception {
    KeyTemplate template = HybridKeyTemplates.ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM_COMPRESSED_WITHOUT_PREFIX;
    assertEquals(new EciesAeadHkdfPrivateKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.RAW, 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.COMPRESSED, 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)

Example 10 with EciesHkdfKemParams

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

the class EciesAeadHkdfPrivateKeyManager method getPrimitive.

/**
 * @param recipientKey {@code EciesAeadHkdfPrivateKey} proto
 */
@Override
public HybridDecrypt getPrimitive(MessageLite recipientKey) throws GeneralSecurityException {
    if (!(recipientKey instanceof EciesAeadHkdfPrivateKey)) {
        throw new GeneralSecurityException("expected EciesAeadHkdfPrivateKey proto");
    }
    EciesAeadHkdfPrivateKey recipientKeyProto = (EciesAeadHkdfPrivateKey) recipientKey;
    validate(recipientKeyProto);
    EciesAeadHkdfParams eciesParams = recipientKeyProto.getPublicKey().getParams();
    EciesHkdfKemParams kemParams = eciesParams.getKemParams();
    ECPrivateKey recipientPrivateKey = EllipticCurves.getEcPrivateKey(HybridUtil.toCurveType(kemParams.getCurveType()), recipientKeyProto.getKeyValue().toByteArray());
    EciesAeadHkdfDemHelper demHelper = new RegistryEciesAeadHkdfDemHelper(eciesParams.getDemParams().getAeadDem());
    return new EciesAeadHkdfHybridDecrypt(recipientPrivateKey, kemParams.getHkdfSalt().toByteArray(), HybridUtil.toHmacAlgo(kemParams.getHkdfHashType()), HybridUtil.toPointFormatType(eciesParams.getEcPointFormat()), demHelper);
}
Also used : EciesAeadHkdfDemHelper(com.google.crypto.tink.subtle.EciesAeadHkdfDemHelper) EciesAeadHkdfParams(com.google.crypto.tink.proto.EciesAeadHkdfParams) ECPrivateKey(java.security.interfaces.ECPrivateKey) EciesAeadHkdfHybridDecrypt(com.google.crypto.tink.subtle.EciesAeadHkdfHybridDecrypt) EciesAeadHkdfPrivateKey(com.google.crypto.tink.proto.EciesAeadHkdfPrivateKey) GeneralSecurityException(java.security.GeneralSecurityException) EciesHkdfKemParams(com.google.crypto.tink.proto.EciesHkdfKemParams)

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