Search in sources :

Example 1 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method validateKeyFormat_negativeSaltLength_throws.

@Test
public void validateKeyFormat_negativeSaltLength_throws() throws Exception {
    RsaSsaPssKeyFormat format = createKeyFormat(HashType.SHA512, HashType.SHA512, -5, 3072, RSAKeyGenParameterSpec.F4);
    assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Example 2 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method createPrimitive.

@Test
public void createPrimitive() throws Exception {
    if (TestUtil.isTsan()) {
        // factory.createKey is too slow in Tsan.
        return;
    }
    RsaSsaPssKeyFormat format = createKeyFormat(HashType.SHA512, HashType.SHA512, 64, 4096, RSAKeyGenParameterSpec.F4);
    RsaSsaPssPrivateKey key = factory.createKey(format);
    PublicKeySign signer = manager.getPrimitive(key, PublicKeySign.class);
    KeyFactory kf = EngineFactory.KEY_FACTORY.getInstance("RSA");
    BigInteger modulus = new BigInteger(1, key.getPublicKey().getN().toByteArray());
    BigInteger exponent = new BigInteger(1, key.getPublicKey().getE().toByteArray());
    RSAPublicKey publicKey = (RSAPublicKey) kf.generatePublic(new RSAPublicKeySpec(modulus, exponent));
    RsaSsaPssParams params = key.getPublicKey().getParams();
    PublicKeyVerify verifier = new RsaSsaPssVerifyJce(publicKey, SigUtil.toHashType(params.getSigHash()), SigUtil.toHashType(params.getMgf1Hash()), params.getSaltLength());
    byte[] message = Random.randBytes(135);
    verifier.verify(signer.sign(message), message);
}
Also used : RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) RsaSsaPssVerifyJce(com.google.crypto.tink.subtle.RsaSsaPssVerifyJce) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) BigInteger(java.math.BigInteger) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) RsaSsaPssParams(com.google.crypto.tink.proto.RsaSsaPssParams) PublicKeySign(com.google.crypto.tink.PublicKeySign) KeyFactory(java.security.KeyFactory) Test(org.junit.Test)

Example 3 with RsaSsaPssKeyFormat

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

the class RsaSsaPssVerifyKeyManagerTest method createPrimitive.

@Test
public void createPrimitive() 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);
    PublicKeySign signer = signManager.getPrimitive(privateKey, PublicKeySign.class);
    PublicKeyVerify verifier = verifyManager.getPrimitive(publicKey, PublicKeyVerify.class);
    byte[] message = Random.randBytes(135);
    verifier.verify(signer.sign(message), 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 4 with RsaSsaPssKeyFormat

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

the class SignatureKeyTemplatesTest method rsaSsaPss3072.

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

Example 5 with RsaSsaPssKeyFormat

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

the class SignatureKeyTemplatesTest method rsaSsaPss4096.

@Test
public void rsaSsaPss4096() throws Exception {
    KeyTemplate template = SignatureKeyTemplates.RSA_SSA_PSS_4096_SHA512_SHA512_64_F4;
    assertEquals(new RsaSsaPssSignKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertTrue(format.hasParams());
    assertEquals(HashType.SHA512, format.getParams().getSigHash());
    assertEquals(HashType.SHA512, format.getParams().getMgf1Hash());
    assertEquals(64, format.getParams().getSaltLength());
    assertEquals(4096, format.getModulusSizeInBits());
    assertEquals(BigInteger.valueOf(65537), new BigInteger(1, format.getPublicExponent().toByteArray()));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) BigInteger(java.math.BigInteger) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) 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