HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //usr/local/openssl/man/man3/ECDSA_sign_setup.3
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" 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'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "ecdsa 3"
.TH ecdsa 3 2019-12-20 1.0.2u OpenSSL
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
ECDSA_SIG_new, ECDSA_SIG_free, i2d_ECDSA_SIG, d2i_ECDSA_SIG, ECDSA_size, ECDSA_sign_setup, ECDSA_sign, ECDSA_sign_ex, ECDSA_verify, ECDSA_do_sign, ECDSA_do_sign_ex, ECDSA_do_verify \- Elliptic Curve Digital Signature Algorithm
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 1
\& #include <openssl/ecdsa.h>
\&
\& ECDSA_SIG*     ECDSA_SIG_new(void);
\& void           ECDSA_SIG_free(ECDSA_SIG *sig);
\& int            i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
\& ECDSA_SIG*     d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, 
\&                long len);
\&
\& ECDSA_SIG*     ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
\&                        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_do_verify(const unsigned char *dgst, int dgst_len,
\&                        const ECDSA_SIG *sig, EC_KEY* eckey);
\& int            ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx,
\&                        BIGNUM **kinv, BIGNUM **rp);
\& int            ECDSA_sign(int type, const unsigned char *dgst,
\&                        int dgstlen, unsigned char *sig,
\&                        unsigned int *siglen, EC_KEY *eckey);
\& 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);
\& int            ECDSA_verify(int type, const unsigned char *dgst,
\&                        int dgstlen, const unsigned char *sig,
\&                        int siglen, EC_KEY *eckey);
\& int            ECDSA_size(const EC_KEY *eckey);
\&
\& const ECDSA_METHOD*    ECDSA_OpenSSL(void);
\& void           ECDSA_set_default_method(const ECDSA_METHOD *meth);
\& const ECDSA_METHOD*    ECDSA_get_default_method(void);
\& int            ECDSA_set_method(EC_KEY *eckey,const ECDSA_METHOD *meth);
\&
\& int            ECDSA_get_ex_new_index(long argl, void *argp,
\&                        CRYPTO_EX_new *new_func,
\&                        CRYPTO_EX_dup *dup_func,
\&                        CRYPTO_EX_free *free_func);
\& int            ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);
\& void*          ECDSA_get_ex_data(EC_KEY *d, int idx);
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
The \fBECDSA_SIG\fR structure consists of two BIGNUMs for the
r and s value of a ECDSA signature (see X9.62 or FIPS 186\-2).
.PP
.Vb 5
\& struct
\&        {
\&        BIGNUM *r;
\&        BIGNUM *s;
\& } ECDSA_SIG;
.Ve
.PP
\&\fBECDSA_SIG_new()\fR allocates a new \fBECDSA_SIG\fR structure (note: this
function also allocates the BIGNUMs) and initialize it.
.PP
\&\fBECDSA_SIG_free()\fR frees the \fBECDSA_SIG\fR structure \fBsig\fR.
.PP
\&\fBi2d_ECDSA_SIG()\fR creates the DER encoding of the ECDSA signature
\&\fBsig\fR and writes the encoded signature to \fB*pp\fR (note: if \fBpp\fR
is NULL \fBi2d_ECDSA_SIG\fR returns the expected length in bytes of 
the DER encoded signature). \fBi2d_ECDSA_SIG\fR returns the length
of the DER encoded signature (or 0 on error).
.PP
\&\fBd2i_ECDSA_SIG()\fR decodes a DER encoded ECDSA signature and returns
the decoded signature in a newly allocated \fBECDSA_SIG\fR structure.
\&\fB*sig\fR points to the buffer containing the DER encoded signature
of size \fBlen\fR.
.PP
\&\fBECDSA_size()\fR returns the maximum length of a DER encoded
ECDSA signature created with the private EC key \fBeckey\fR.
.PP
\&\fBECDSA_sign_setup()\fR may be used to precompute parts of the
signing operation. \fBeckey\fR is the private EC key and \fBctx\fR
is a pointer to \fBBN_CTX\fR structure (or NULL). The precomputed
values or returned in \fBkinv\fR and \fBrp\fR and can be used in a
later call to \fBECDSA_sign_ex\fR or \fBECDSA_do_sign_ex\fR.
.PP
\&\fBECDSA_sign()\fR is wrapper function for ECDSA_sign_ex with \fBkinv\fR
and \fBrp\fR set to NULL.
.PP
\&\fBECDSA_sign_ex()\fR computes a digital signature of the \fBdgstlen\fR bytes
hash value \fBdgst\fR using the private EC key \fBeckey\fR and the optional
pre-computed values \fBkinv\fR and \fBrp\fR. The DER encoded signatures is
stored in \fBsig\fR and it's length is returned in \fBsig_len\fR. Note: \fBsig\fR
must point to \fBECDSA_size\fR bytes of memory. The parameter \fBtype\fR
is ignored.
.PP
\&\fBECDSA_verify()\fR verifies that the signature in \fBsig\fR of size
\&\fBsiglen\fR is a valid ECDSA signature of the hash value
\&\fBdgst\fR of size \fBdgstlen\fR using the public key \fBeckey\fR.
The parameter \fBtype\fR is ignored.
.PP
\&\fBECDSA_do_sign()\fR is wrapper function for ECDSA_do_sign_ex with \fBkinv\fR
and \fBrp\fR set to NULL.
.PP
\&\fBECDSA_do_sign_ex()\fR computes a digital signature of the \fBdgst_len\fR
bytes hash value \fBdgst\fR using the private key \fBeckey\fR and the
optional pre-computed values \fBkinv\fR and \fBrp\fR. The signature is
returned in a newly allocated \fBECDSA_SIG\fR structure (or NULL on error).
.PP
\&\fBECDSA_do_verify()\fR verifies that the signature \fBsig\fR is a valid
ECDSA signature of the hash value \fBdgst\fR of size \fBdgst_len\fR
using the public key \fBeckey\fR.
.SH "RETURN VALUES"
.IX Header "RETURN VALUES"
\&\fBECDSA_SIG_new()\fR returns NULL if the allocation fails.
.PP
\&\fBECDSA_size()\fR returns the maximum length signature or 0 on error.
.PP
\&\fBECDSA_sign_setup()\fR and \fBECDSA_sign()\fR return 1 if successful or 0
on error.
.PP
\&\fBECDSA_verify()\fR and \fBECDSA_do_verify()\fR return 1 for a valid
signature, 0 for an invalid signature and \-1 on error.
The error codes can be obtained by \fBERR_get_error\fR\|(3).
.SH EXAMPLES
.IX Header "EXAMPLES"
Creating a ECDSA signature of given SHA\-1 hash value using the
named curve secp192k1.
.PP
First step: create a EC_KEY object (note: this part is \fBnot\fR ECDSA
specific)
.PP
.Vb 12
\& int        ret;
\& ECDSA_SIG *sig;
\& EC_KEY    *eckey;
\& eckey = EC_KEY_new_by_curve_name(NID_secp192k1);
\& if (eckey == NULL)
\&        {
\&        /* error */
\&        }
\& if (!EC_KEY_generate_key(eckey))
\&        {
\&        /* error */
\&        }
.Ve
.PP
Second step: compute the ECDSA signature of a SHA\-1 hash value 
using \fBECDSA_do_sign\fR
.PP
.Vb 5
\& sig = ECDSA_do_sign(digest, 20, eckey);
\& if (sig == NULL)
\&        {
\&        /* error */
\&        }
.Ve
.PP
or using \fBECDSA_sign\fR
.PP
.Vb 9
\& 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);
\&        {
\&        /* error */
\&        }
.Ve
.PP
Third step: verify the created ECDSA signature using \fBECDSA_do_verify\fR
.PP
.Vb 1
\& ret = ECDSA_do_verify(digest, 20, sig, eckey);
.Ve
.PP
or using \fBECDSA_verify\fR
.PP
.Vb 1
\& ret = ECDSA_verify(0, digest, 20, buffer, buf_len, eckey);
.Ve
.PP
and finally evaluate the return value:
.PP
.Vb 12
\& if (ret == \-1)
\&        {
\&        /* error */
\&        }
\& else if (ret == 0)
\&        {
\&        /* incorrect signature */
\&        }
\& else   /* ret == 1 */
\&        {
\&        /* signature ok */
\&        }
.Ve
.SH "CONFORMING TO"
.IX Header "CONFORMING TO"
ANSI X9.62, US Federal Information Processing Standard FIPS 186\-2
(Digital Signature Standard, DSS)
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fBdsa\fR\|(3), \fBrsa\fR\|(3)
.SH HISTORY
.IX Header "HISTORY"
The ecdsa implementation was first introduced in OpenSSL 0.9.8
.SH AUTHOR
.IX Header "AUTHOR"
Nils Larsch for the OpenSSL project (http://www.openssl.org).