Search in sources :

Example 26 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method testRawRsa3072PssSha256F4Template.

@Test
public void testRawRsa3072PssSha256F4Template() throws Exception {
    KeyTemplate template = RsaSsaPssSignKeyManager.rawRsa3072PssSha256F4Template();
    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.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));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) BigInteger(java.math.BigInteger) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 27 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method createKey_largeKey.

@Test
public void createKey_largeKey() 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);
    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 28 with RsaSsaPssKeyFormat

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

the class RsaSsaPssSignKeyManagerTest method testRsa4096PssSha512F4Template.

@Test
public void testRsa4096PssSha512F4Template() throws Exception {
    KeyTemplate template = RsaSsaPssSignKeyManager.rsa4096PssSha512F4Template();
    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.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));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) BigInteger(java.math.BigInteger) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 29 with RsaSsaPssKeyFormat

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

the class SignatureKeyTemplates method createRsaSsaPssKeyTemplate.

/**
 * @return a {@link KeyTemplate} containing a {@link RsaSsaPssKeyFormat} with some specified
 *     parameters.
 */
public static KeyTemplate createRsaSsaPssKeyTemplate(HashType sigHash, HashType mgf1Hash, int saltLength, int modulusSize, BigInteger publicExponent) {
    RsaSsaPssParams params = RsaSsaPssParams.newBuilder().setSigHash(sigHash).setMgf1Hash(mgf1Hash).setSaltLength(saltLength).build();
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.newBuilder().setParams(params).setModulusSizeInBits(modulusSize).setPublicExponent(ByteString.copyFrom(publicExponent.toByteArray())).build();
    return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(new RsaSsaPssSignKeyManager().getKeyType()).setOutputPrefixType(OutputPrefixType.TINK).build();
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) RsaSsaPssParams(com.google.crypto.tink.proto.RsaSsaPssParams)

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