xref: /freebsd/secure/lib/libcrypto/man/man3/ECDSA_SIG_new.3 (revision f7c32ed617858bcd22f8d1b03199099d50125721)
Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)

Standard preamble:
========================================================================
..
..
.. Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.

If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.

Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF
Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================

Title "ECDSA_SIG_NEW 3"
ECDSA_SIG_NEW 3 "2021-08-24" "1.1.1l" "OpenSSL"
For nroff, turn off justification. Always turn off hyphenation; it makes
way too many mistakes in technical documents.
"NAME"
ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0, ECDSA_SIG_new, ECDSA_SIG_free, ECDSA_size, ECDSA_sign, ECDSA_do_sign, ECDSA_verify, ECDSA_do_verify, ECDSA_sign_setup, ECDSA_sign_ex, ECDSA_do_sign_ex - low-level elliptic curve digital signature algorithm (ECDSA) functions
"SYNOPSIS"
Header "SYNOPSIS" .Vb 1 #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); 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); ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, EC_KEY *eckey); \& int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, const unsigned char *sig, int siglen, EC_KEY *eckey); int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, EC_KEY* eckey); \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp); int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); .Ve
"DESCRIPTION"
Header "DESCRIPTION" Note: these functions provide a low-level interface to \s-1ECDSA.\s0 Most applications should use the higher level \s-1EVP\s0 interface such as \fBEVP_DigestSignInit\|(3) or EVP_DigestVerifyInit\|(3) instead.

\fB\s-1ECDSA_SIG\s0 is an opaque structure consisting of two BIGNUMs for the \fBr and s value of an \s-1ECDSA\s0 signature (see X9.62 or \s-1FIPS 186-2\s0).

\fBECDSA_SIG_new() allocates an empty \s-1ECDSA_SIG\s0 structure. Note: before OpenSSL 1.1.0 the: the r and s components were initialised.

\fBECDSA_SIG_free() frees the \s-1ECDSA_SIG\s0 structure sig.

\fBECDSA_SIG_get0() returns internal pointers the r and s values contained in sig and stores them in *pr and *ps, respectively. The pointer pr or ps can be \s-1NULL,\s0 in which case the corresponding value is not returned.

The values r, s can also be retrieved separately by the corresponding function ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s(), respectively.

The r and s values can be set by calling ECDSA_SIG_set0() and passing the new values for r and s as parameters to the function. Calling this function transfers the memory management of the values to the \s-1ECDSA_SIG\s0 object, and therefore the values that have been passed in should not be freed directly after this function has been called.

See i2d_ECDSA_SIG\|(3) and d2i_ECDSA_SIG\|(3) for information about encoding and decoding \s-1ECDSA\s0 signatures to/from \s-1DER.\s0

\fBECDSA_size() returns the maximum length of a \s-1DER\s0 encoded \s-1ECDSA\s0 signature created with the private \s-1EC\s0 key eckey.

\fBECDSA_sign() computes a digital signature of the dgstlen bytes hash value \fBdgst using the private \s-1EC\s0 key eckey. The \s-1DER\s0 encoded signatures is stored in sig and its length is returned in sig_len. Note: sig must point to ECDSA_size(eckey) bytes of memory. The parameter type is currently ignored. ECDSA_sign() is wrapper function for ECDSA_sign_ex() with kinv and rp set to \s-1NULL.\s0

\fBECDSA_do_sign() is similar to ECDSA_sign() except the signature is returned as a newly allocated \s-1ECDSA_SIG\s0 structure (or \s-1NULL\s0 on error). ECDSA_do_sign() is a wrapper function for ECDSA_do_sign_ex() with kinv and rp set to \s-1NULL.\s0

\fBECDSA_verify() verifies that the signature in sig of size siglen is a valid \s-1ECDSA\s0 signature of the hash value dgst of size dgstlen using the public key eckey. The parameter type is ignored.

\fBECDSA_do_verify() is similar to ECDSA_verify() except the signature is presented in the form of a pointer to an \s-1ECDSA_SIG\s0 structure.

