use of com.google.crypto.tink.proto.RsaSsaPssKeyFormat 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.RsaSsaPssKeyFormat 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.RsaSsaPssKeyFormat in project tink by google.
the class RsaSsaPssSignKeyManagerTest method testRsa3072PssSha256F4Template.
@Test
public void testRsa3072PssSha256F4Template() throws Exception {
KeyTemplate template = RsaSsaPssSignKeyManager.rsa3072PssSha256F4Template();
assertThat(template.getTypeUrl()).isEqualTo(new RsaSsaPssSignKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.TINK);
RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.hasParams()).isTrue();
assertThat(format.getParams().getSigHash()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getMgf1Hash()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getSaltLength()).isEqualTo(32);
assertThat(format.getModulusSizeInBits()).isEqualTo(3072);
assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(65537));
}
use of com.google.crypto.tink.proto.RsaSsaPssKeyFormat in project tink by google.
the class RsaSsaPssSignKeyManagerTest method testRawRsa4096PssSha512F4Template.
@Test
public void testRawRsa4096PssSha512F4Template() throws Exception {
KeyTemplate template = RsaSsaPssSignKeyManager.rawRsa4096PssSha512F4Template();
assertThat(template.getTypeUrl()).isEqualTo(new RsaSsaPssSignKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.hasParams()).isTrue();
assertThat(format.getParams().getSigHash()).isEqualTo(HashType.SHA512);
assertThat(format.getParams().getMgf1Hash()).isEqualTo(HashType.SHA512);
assertThat(format.getParams().getSaltLength()).isEqualTo(64);
assertThat(format.getModulusSizeInBits()).isEqualTo(4096);
assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(65537));
}
use of com.google.crypto.tink.proto.RsaSsaPssKeyFormat in project tink by google.
the class RsaSsaPssSignKeyManagerTest method testRsa4096PssSha512F4TemplateWithManager.
@Test
public void testRsa4096PssSha512F4TemplateWithManager() throws Exception {
RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(RsaSsaPssSignKeyManager.rsa4096PssSha512F4Template().getValue(), ExtensionRegistryLite.getEmptyRegistry());
new RsaSsaPssSignKeyManager().keyFactory().validateKeyFormat(format);
}
Aggregations