ECDSA_SIG_NEW(3ossl)
π ECDSA_SIG_NEW π
okay bestie, welcome to ECDSA_SIG_NEW(3ossl) β yes the manpage name is literally ECDSA_SIG_NEW but it's actually a whole lil family of functions: ECDSA_SIG_new, ECDSA_SIG_free, ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, and ECDSA_SIG_set0. They're all about creating, destroying and manipulating ECDSA_SIG objects. grab a snack, we're going in π
β¨ SYNOPSIS β¨
#include <openssl/ecdsa.h>
ECDSA_SIG *ECDSA_SIG_new(void);
void ECDSA_SIG_free(ECDSA_SIG *sig);
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
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);
πΈ DESCRIPTION πΈ
so <pink>ECDSA_SIG</pink> is an opaque structure β meaning you can't just peek inside, it's giving mysterious π
. It holds two <purple>BIGNUM</purple>s: the r and s values of an Elliptic Curve Digital Signature Algorithm (ECDSA) signature (peep FIPS186-4 or X9.62 if you wanna read the receipts).
the ECDSA_SIG object was mainly used by the deprecated low level functions described in ECDSA_sign(3) β ngl, deprecated is deprecated, but it's still required if you wanna be able to set or get the r and s values into or from a signature. This is mainly used for testing purposes, as shown in the "EXAMPLES" section. iykyk π§
ECDSA_SIG_new()β allocates an emptyECDSA_SIGstructure. β οΈ note: before OpenSSL 1.1.0, therandscomponents were initialised. not anymore, bestie, they start empty now.ECDSA_SIG_free()β frees theECDSA_SIGstructuresig. If the argument isNULL, nothing is done. (very demure, very mindful π«Ά)ECDSA_SIG_get0()β returns internal pointers to therandsvalues contained insig, and stores them in*prand*ps, respectively. The pointerprorpscan beNULL, in which case the corresponding value is not returned. no drama, just skipping πECDSA_SIG_get0_r()andECDSA_SIG_get0_s()β the valuesr,scan also be retrieved separately by these corresponding functions, respectively. one at a time, main character energy πECDSA_SIG_set0()β Non-NULLrandsvalues can be set on thesigby calling this. π¨ important, bestie: calling this function transfers the memory management of the values to theECDSA_SIGobject, and therefore the values that have been passed in should not be freed by the caller. the object owns them now, periodt.
also seei2d_ECDSA_SIG(3)andd2i_ECDSA_SIG(3)for info about encoding and decoding ECDSA signatures to/from DER. π
π RETURN VALUES π
ECDSA_SIG_new()returnsNULLif the allocation fails. πECDSA_SIG_set0()returns1on success or0on failure.ECDSA_SIG_get0_r()andECDSA_SIG_get0_s()return the corresponding value, orNULLif it is unset.
π¦ EXAMPLES π¦
extract signature r and s values from a ECDSA signature of size signaturelen:
ECDSA_SIG *obj;
const BIGNUM *r, *s;
/* Load a signature into the ECDSA_SIG object */
obj = d2i_ECDSA_SIG(NULL, &signature, signaturelen);
if (obj == NULL)
/* error */
r = ECDSA_SIG_get0_r(obj);
s = ECDSA_SIG_get0_s(obj);
if (r == NULL || s == NULL)
/* error */
/* Use BN_bn2binpad() here to convert to r and s into byte arrays */
/*
* Do not try to access I<r> or I<s> after calling ECDSA_SIG_free(),
* as they are both freed by this call.
*/
ECDSA_SIG_free(obj);
convert r and s byte arrays into an ECDSA_SIG signature of size signaturelen:
ECDSA_SIG *obj = NULL;
unsigned char *signature = NULL;
size_t signaturelen;
BIGNUM *rbn = NULL, *sbn = NULL;
obj = ECDSA_SIG_new();
if (obj == NULL)
/* error */
rbn = BN_bin2bn(r, rlen, NULL);
sbn = BN_bin2bn(s, slen, NULL);
if (rbn == NULL || sbn == NULL)
/* error */
if (!ECDSA_SIG_set0(obj, rbn, sbn))
/* error */
/* Set these to NULL since they are now owned by obj */
rbn = sbn = NULL;
signaturelen = i2d_ECDSA_SIG(obj, &signature);
if (signaturelen <= 0)
/* error */
/*
* This signature could now be passed to L<EVP_DigestVerify(3)>
* or L<EVP_DigestVerifyFinal(3)>
*/
BN_free(rbn);
BN_free(sbn);
OPENSSL_free(signature);
ECDSA_SIG_free(obj);
π CONFORMING TO π
ANSI X9.62, US Federal Information Processing Standard FIPS186-4 (Digital Signature Standard, DSS). certified iconic behavior, no cap β
π₯ SEE ALSO π₯
EC_KEY_new(3), EVP_DigestSignInit(3), EVP_DigestVerifyInit(3), EVP_PKEY_sign(3) i2d_ECDSA_SIG(3), d2i_ECDSA_SIG(3), ECDSA_sign(3)
π COPYRIGHT π
Copyright 2004-2024 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay that's the whole page, bestie, you ate that π«Ά this was version 3.5.9, dated 2026-09-29, from the ECDSA_SIG_NEW(3ossl) manual β go forth and manipulate those signatures, slay πβ¨π
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms