test_class.file: java_src/src/test/java/com/google/crypto/tink/subtle/EcdsaVerifyJceTest.java
test_class.identifier: EcdsaVerifyJceTest
test_case.body: @Test
    public void testModification() throws Exception {
      ECParameterSpec ecParams = EllipticCurves.getNistP256Params();
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
      keyGen.initialize(ecParams);
      KeyPair keyPair = keyGen.generateKeyPair();
      ECPublicKey pub = (ECPublicKey) keyPair.getPublic();
      ECPrivateKey priv = (ECPrivateKey) keyPair.getPrivate();
  
      EcdsaEncoding[] encodings = new EcdsaEncoding[] {EcdsaEncoding.IEEE_P1363, EcdsaEncoding.DER};
      for (EcdsaEncoding encoding : encodings) {
        // Sign with EcdsaSignJce
        EcdsaSignJce signer = new EcdsaSignJce(priv, HashType.SHA256, encoding);
        byte[] message = "Hello".getBytes("UTF-8");
        byte[] signature = signer.sign(message);
  
        // Verify with EcdsaVerifyJce.
        EcdsaVerifyJce verifier = new EcdsaVerifyJce(pub, HashType.SHA256, encoding);
  
        for (BytesMutation mutation : TestUtil.generateMutations(signature)) {
          try {
            verifier.verify(mutation.value, message);
            fail(
                String.format(
                    "Invalid signature, should have thrown exception : signature = %s, message = %s, "
                        + " description = %s",
                    Hex.encode(mutation.value), Arrays.toString(message), mutation.description));
          } catch (GeneralSecurityException expected) {
            // Expected.
          }
        }
  
        // Encodings mismatch.
        verifier =
            new EcdsaVerifyJce(
                pub,
                HashType.SHA256,
                encoding == EcdsaEncoding.IEEE_P1363 ? EcdsaEncoding.DER : EcdsaEncoding.IEEE_P1363);
        try {
          verifier.verify(signature, message);
          fail("Invalid signature, should have thrown exception");
        } catch (GeneralSecurityException expected) {
          // Expected.
        }
      }
    }
test_case.class_method_signature: EcdsaVerifyJceTest.testModification()
test_case.full_signature: @Test public void testModification()
test_case.identifier: testModification
test_case.invocations: getNistP256Params getInstance initialize generateKeyPair getPublic getPrivate getBytes sign generateMutations verify fail format encode toString verify fail
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testModification()
focal_class.declarator: publicKey
focal_class.modifier: private final
focal_class.original_string: private final ECPublicKey publicKey;
focal_class.type: ECPublicKey
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.declarator: encoding
focal_class.modifier: private final
focal_class.original_string: private final EcdsaEncoding encoding;
focal_class.type: EcdsaEncoding
focal_class.var_name: encoding
focal_class.file: java_src/src/main/java/com/google/crypto/tink/subtle/EcdsaVerifyJce.java
focal_class.identifier: EcdsaVerifyJce
focal_class.interfaces: implements PublicKeyVerify
focal_class.class_method_signature: EcdsaVerifyJce.EcdsaVerifyJce(final ECPublicKey pubKey, HashType hash, EcdsaEncoding encoding)
focal_class.full_signature: public  EcdsaVerifyJce(final ECPublicKey pubKey, HashType hash, EcdsaEncoding encoding)
focal_class.identifier: EcdsaVerifyJce
focal_class.modifiers: public
focal_class.parameters: (final ECPublicKey pubKey, HashType hash, EcdsaEncoding encoding)
focal_class.signature:  EcdsaVerifyJce(final ECPublicKey pubKey, HashType hash, EcdsaEncoding encoding)
focal_class.class_method_signature: EcdsaVerifyJce.verify(final byte[] signature, final byte[] data)
focal_class.full_signature: @Override public void verify(final byte[] signature, final byte[] data)
focal_class.identifier: verify
focal_class.modifiers: @Override public
focal_class.parameters: (final byte[] signature, final byte[] data)
focal_class.return: void
focal_class.signature: void verify(final byte[] signature, final byte[] data)
focal_method.body: @Override
    public void verify(final byte[] signature, final byte[] data) throws GeneralSecurityException {
      byte[] derSignature = signature;
      if (encoding == EcdsaEncoding.IEEE_P1363) {
        EllipticCurve curve = publicKey.getParams().getCurve();
        if (signature.length != 2 * EllipticCurves.fieldSizeInBytes(curve)) {
          throw new GeneralSecurityException("Invalid signature");
        }
        derSignature = EllipticCurves.ecdsaIeee2Der(signature);
      }
      if (!EllipticCurves.isValidDerEncoding(derSignature)) {
        throw new GeneralSecurityException("Invalid signature");
      }
      Signature verifier = EngineFactory.SIGNATURE.getInstance(signatureAlgorithm);
      verifier.initVerify(publicKey);
      verifier.update(data);
      boolean verified = false;
      try {
        verified = verifier.verify(derSignature);
      } catch (java.lang.RuntimeException ex) {
        verified = false;
      }
      if (!verified) {
        throw new GeneralSecurityException("Invalid signature");
      }
    }
focal_method.class_method_signature: EcdsaVerifyJce.verify(final byte[] signature, final byte[] data)
focal_method.full_signature: @Override public void verify(final byte[] signature, final byte[] data)
focal_method.identifier: verify
focal_method.invocations: getCurve getParams fieldSizeInBytes ecdsaIeee2Der isValidDerEncoding getInstance initVerify update verify
focal_method.modifiers: @Override public
focal_method.parameters: (final byte[] signature, final byte[] data)
focal_method.return: void
focal_method.signature: void verify(final byte[] signature, final byte[] data)