@@ -527,6 +527,48 @@ public IRubyObject dsa_verify_asn1(final ThreadContext context, final IRubyObjec
527527 }
528528 }
529529
530+ // sign_raw(digest, data) -- signs pre-hashed (raw) bytes with the EC private key.
531+ // Produces a DER-encoded ASN.1 SEQUENCE [r, s], identical to dsa_sign_asn1.
532+ // The digest argument is accepted for API parity with RSA/DSA sign_raw but is unused;
533+ // ECDSASigner operates directly on the supplied bytes without additional hashing.
534+ @ JRubyMethod (name = "sign_raw" )
535+ public IRubyObject sign_raw (final ThreadContext context , final IRubyObject digest , final IRubyObject data ) {
536+ return dsa_sign_asn1 (context , data );
537+ }
538+
539+ // verify_raw(digest, signature, data) -- verifies a DER-encoded ECDSA signature over raw bytes.
540+ // Returns true/false; returns false (rather than raising) for a malformed or invalid signature.
541+ // Argument order matches PKey#verify_raw convention: (digest, signature, data), unlike
542+ // dsa_verify_asn1 which takes (data, signature).
543+ @ JRubyMethod (name = "verify_raw" )
544+ public IRubyObject verify_raw (final ThreadContext context , final IRubyObject digest ,
545+ final IRubyObject sign , final IRubyObject data ) {
546+ final Ruby runtime = context .runtime ;
547+ try {
548+ final ECNamedCurveParameterSpec params = getParameterSpec ();
549+
550+ final ECDSASigner signer = new ECDSASigner ();
551+ signer .init (false , new ECPublicKeyParameters (
552+ EC5Util .convertPoint (publicKey .getParams (), publicKey .getW ()),
553+ new ECDomainParameters (params .getCurve (), params .getG (), params .getN (), params .getH ())
554+ ));
555+
556+ ASN1Primitive vec = new ASN1InputStream (sign .convertToString ().getBytes ()).readObject ();
557+ if (!(vec instanceof ASN1Sequence )) return runtime .getFalse ();
558+
559+ ASN1Sequence seq = (ASN1Sequence ) vec ;
560+ ASN1Integer r = ASN1Integer .getInstance (seq .getObjectAt (0 ));
561+ ASN1Integer s = ASN1Integer .getInstance (seq .getObjectAt (1 ));
562+
563+ boolean verified = signer .verifySignature (data .convertToString ().getBytes (), r .getPositiveValue (), s .getPositiveValue ());
564+ return runtime .newBoolean (verified );
565+ }
566+ catch (IOException | IllegalArgumentException | IllegalStateException ex ) {
567+ debugStackTrace (runtime , ex );
568+ return runtime .getFalse ();
569+ }
570+ }
571+
530572 @ JRubyMethod (name = "dh_compute_key" )
531573 public IRubyObject dh_compute_key (final ThreadContext context , final IRubyObject point ) {
532574 try {
0 commit comments