1 .\" $NetBSD: openssl_ecdsa.3,v 1.14 2015/06/12 17:01:14 christos Exp $
3 .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
6 .\" ========================================================================
7 .de Sp \" Vertical space (when we can't use .PP)
11 .de Vb \" Begin verbatim text
16 .de Ve \" End verbatim text
20 .\" Set up some character translations and predefined strings. \*(-- will
21 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
22 .\" double quote, and \*(R" will give a right double quote. \*(C+ will
23 .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
24 .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
25 .\" nothing in troff, for use with C<>.
27 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
31 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
32 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
47 .\" Escape single quotes in literal strings from groff's Unicode transform.
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
53 .\" entries marked with X<> in POD. Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
56 .\" Avoid warning from groff about undefined register 'F'.
60 .if \n(.g .if rF .nr rF 1
61 .if (\n(rF:(\n(.g==0)) \{
64 . tm Index:\\$1\t\\n%\t"\\$2"
74 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
75 .\" Fear. Run. Save yourself. No user-serviceable parts.
76 . \" fudge factors for nroff and troff
85 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
91 . \" simple accents for nroff and troff
101 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
102 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
103 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
104 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
105 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
106 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
108 . \" troff and (daisy-wheel) nroff accents
109 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
110 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
111 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
112 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
113 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
114 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
115 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
116 .ds ae a\h'-(\w'a'u*4/10)'e
117 .ds Ae A\h'-(\w'A'u*4/10)'E
118 . \" corrections for vroff
119 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
120 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
121 . \" for low resolution devices (crt and lpr)
122 .if \n(.H>23 .if \n(.V>19 \
135 .\" ========================================================================
138 .TH ecdsa 3 "2014-01-11" "1.0.1n" "OpenSSL"
139 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
140 .\" way too many mistakes in technical documents.
144 ecdsa \- Elliptic Curve Digital Signature Algorithm
148 .IX Header "SYNOPSIS"
150 \& #include <openssl/ecdsa.h>
152 \& ECDSA_SIG* ECDSA_SIG_new(void);
153 \& void ECDSA_SIG_free(ECDSA_SIG *sig);
154 \& int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
155 \& ECDSA_SIG* d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp,
158 \& ECDSA_SIG* ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
160 \& ECDSA_SIG* ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
161 \& const BIGNUM *kinv, const BIGNUM *rp,
163 \& int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
164 \& const ECDSA_SIG *sig, EC_KEY* eckey);
165 \& int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx,
166 \& BIGNUM **kinv, BIGNUM **rp);
167 \& int ECDSA_sign(int type, const unsigned char *dgst,
168 \& int dgstlen, unsigned char *sig,
169 \& unsigned int *siglen, EC_KEY *eckey);
170 \& int ECDSA_sign_ex(int type, const unsigned char *dgst,
171 \& int dgstlen, unsigned char *sig,
172 \& unsigned int *siglen, const BIGNUM *kinv,
173 \& const BIGNUM *rp, EC_KEY *eckey);
174 \& int ECDSA_verify(int type, const unsigned char *dgst,
175 \& int dgstlen, const unsigned char *sig,
176 \& int siglen, EC_KEY *eckey);
177 \& int ECDSA_size(const EC_KEY *eckey);
179 \& const ECDSA_METHOD* ECDSA_OpenSSL(void);
180 \& void ECDSA_set_default_method(const ECDSA_METHOD *meth);
181 \& const ECDSA_METHOD* ECDSA_get_default_method(void);
182 \& int ECDSA_set_method(EC_KEY *eckey,const ECDSA_METHOD *meth);
184 \& int ECDSA_get_ex_new_index(long argl, void *argp,
185 \& CRYPTO_EX_new *new_func,
186 \& CRYPTO_EX_dup *dup_func,
187 \& CRYPTO_EX_free *free_func);
188 \& int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);
189 \& void* ECDSA_get_ex_data(EC_KEY *d, int idx);
192 .IX Header "DESCRIPTION"
193 The \fB\s-1ECDSA_SIG\s0\fR structure consists of two BIGNUMs for the
194 r and s value of a \s-1ECDSA\s0 signature (see X9.62 or \s-1FIPS 186\-2\s0).
204 \&\fIECDSA_SIG_new()\fR allocates a new \fB\s-1ECDSA_SIG\s0\fR structure (note: this
205 function also allocates the BIGNUMs) and initialize it.
207 \&\fIECDSA_SIG_free()\fR frees the \fB\s-1ECDSA_SIG\s0\fR structure \fBsig\fR.
209 \&\fIi2d_ECDSA_SIG()\fR creates the \s-1DER\s0 encoding of the \s-1ECDSA\s0 signature
210 \&\fBsig\fR and writes the encoded signature to \fB*pp\fR (note: if \fBpp\fR
211 is \s-1NULL \s0\fBi2d_ECDSA_SIG\fR returns the expected length in bytes of
212 the \s-1DER\s0 encoded signature). \fBi2d_ECDSA_SIG\fR returns the length
213 of the \s-1DER\s0 encoded signature (or 0 on error).
215 \&\fId2i_ECDSA_SIG()\fR decodes a \s-1DER\s0 encoded \s-1ECDSA\s0 signature and returns
216 the decoded signature in a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure.
217 \&\fB*sig\fR points to the buffer containing the \s-1DER\s0 encoded signature
220 \&\fIECDSA_size()\fR returns the maximum length of a \s-1DER\s0 encoded
221 \&\s-1ECDSA\s0 signature created with the private \s-1EC\s0 key \fBeckey\fR.
223 \&\fIECDSA_sign_setup()\fR may be used to precompute parts of the
224 signing operation. \fBeckey\fR is the private \s-1EC\s0 key and \fBctx\fR
225 is a pointer to \fB\s-1BN_CTX\s0\fR structure (or \s-1NULL\s0). The precomputed
226 values or returned in \fBkinv\fR and \fBrp\fR and can be used in a
227 later call to \fBECDSA_sign_ex\fR or \fBECDSA_do_sign_ex\fR.
229 \&\fIECDSA_sign()\fR is wrapper function for ECDSA_sign_ex with \fBkinv\fR
230 and \fBrp\fR set to \s-1NULL.\s0
232 \&\fIECDSA_sign_ex()\fR computes a digital signature of the \fBdgstlen\fR bytes
233 hash value \fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR and the optional
234 pre-computed values \fBkinv\fR and \fBrp\fR. The \s-1DER\s0 encoded signatures is
235 stored in \fBsig\fR and it's length is returned in \fBsig_len\fR. Note: \fBsig\fR
236 must point to \fBECDSA_size\fR bytes of memory. The parameter \fBtype\fR
239 \&\fIECDSA_verify()\fR verifies that the signature in \fBsig\fR of size
240 \&\fBsiglen\fR is a valid \s-1ECDSA\s0 signature of the hash value
241 \&\fBdgst\fR of size \fBdgstlen\fR using the public key \fBeckey\fR.
242 The parameter \fBtype\fR is ignored.
244 \&\fIECDSA_do_sign()\fR is wrapper function for ECDSA_do_sign_ex with \fBkinv\fR
245 and \fBrp\fR set to \s-1NULL.\s0
247 \&\fIECDSA_do_sign_ex()\fR computes a digital signature of the \fBdgst_len\fR
248 bytes hash value \fBdgst\fR using the private key \fBeckey\fR and the
249 optional pre-computed values \fBkinv\fR and \fBrp\fR. The signature is
250 returned in a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error).
252 \&\fIECDSA_do_verify()\fR verifies that the signature \fBsig\fR is a valid
253 \&\s-1ECDSA\s0 signature of the hash value \fBdgst\fR of size \fBdgst_len\fR
254 using the public key \fBeckey\fR.
256 .IX Header "RETURN VALUES"
257 \&\fIECDSA_size()\fR returns the maximum length signature or 0 on error.
259 \&\fIECDSA_sign_setup()\fR and \fIECDSA_sign()\fR return 1 if successful or 0
262 \&\fIECDSA_verify()\fR and \fIECDSA_do_verify()\fR return 1 for a valid
263 signature, 0 for an invalid signature and \-1 on error.
264 The error codes can be obtained by \fIERR_get_error\fR\|(3).
266 .IX Header "EXAMPLES"
267 Creating a \s-1ECDSA\s0 signature of given \s-1SHA\-1\s0 hash value using the
268 named curve secp192k1.
270 First step: create a \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
277 \& eckey = EC_KEY_new_by_curve_name(NID_secp192k1);
278 \& if (eckey == NULL)
282 \& if (!EC_KEY_generate_key(eckey))
288 Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-1\s0 hash value
289 using \fBECDSA_do_sign\fR
292 \& sig = ECDSA_do_sign(digest, 20, eckey);
299 or using \fBECDSA_sign\fR
302 \& unsigned char *buffer, *pp;
304 \& buf_len = ECDSA_size(eckey);
305 \& buffer = OPENSSL_malloc(buf_len);
307 \& if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey);
313 Third step: verify the created \s-1ECDSA\s0 signature using \fBECDSA_do_verify\fR
316 \& ret = ECDSA_do_verify(digest, 20, sig, eckey);
319 or using \fBECDSA_verify\fR
322 \& ret = ECDSA_verify(0, digest, 20, buffer, buf_len, eckey);
325 and finally evaluate the return value:
332 \& else if (ret == 0)
334 \& /* incorrect signature */
336 \& else /* ret == 1 */
338 \& /* signature ok */
342 .IX Header "CONFORMING TO"
343 \&\s-1ANSI X9.62, US\s0 Federal Information Processing Standard \s-1FIPS 186\-2
344 \&\s0(Digital Signature Standard, \s-1DSS\s0)
346 .IX Header "SEE ALSO"
347 \&\fIopenssl_dsa\fR\|(3), \fIopenssl_rsa\fR\|(3)
350 The ecdsa implementation was first introduced in OpenSSL 0.9.8
353 Nils Larsch for the OpenSSL project (http://www.openssl.org).