ECDSA_SIG_NEW(3)
π ECDSA_SIG_NEW(3) π
okay so bestie, welcome to the ECDSA_SIG_NEW(3) glow-up π
this one is from the Library Functions Manual, and it's literally all about the Elliptic Curve Digital Signature Algorithm β ECDSA for short, iykyk π¦β¨
πΈ NAME πΈ
The whole squad on this page is: ECDSA_SIG_new, ECDSA_SIG_free, ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0, i2d_ECDSA_SIG, d2i_ECDSA_SIG, ECDSA_size, ECDSA_sign, ECDSA_verify, ECDSA_do_sign, ECDSA_do_verify β and together they're serving Elliptic Curve Digital Signature Algorithm. periodt π
β¨ SYNOPSIS β¨
This is the libcrypto era, so include the header exactly like this:
library βlibcryptoβ #include <openssl/ec.h>
And here's the full function lineup, no cap:
ECDSA_SIG *
ECDSA_SIG_new(void);
void
ECDSA_SIG_free(ECDSA_SIG *sig);
void
ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **r,
const BIGNUM **s);
const BIGNUM *
ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
const BIGNUM *
ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
int
ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
int
i2d_ECDSA_SIG(const ECDSA_SIG *sig_in, unsigned char **der_out);
ECDSA_SIG *
d2i_ECDSA_SIG(ECDSA_SIG **sig_out, const unsigned char **der_in,
long len);
int
ECDSA_size(const EC_KEY *eckey);
int
ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
int
ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
const unsigned char *sig, int siglen, EC_KEY *eckey);
ECDSA_SIG *
ECDSA_do_sign(const unsigned char *dgst, int dgst_len, EC_KEY *eckey);
int
ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
const ECDSA_SIG *sig, EC_KEY* eckey);
π¦ DESCRIPTION π¦
okay so here's the tea: these functions are the low level interface to ECDSA. Most applications should use the higher level EVP interface, like EVP_DigestSignInit(3) or EVP_DigestVerifyInit(3), instead. Creation of the required EC_KEY objects is described in EC_KEY_new(3). π«Ά
The ECDSA_SIG structure consists of two BIGNUMs for the r and s value of an ECDSA signature (see X9.62 or FIPS 186-2). It's giving very tiny but very important:
struct {
BIGNUM *r;
BIGNUM *s;
} ECDSA_SIG;
ECDSA_SIG_new()β allocates a newECDSA_SIGstructure (note: this function also allocates theBIGNUMs) and initializes it. πECDSA_SIG_free()β frees theECDSA_SIGstructuresig. bye bestie πECDSA_SIG_get0()β retrieves internal pointers for therandsvalues contained insig. The valuesrandscan also be retrieved separately by the corresponding functionECDSA_SIG_get0_r()andECDSA_SIG_get0_s(), respectively. πECDSA_SIG_set0()β sets therandsvalues insig. Calling this function transfers the memory management of the values tosig. Therefore, the values that have been passed in should not be freed by the caller.
warning bestie: onceECDSA_SIG_set0()takes over, thesigowns that memory β do not free the values you passed in π«Ά
i2d_ECDSA_SIG()β creates the DER encoding of the ECDSA signaturesig_inand writes the encoded signature to*der_out.d2i_ECDSA_SIG()β decodes the DER-encoded signature stored in the buffer*der_inwhich islenbytes long into*sig_out. For details about the semantics, examples, caveats, and bugs, seeASN1_item_d2i(3). π§ECDSA_size()β returns the maximum length of a DER-encoded ECDSA signature created with the private EC keyeckey.ECDSA_sign()β computes a digital signature of thedgstlenbytes hash valuedgstusing the private EC keyeckey. The DER-encoded signature is stored insigand its length is returned insiglen. Note:sigmust point toECDSA_size()bytes of memory. The parametertypeis ignored. π₯ECDSA_verify()β verifies that the signature insigof sizesiglenis a valid ECDSA signature of the hash valuedgstof sizedgstlenusing the public keyeckey. The parametertypeis ignored. βECDSA_do_sign()β computes a digital signature of thedgst_lenbytes hash valuedgstusing the private keyeckey. The signature is returned in a newly allocatedECDSA_SIGstructure (orNULLon error). πECDSA_do_verify()β verifies that the signaturesigis a valid ECDSA signature of the hash valuedgstof sizedgst_lenusing the public keyeckey. π
π RETURN VALUES π
ECDSA_SIG_new()β returns the newECDSA_SIGobject orNULLif an error occurs.i2d_ECDSA_SIG()β returns the number of bytes successfully encoded or a negative value if an error occurs.d2i_ECDSA_SIG()β returns a pointer to the decodedECDSA_SIGstructure orNULLif an error occurs.ECDSA_size()β returns the maximum length signature or0on error.ECDSA_SIG_get0_r()andECDSA_SIG_get0_s()β return a pointer owned by theECDSA_SIGobject if it has been set orNULLotherwise.ECDSA_SIG_set0()andECDSA_sign()β return1if successful or0on error.ECDSA_do_sign()β returns a pointer to an allocatedECDSA_SIGstructure orNULLon error.ECDSA_verify()andECDSA_do_verify()β return1for a valid signature,0for an invalid signature and-1on error. The error codes can be obtained byERR_get_error(3). π
π EXAMPLES π
Creating an ECDSA signature of given SHA-384 hash value using the named curve secp384r1. okay this is the whole little routine, bestie:
First step: create an EC_KEY object. This part is not ECDSA specific.
int ret;
ECDSA_SIG *sig;
EC_KEY *eckey;
eckey = EC_KEY_new_by_curve_name(NID_secp384r1);
if (eckey == NULL) {
/* error */
}
if (!EC_KEY_generate_key(eckey)) {
/* error */
}
Second step: compute the ECDSA signature of a SHA-384 hash value using ECDSA_do_sign()
sig = ECDSA_do_sign(digest, SHA384_DIGEST_LENGTH, eckey);
if (sig == NULL) {
/* error */
}
or using ECDSA_sign()
unsigned char *buffer, *pp;
int buf_len;
buf_len = ECDSA_size(eckey);
buffer = malloc(buf_len);
pp = buffer;
if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) {
/* error */
}
Third step: verify the created ECDSA signature using ECDSA_do_verify()
ret = ECDSA_do_verify(digest, SHA384_DIGEST_LENGTH, sig, eckey);
or using ECDSA_verify()
ret = ECDSA_verify(0, digest, SHA384_DIGEST_LENGTH, buffer,
buf_len, eckey);
and finally evaluate the return value:
if (ret == -1) {
/* error */
} else if (ret == 0) {
/* incorrect signature */
} else {
/* ret == 1 */
/* signature ok */
}
π₯ SEE ALSO π₯
crypto(3), d2i_ECPKParameters(3), DSA_new(3), EC_GROUP_new_by_curve_name(3), EC_KEY_METHOD_new(3), EC_KEY_new(3), EC_KEY_set_ex_data(3), EVP_DigestSignInit(3), EVP_DigestVerifyInit(3), RSA_new(3). the whole linked-list friend group is here π«Άβ¨
π STANDARDS π
ANSI X9.62, US Federal Information Processing Standard FIPS 186-5 (Digital Signature Standard, DSS). iconic behavior π
π HISTORY π
ECDSA_SIG_new(), ECDSA_SIG_free(), i2d_ECDSA_SIG(), d2i_ECDSA_SIG(), ECDSA_size(), ECDSA_sign(), ECDSA_verify(), ECDSA_do_sign(), and ECDSA_do_verify() first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5. π¦
ECDSA_SIG_get0() and ECDSA_SIG_set0() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.3. ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() first appeared in OpenSSL 1.1.1 and have been available since OpenBSD 7.1. β
π«Ά AUTHORS π«Ά
Nils Larsch for the OpenSSL project. shoutout to Nils, absolute icon ππ
xoxo, this page came from Debian, dated June 13, 2025, and it's literally ECDSA_SIG_NEW(3). bye bestie, go sign something cute π
β¨π¦
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2004, 2005, 2013, 2016 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms