Non-DER format ECDSA with EVP_DigestSign() in OpenSSL

Viewed 108

I want to use EVP_DigestSign() for ECDSA signing because it works for OpenSSL 1.1.1 and OpenSSL 3.x and it can be used for RSA and other.

I have it working, but the output I get is the DER-encoded ECDSA signature. I just want the r and s values without the DER wrapping. (I am implementing COSE, RFC 9052, and it doesn't use DER).

I can get this with ECDSA_do_sign() but this function is to be deprecated.

How to I control the output format of EVP_DigestSign()?

1 Answers

Sign as normal using EVP_DigestSign(). Take the signature that is emitted and pass it to the d2i_ECDSA_SIG function to create an ECDSA_SIG object (note that this is not deprecated in 3.0). Then you can use ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() to extract the r and s values from it.

d2i_ECDSA_SIG is documented on this page: https://www.openssl.org/docs/man3.0/man3/d2i_ECDSA_SIG.html

ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() are documented on this page: https://www.openssl.org/docs/man3.0/man3/ECDSA_SIG_get0_r.html

Related