Search in sources :

Example 16 with RsaSsaPssKeyFormat

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

the class RsaSsaPssVerifyKeyManagerTest method validateKey_generated.

@Test
public void validateKey_generated() throws Exception {
    if (TestUtil.isTsan()) {
        // factory.createKey is too slow in Tsan.
        return;
    }
    RsaSsaPssKeyFormat keyFormat = RsaSsaPssKeyFormat.newBuilder().setParams(RsaSsaPssParams.newBuilder().setSigHash(HashType.SHA256).setMgf1Hash(HashType.SHA256).setSaltLength(32)).setModulusSizeInBits(3072).setPublicExponent(ByteString.copyFrom(RSAKeyGenParameterSpec.F4.toByteArray())).build();
    RsaSsaPssPrivateKey privateKey = factory.createKey(keyFormat);
    RsaSsaPssPublicKey publicKey = signManager.getPublicKey(privateKey);
    verifyManager.validateKey(publicKey);
}
Also used : RsaSsaPssPublicKey(com.google.crypto.tink.proto.RsaSsaPssPublicKey) RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Example 17 with RsaSsaPssKeyFormat

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

the class RsaSsaPssVerifyKeyManagerTest method createPrimitive_anotherKey_throws.

@Test
public void createPrimitive_anotherKey_throws() throws Exception {
    if (TestUtil.isTsan()) {
        // factory.createKey is too slow in Tsan.
        return;
    }
    RsaSsaPssKeyFormat keyFormat = RsaSsaPssKeyFormat.newBuilder().setParams(RsaSsaPssParams.newBuilder().setSigHash(HashType.SHA256).setMgf1Hash(HashType.SHA256).setSaltLength(32)).setModulusSizeInBits(3072).setPublicExponent(ByteString.copyFrom(RSAKeyGenParameterSpec.F4.toByteArray())).build();
    RsaSsaPssPrivateKey privateKey = factory.createKey(keyFormat);
    // Create a different key.
    RsaSsaPssPublicKey publicKey = signManager.getPublicKey(factory.createKey(keyFormat));
    PublicKeySign signer = signManager.getPrimitive(privateKey, PublicKeySign.class);
    PublicKeyVerify verifier = verifyManager.getPrimitive(publicKey, PublicKeyVerify.class);
    byte[] message = Random.randBytes(135);
    byte[] signature = signer.sign(message);
    assertThrows(GeneralSecurityException.class, () -> verifier.verify(signature, message));
}
Also used : RsaSsaPssPublicKey(com.google.crypto.tink.proto.RsaSsaPssPublicKey) RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test)

Example 18 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method testRsa3072PssSha256F4Template.

@Test
public void testRsa3072PssSha256F4Template() throws Exception {
    KeyTemplate template = RsaSsaPssSignKeyManager.rsa3072PssSha256F4Template();
    assertThat(template.getTypeUrl()).isEqualTo(new RsaSsaPssSignKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.TINK);
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.hasParams()).isTrue();
    assertThat(format.getParams().getSigHash()).isEqualTo(HashType.SHA256);
    assertThat(format.getParams().getMgf1Hash()).isEqualTo(HashType.SHA256);
    assertThat(format.getParams().getSaltLength()).isEqualTo(32);
    assertThat(format.getModulusSizeInBits()).isEqualTo(3072);
    assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(65537));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) BigInteger(java.math.BigInteger) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 19 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method testRawRsa4096PssSha512F4Template.

@Test
public void testRawRsa4096PssSha512F4Template() throws Exception {
    KeyTemplate template = RsaSsaPssSignKeyManager.rawRsa4096PssSha512F4Template();
    assertThat(template.getTypeUrl()).isEqualTo(new RsaSsaPssSignKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.hasParams()).isTrue();
    assertThat(format.getParams().getSigHash()).isEqualTo(HashType.SHA512);
    assertThat(format.getParams().getMgf1Hash()).isEqualTo(HashType.SHA512);
    assertThat(format.getParams().getSaltLength()).isEqualTo(64);
    assertThat(format.getModulusSizeInBits()).isEqualTo(4096);
    assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(65537));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) BigInteger(java.math.BigInteger) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 20 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method testRsa4096PssSha512F4TemplateWithManager.

@Test
public void testRsa4096PssSha512F4TemplateWithManager() throws Exception {
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(RsaSsaPssSignKeyManager.rsa4096PssSha512F4Template().getValue(), ExtensionRegistryLite.getEmptyRegistry());
    new RsaSsaPssSignKeyManager().keyFactory().validateKeyFormat(format);
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Aggregations

RsaSsaPssKeyFormat (com.google.crypto.tink.proto.RsaSsaPssKeyFormat)29 Test (org.junit.Test)27 RsaSsaPssPrivateKey (com.google.crypto.tink.proto.RsaSsaPssPrivateKey)9 BigInteger (java.math.BigInteger)8 RsaSsaPssPublicKey (com.google.crypto.tink.proto.RsaSsaPssPublicKey)5 KeyTemplate (com.google.crypto.tink.KeyTemplate)4 PublicKeySign (com.google.crypto.tink.PublicKeySign)4 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)3 RsaSsaPssParams (com.google.crypto.tink.proto.RsaSsaPssParams)3 ByteString (com.google.protobuf.ByteString)3 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)2 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 RsaSsaPssVerifyJce (com.google.crypto.tink.subtle.RsaSsaPssVerifyJce)1 KeyFactory (java.security.KeyFactory)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)1 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 HashMap (java.util.HashMap)1