Search in sources :

Example 11 with RsaSsaPssPublicKey

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

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

the class RsaSsaPssVerifyKeyManagerTest method validateKey_smallModulus.

@Test
public void validateKey_smallModulus() throws Exception {
    RsaSsaPssPublicKey publicKey = nistTestVectors[0].publicKeyProto;
    RsaSsaPssPublicKey invalidKey = RsaSsaPssPublicKey.newBuilder(publicKey).setN(ByteString.copyFrom(TestUtil.hexDecode("23"))).setE(ByteString.copyFrom(TestUtil.hexDecode("03"))).build();
    assertThrows(GeneralSecurityException.class, () -> verifyManager.validateKey(invalidKey));
}
Also used : RsaSsaPssPublicKey(com.google.crypto.tink.proto.RsaSsaPssPublicKey) Test(org.junit.Test)

Example 13 with RsaSsaPssPublicKey

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

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

the class RsaSsaPssSignKeyManagerTest method checkKey.

private void checkKey(RsaSsaPssPrivateKey privateKey) throws Exception {
    RsaSsaPssPublicKey publicKey = privateKey.getPublicKey();
    assertThat(privateKey.getVersion()).isEqualTo(0);
    assertThat(publicKey.getVersion()).isEqualTo(privateKey.getVersion());
    BigInteger p = new BigInteger(1, privateKey.getP().toByteArray());
    BigInteger q = new BigInteger(1, privateKey.getQ().toByteArray());
    BigInteger n = new BigInteger(1, privateKey.getPublicKey().getN().toByteArray());
    BigInteger d = new BigInteger(1, privateKey.getD().toByteArray());
    BigInteger dp = new BigInteger(1, privateKey.getDp().toByteArray());
    BigInteger dq = new BigInteger(1, privateKey.getDq().toByteArray());
    BigInteger crt = new BigInteger(1, privateKey.getCrt().toByteArray());
    assertThat(p).isGreaterThan(BigInteger.ONE);
    assertThat(q).isGreaterThan(BigInteger.ONE);
    assertEquals(n, p.multiply(q));
    assertEquals(dp, d.mod(p.subtract(BigInteger.ONE)));
    assertEquals(dq, d.mod(q.subtract(BigInteger.ONE)));
    assertEquals(crt, q.modInverse(p));
}
Also used : RsaSsaPssPublicKey(com.google.crypto.tink.proto.RsaSsaPssPublicKey) BigInteger(java.math.BigInteger)

Aggregations

RsaSsaPssPublicKey (com.google.crypto.tink.proto.RsaSsaPssPublicKey)14 Test (org.junit.Test)11 RsaSsaPssKeyFormat (com.google.crypto.tink.proto.RsaSsaPssKeyFormat)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 KeysetReader (com.google.crypto.tink.KeysetReader)4 KeyData (com.google.crypto.tink.proto.KeyData)4 Keyset (com.google.crypto.tink.proto.Keyset)4 RsaSsaPssPrivateKey (com.google.crypto.tink.proto.RsaSsaPssPrivateKey)4 BufferedReader (java.io.BufferedReader)4 StringReader (java.io.StringReader)4 PublicKeySign (com.google.crypto.tink.PublicKeySign)3 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)2 RsaSsaPssParams (com.google.crypto.tink.proto.RsaSsaPssParams)2 ByteString (com.google.protobuf.ByteString)2 BigInteger (java.math.BigInteger)2 EcdsaPublicKey (com.google.crypto.tink.proto.EcdsaPublicKey)1 RsaSsaPkcs1Params (com.google.crypto.tink.proto.RsaSsaPkcs1Params)1 RsaSsaPkcs1PublicKey (com.google.crypto.tink.proto.RsaSsaPkcs1PublicKey)1 IOException (java.io.IOException)1 KeyPair (java.security.KeyPair)1