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);
}
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));
}
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));
}
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));
}
Aggregations