Search in sources :

Example 21 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method getPublicKey_correctValues.

@Test
public void getPublicKey_correctValues() 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);
    assertThat(manager.getPublicKey(key)).isEqualTo(key.getPublicKey());
}
Also used : RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Example 22 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method validateKeyFormat_hashMismatchDisallowed2_throws.

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

Example 23 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method validateKeyFormat_hashMismatchDisallowed1_throws.

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

Example 24 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method createKey_smallKey.

@Test
public void createKey_smallKey() throws Exception {
    if (TestUtil.isTsan()) {
        // factory.createKey is too slow in Tsan.
        return;
    }
    RsaSsaPssKeyFormat format = createKeyFormat(HashType.SHA256, HashType.SHA256, 32, 3072, RSAKeyGenParameterSpec.F4);
    RsaSsaPssPrivateKey key = factory.createKey(format);
    checkConsistency(key, format);
    checkKey(key);
}
Also used : RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) Test(org.junit.Test)

Example 25 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method createKey_alwaysNewElement.

@Test
public void createKey_alwaysNewElement() throws Exception {
    if (TestUtil.isTsan()) {
        // factory.createKey is too slow in Tsan.
        return;
    }
    RsaSsaPssKeyFormat format = createKeyFormat(HashType.SHA256, HashType.SHA256, 32, 3072, RSAKeyGenParameterSpec.F4);
    Set<String> keys = new TreeSet<>();
    // Calls newKey multiple times and make sure that they generate different keys -- takes about a
    // second per key.
    int numTests = 5;
    for (int i = 0; i < numTests; i++) {
        RsaSsaPssPrivateKey key = factory.createKey(format);
        keys.add(TestUtil.hexEncode(key.getQ().toByteArray()));
        keys.add(TestUtil.hexEncode(key.getP().toByteArray()));
    }
    assertThat(keys).hasSize(2 * numTests);
}
Also used : RsaSsaPssPrivateKey(com.google.crypto.tink.proto.RsaSsaPssPrivateKey) TreeSet(java.util.TreeSet) RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) ByteString(com.google.protobuf.ByteString) 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