use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method createCorruptedModulusPrimitive_throws.
@Test
public void createCorruptedModulusPrimitive_throws() throws Exception {
RsaSsaPkcs1KeyFormat format = createKeyFormat(HashType.SHA512, 4096, RSAKeyGenParameterSpec.F4);
RsaSsaPkcs1PrivateKey originalKey = factory.createKey(format);
byte[] originalN = originalKey.getPublicKey().getN().toByteArray();
originalN[0] = (byte) (originalN[0] ^ 0x01);
ByteString corruptedN = ByteString.copyFrom(originalN);
RsaSsaPkcs1PublicKey corruptedPub = RsaSsaPkcs1PublicKey.newBuilder().setVersion(originalKey.getPublicKey().getVersion()).setN(corruptedN).setE(originalKey.getPublicKey().getE()).build();
RsaSsaPkcs1PrivateKey corruptedKey = RsaSsaPkcs1PrivateKey.newBuilder().setVersion(originalKey.getVersion()).setPublicKey(corruptedPub).setD(originalKey.getD()).setP(originalKey.getP()).setQ(originalKey.getQ()).setDp(originalKey.getDp()).setDq(originalKey.getDq()).setCrt(originalKey.getCrt()).build();
assertThrows(GeneralSecurityException.class, () -> manager.getPrimitive(corruptedKey, PublicKeySign.class));
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method testRawRsa4096SsaPkcs1Sha512F4Template.
@Test
public void testRawRsa4096SsaPkcs1Sha512F4Template() throws Exception {
KeyTemplate template = RsaSsaPkcs1SignKeyManager.rawRsa4096SsaPkcs1Sha512F4Template();
assertThat(template.getTypeUrl()).isEqualTo(new RsaSsaPkcs1SignKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
RsaSsaPkcs1KeyFormat format = RsaSsaPkcs1KeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.hasParams()).isTrue();
assertThat(format.getParams().getHashType()).isEqualTo(HashType.SHA512);
assertThat(format.getModulusSizeInBits()).isEqualTo(4096);
assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(65537));
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method getPublicKey_correctValues.
@Test
public void getPublicKey_correctValues() throws Exception {
if (TestUtil.isTsan()) {
// factory.createKey is too slow in Tsan.
return;
}
RsaSsaPkcs1KeyFormat format = createKeyFormat(HashType.SHA256, 3072, RSAKeyGenParameterSpec.F4);
RsaSsaPkcs1PrivateKey key = factory.createKey(format);
assertThat(manager.getPublicKey(key)).isEqualTo(key.getPublicKey());
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method testRsa3072SsaPkcs1Sha256F4TemplateWithManager.
@Test
public void testRsa3072SsaPkcs1Sha256F4TemplateWithManager() throws Exception {
RsaSsaPkcs1KeyFormat format = RsaSsaPkcs1KeyFormat.parseFrom(RsaSsaPkcs1SignKeyManager.rsa3072SsaPkcs1Sha256F4Template().getValue(), ExtensionRegistryLite.getEmptyRegistry());
new RsaSsaPkcs1SignKeyManager().keyFactory().validateKeyFormat(format);
}
use of com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat in project tink by google.
the class RsaSsaPkcs1SignKeyManagerTest method validateKeyFormat_smallModulusDisallowed_throws.
@Test
public void validateKeyFormat_smallModulusDisallowed_throws() throws Exception {
RsaSsaPkcs1KeyFormat format = createKeyFormat(HashType.SHA512, 1024, RSAKeyGenParameterSpec.F4);
assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
Aggregations