test_class.file: java_src/src/test/java/com/google/crypto/tink/subtle/RsaSsaPkcs1SignJceTest.java
test_class.identifier: RsaSsaPkcs1SignJceTest
test_case.body: @Test
    public void testSignWithTheSameMessage() throws Exception {
      if (TestUtil.isTsan()) {
        // This test times out when running under thread sanitizer, so we just skip.
        return;
      }
      int keySize = 4096;
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
      keyGen.initialize(keySize);
      KeyPair keyPair = keyGen.generateKeyPair();
      RSAPrivateCrtKey priv = (RSAPrivateCrtKey) keyPair.getPrivate();
      RSAPublicKey pub = (RSAPublicKey) keyPair.getPublic();
  
      byte[] msg = Random.randBytes(20);
      TreeSet<String> allSignatures = new TreeSet<String>();
      RsaSsaPkcs1SignJce signer = new RsaSsaPkcs1SignJce(priv, HashType.SHA512);
      for (int i = 0; i < 100; i++) {
        byte[] sig = signer.sign(msg);
        allSignatures.add(TestUtil.hexEncode(sig));
        // Verify with JCE's Signature.
        Signature verifier = Signature.getInstance("SHA512WithRSA");
        verifier.initVerify(pub);
        verifier.update(msg);
        if (!verifier.verify(sig)) {
          fail(
              String.format(
                  "\n\nMessage: %s\nSignature: %s\nPrivateKey: %s\nPublicKey: %s\n",
                  TestUtil.hexEncode(msg),
                  TestUtil.hexEncode(sig),
                  TestUtil.hexEncode(priv.getEncoded()),
                  TestUtil.hexEncode(pub.getEncoded())));
        }
      }
      // RSA SSA PKCS1 is deterministic, expect a unique signature for the same message.
      assertEquals(1, allSignatures.size());
    }
test_case.class_method_signature: RsaSsaPkcs1SignJceTest.testSignWithTheSameMessage()
test_case.full_signature: @Test public void testSignWithTheSameMessage()
test_case.identifier: testSignWithTheSameMessage
test_case.invocations: isTsan getInstance initialize generateKeyPair getPrivate getPublic randBytes sign add hexEncode getInstance initVerify update verify fail format hexEncode hexEncode hexEncode getEncoded hexEncode getEncoded assertEquals size
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSignWithTheSameMessage()
focal_class.declarator: privateKey
focal_class.modifier: private final
focal_class.original_string: private final RSAPrivateCrtKey privateKey;
focal_class.type: RSAPrivateCrtKey
focal_class.var_name: privateKey
focal_class.declarator: publicKey
focal_class.modifier: private final
focal_class.original_string: private final RSAPublicKey publicKey;
focal_class.type: RSAPublicKey
focal_class.var_name: publicKey
focal_class.declarator: signatureAlgorithm
focal_class.modifier: private final
focal_class.original_string: private final String signatureAlgorithm;
focal_class.type: String
focal_class.var_name: signatureAlgorithm
focal_class.file: java_src/src/main/java/com/google/crypto/tink/subtle/RsaSsaPkcs1SignJce.java
focal_class.identifier: RsaSsaPkcs1SignJce
focal_class.interfaces: implements PublicKeySign
focal_class.class_method_signature: RsaSsaPkcs1SignJce.RsaSsaPkcs1SignJce(final RSAPrivateCrtKey priv, HashType hash)
focal_class.full_signature: public  RsaSsaPkcs1SignJce(final RSAPrivateCrtKey priv, HashType hash)
focal_class.identifier: RsaSsaPkcs1SignJce
focal_class.modifiers: public
focal_class.parameters: (final RSAPrivateCrtKey priv, HashType hash)
focal_class.signature:  RsaSsaPkcs1SignJce(final RSAPrivateCrtKey priv, HashType hash)
focal_class.class_method_signature: RsaSsaPkcs1SignJce.sign(final byte[] data)
focal_class.full_signature: @Override public byte[] sign(final byte[] data)
focal_class.identifier: sign
focal_class.modifiers: @Override public
focal_class.parameters: (final byte[] data)
focal_class.return: byte[]
focal_class.signature: byte[] sign(final byte[] data)
focal_method.body: @Override
    public byte[] sign(final byte[] data) throws GeneralSecurityException {
      Signature signer = EngineFactory.SIGNATURE.getInstance(signatureAlgorithm);
      signer.initSign(privateKey);
      signer.update(data);
      byte[] signature = signer.sign();
      // Verify the signature to prevent against faulty signature computation.
      Signature verifier = EngineFactory.SIGNATURE.getInstance(signatureAlgorithm);
      verifier.initVerify(publicKey);
      verifier.update(data);
      if (!verifier.verify(signature)) {
        throw new java.lang.RuntimeException("Security bug: RSA signature computation error");
      }
      return signature;
    }
focal_method.class_method_signature: RsaSsaPkcs1SignJce.sign(final byte[] data)
focal_method.full_signature: @Override public byte[] sign(final byte[] data)
focal_method.identifier: sign
focal_method.invocations: getInstance initSign update sign getInstance initVerify update verify
focal_method.modifiers: @Override public
focal_method.parameters: (final byte[] data)
focal_method.return: byte[]
focal_method.signature: byte[] sign(final byte[] data)