The remaining functions utilise the internal kinv and r values used during signature computation. Most applications will never need to call these and some external \s-1ECDSA ENGINE\s0 implementations may not support them at all if either kinv or r is not \s-1NULL\s0.

\fBECDSA_sign_setup() may be used to precompute parts of the signing operation. \fBeckey is the private \s-1EC\s0 key and ctx is a pointer to \s-1BN_CTX\s0 structure (or \s-1NULL\s0). The precomputed values or returned in kinv and rp and can be used in a later call to ECDSA_sign_ex() or ECDSA_do_sign_ex().

\fBECDSA_sign_ex() computes a digital signature of the dgstlen bytes hash value \fBdgst using the private \s-1EC\s0 key eckey and the optional pre-computed values \fBkinv and rp. The \s-1DER\s0 encoded signature is stored in sig and its length is returned in sig_len. Note: sig must point to ECDSA_size(eckey) bytes of memory. The parameter type is ignored.

\fBECDSA_do_sign_ex() is similar to ECDSA_sign_ex() except the signature is returned as a newly allocated \s-1ECDSA_SIG\s0 structure (or \s-1NULL\s0 on error).

"RETURN VALUES"
Header "RETURN VALUES" \fBECDSA_SIG_new() returns \s-1NULL\s0 if the allocation fails.

\fBECDSA_SIG_set0() returns 1 on success or 0 on failure.

\fBECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() return the corresponding value, or \s-1NULL\s0 if it is unset.

\fBECDSA_size() returns the maximum length signature or 0 on error.

\fBECDSA_sign(), ECDSA_sign_ex() and ECDSA_sign_setup() return 1 if successful or 0 on error.

\fBECDSA_do_sign() and ECDSA_do_sign_ex() return a pointer to an allocated \fB\s-1ECDSA_SIG\s0 structure or \s-1NULL\s0 on error.

\fBECDSA_verify() and ECDSA_do_verify() return 1 for a valid signature, 0 for an invalid signature and -1 on error. The error codes can be obtained by ERR_get_error\|(3).

"EXAMPLES"
Header "EXAMPLES" Creating an \s-1ECDSA\s0 signature of a given \s-1SHA-256\s0 hash value using the named curve prime256v1 (aka P-256).

First step: create an \s-1EC_KEY\s0 object (note: this part is not \s-1ECDSA\s0 specific)

.Vb 3 int ret; ECDSA_SIG *sig; EC_KEY *eckey; \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); if (eckey == NULL) /* error */ if (EC_KEY_generate_key(eckey) == 0) /* error */ .Ve

Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA-256\s0 hash value using ECDSA_do_sign():

.Vb 3 sig = ECDSA_do_sign(digest, 32, eckey); if (sig == NULL) /* error */ .Ve

or using ECDSA_sign():

.Vb 2 unsigned char *buffer, *pp; int buf_len; \& buf_len = ECDSA_size(eckey); buffer = OPENSSL_malloc(buf_len); pp = buffer; if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0) /* error */ .Ve

Third step: verify the created \s-1ECDSA\s0 signature using ECDSA_do_verify():

.Vb 1 ret = ECDSA_do_verify(digest, 32, sig, eckey); .Ve

or using ECDSA_verify():

.Vb 1 ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey); .Ve

and finally evaluate the return value:

.Vb 6 if (ret == 1) /* signature ok */ else if (ret == 0) /* incorrect signature */ else /* error */ .Ve

"CONFORMING TO"
Header "CONFORMING TO" \s-1ANSI X9.62, US\s0 Federal Information Processing Standard \s-1FIPS 186-2\s0 (Digital Signature Standard, \s-1DSS\s0)
"SEE ALSO"
Header "SEE ALSO" \fBEC_KEY_new\|(3), \fBEVP_DigestSignInit\|(3), \fBEVP_DigestVerifyInit\|(3), \fBi2d_ECDSA_SIG\|(3), \fBd2i_ECDSA_SIG\|(3)
"COPYRIGHT"
Header "COPYRIGHT" Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the OpenSSL license (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.