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