]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/ECDSA_SIG_new.3
MFC: r344602
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / ECDSA_SIG_new.3
1 .\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
60 .    if \nF \{\
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{\
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "ECDSA_SIG_NEW 3"
136 .TH ECDSA_SIG_NEW 3 "2019-02-26" "1.1.1b" "OpenSSL"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0, ECDSA_SIG_new, ECDSA_SIG_free, i2d_ECDSA_SIG, d2i_ECDSA_SIG, 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
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 1
146 \& #include <openssl/ecdsa.h>
147 \&
148 \& ECDSA_SIG *ECDSA_SIG_new(void);
149 \& void ECDSA_SIG_free(ECDSA_SIG *sig);
150 \& void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
151 \& const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
152 \& const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
153 \& int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
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, long len);
156 \& int ECDSA_size(const EC_KEY *eckey);
157 \&
158 \& int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
159 \&                unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
160 \& ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
161 \&                          EC_KEY *eckey);
162 \&
163 \& int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
164 \&                  const unsigned char *sig, int siglen, EC_KEY *eckey);
165 \& int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
166 \&                     const ECDSA_SIG *sig, EC_KEY* eckey);
167 \&
168 \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
169 \&                             const BIGNUM *kinv, const BIGNUM *rp,
170 \&                             EC_KEY *eckey);
171 \& int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
172 \& int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
173 \&                   unsigned char *sig, unsigned int *siglen,
174 \&                   const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
175 .Ve
176 .SH "DESCRIPTION"
177 .IX Header "DESCRIPTION"
178 Note: these functions provide a low level interface to \s-1ECDSA.\s0 Most
179 applications should use the higher level \fB\s-1EVP\s0\fR interface such as
180 \&\fBEVP_DigestSignInit\fR\|(3) or \fBEVP_DigestVerifyInit\fR\|(3) instead.
181 .PP
182 \&\fB\s-1ECDSA_SIG\s0\fR is an opaque structure consisting of two BIGNUMs for the
183 \&\fBr\fR and \fBs\fR value of an \s-1ECDSA\s0 signature (see X9.62 or \s-1FIPS 186\-2\s0).
184 .PP
185 \&\fBECDSA_SIG_new()\fR allocates an empty \fB\s-1ECDSA_SIG\s0\fR structure. Note: before
186 OpenSSL 1.1.0 the: the \fBr\fR and \fBs\fR components were initialised.
187 .PP
188 \&\fBECDSA_SIG_free()\fR frees the \fB\s-1ECDSA_SIG\s0\fR structure \fBsig\fR.
189 .PP
190 \&\fBECDSA_SIG_get0()\fR returns internal pointers the \fBr\fR and \fBs\fR values contained
191 in \fBsig\fR and stores them in \fB*pr\fR and \fB*ps\fR, respectively.
192 The pointer \fBpr\fR or \fBps\fR can be \s-1NULL,\s0 in which case the corresponding value
193 is not returned.
194 .PP
195 The values \fBr\fR, \fBs\fR can also be retrieved separately by the corresponding
196 function \fBECDSA_SIG_get0_r()\fR and \fBECDSA_SIG_get0_s()\fR, respectively.
197 .PP
198 The \fBr\fR and \fBs\fR values can be set by calling \fBECDSA_SIG_set0()\fR and passing the
199 new values for \fBr\fR and \fBs\fR as parameters to the function. Calling this
200 function transfers the memory management of the values to the \s-1ECDSA_SIG\s0 object,
201 and therefore the values that have been passed in should not be freed directly
202 after this function has been called.
203 .PP
204 \&\fBi2d_ECDSA_SIG()\fR creates the \s-1DER\s0 encoding of the \s-1ECDSA\s0 signature \fBsig\fR and
205 writes the encoded signature to \fB*pp\fR (note: if \fBpp\fR is \s-1NULL\s0 \fBi2d_ECDSA_SIG()\fR
206 returns the expected length in bytes of the \s-1DER\s0 encoded signature).
207 \&\fBi2d_ECDSA_SIG()\fR returns the length of the \s-1DER\s0 encoded signature (or 0 on
208 error).
209 .PP
210 \&\fBd2i_ECDSA_SIG()\fR decodes a \s-1DER\s0 encoded \s-1ECDSA\s0 signature and returns the decoded
211 signature in a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure. \fB*sig\fR points to the
212 buffer containing the \s-1DER\s0 encoded signature of size \fBlen\fR.
213 .PP
214 \&\fBECDSA_size()\fR returns the maximum length of a \s-1DER\s0 encoded \s-1ECDSA\s0 signature
215 created with the private \s-1EC\s0 key \fBeckey\fR.
216 .PP
217 \&\fBECDSA_sign()\fR computes a digital signature of the \fBdgstlen\fR bytes hash value
218 \&\fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR. The \s-1DER\s0 encoded signatures is
219 stored in \fBsig\fR and its length is returned in \fBsig_len\fR. Note: \fBsig\fR must
220 point to ECDSA_size(eckey) bytes of memory. The parameter \fBtype\fR is currently
221 ignored. \fBECDSA_sign()\fR is wrapper function for \fBECDSA_sign_ex()\fR with \fBkinv\fR
222 and \fBrp\fR set to \s-1NULL.\s0
223 .PP
224 \&\fBECDSA_do_sign()\fR is similar to \fBECDSA_sign()\fR except the signature is returned
225 as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error). \fBECDSA_do_sign()\fR
226 is a wrapper function for \fBECDSA_do_sign_ex()\fR with \fBkinv\fR and \fBrp\fR set to
227 \&\s-1NULL.\s0
228 .PP
229 \&\fBECDSA_verify()\fR verifies that the signature in \fBsig\fR of size \fBsiglen\fR is a
230 valid \s-1ECDSA\s0 signature of the hash value \fBdgst\fR of size \fBdgstlen\fR using the
231 public key \fBeckey\fR.  The parameter \fBtype\fR is ignored.
232 .PP
233 \&\fBECDSA_do_verify()\fR is similar to \fBECDSA_verify()\fR except the signature is
234 presented in the form of a pointer to an \fB\s-1ECDSA_SIG\s0\fR structure.
235 .PP
236 The remaining functions utilise the internal \fBkinv\fR and \fBr\fR values used
237 during signature computation. Most applications will never need to call these
238 and some external \s-1ECDSA ENGINE\s0 implementations may not support them at all if
239 either \fBkinv\fR or \fBr\fR is not \fB\s-1NULL\s0\fR.
240 .PP
241 \&\fBECDSA_sign_setup()\fR may be used to precompute parts of the signing operation.
242 \&\fBeckey\fR is the private \s-1EC\s0 key and \fBctx\fR is a pointer to \fB\s-1BN_CTX\s0\fR structure
243 (or \s-1NULL\s0). The precomputed values or returned in \fBkinv\fR and \fBrp\fR and can be
244 used in a later call to \fBECDSA_sign_ex()\fR or \fBECDSA_do_sign_ex()\fR.
245 .PP
246 \&\fBECDSA_sign_ex()\fR computes a digital signature of the \fBdgstlen\fR bytes hash value
247 \&\fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR and the optional pre-computed values
248 \&\fBkinv\fR and \fBrp\fR. The \s-1DER\s0 encoded signature is stored in \fBsig\fR and its
249 length is returned in \fBsig_len\fR. Note: \fBsig\fR must point to ECDSA_size(eckey)
250 bytes of memory. The parameter \fBtype\fR is ignored.
251 .PP
252 \&\fBECDSA_do_sign_ex()\fR is similar to \fBECDSA_sign_ex()\fR except the signature is
253 returned as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error).
254 .SH "RETURN VALUES"
255 .IX Header "RETURN VALUES"
256 \&\fBECDSA_SIG_new()\fR returns \s-1NULL\s0 if the allocation fails.
257 .PP
258 \&\fBECDSA_SIG_set0()\fR returns 1 on success or 0 on failure.
259 .PP
260 \&\fBECDSA_SIG_get0_r()\fR and \fBECDSA_SIG_get0_s()\fR return the corresponding value,
261 or \s-1NULL\s0 if it is unset.
262 .PP
263 \&\fBECDSA_size()\fR returns the maximum length signature or 0 on error.
264 .PP
265 \&\fBECDSA_sign()\fR, \fBECDSA_sign_ex()\fR and \fBECDSA_sign_setup()\fR return 1 if successful
266 or 0 on error.
267 .PP
268 \&\fBECDSA_do_sign()\fR and \fBECDSA_do_sign_ex()\fR return a pointer to an allocated
269 \&\fB\s-1ECDSA_SIG\s0\fR structure or \s-1NULL\s0 on error.
270 .PP
271 \&\fBECDSA_verify()\fR and \fBECDSA_do_verify()\fR return 1 for a valid
272 signature, 0 for an invalid signature and \-1 on error.
273 The error codes can be obtained by \fBERR_get_error\fR\|(3).
274 .SH "EXAMPLES"
275 .IX Header "EXAMPLES"
276 Creating an \s-1ECDSA\s0 signature of a given \s-1SHA\-256\s0 hash value using the
277 named curve prime256v1 (aka P\-256).
278 .PP
279 First step: create an \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
280 specific)
281 .PP
282 .Vb 3
283 \& int ret;
284 \& ECDSA_SIG *sig;
285 \& EC_KEY *eckey;
286 \&
287 \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
288 \& if (eckey == NULL)
289 \&     /* error */
290 \& if (EC_KEY_generate_key(eckey) == 0)
291 \&     /* error */
292 .Ve
293 .PP
294 Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-256\s0 hash value
295 using \fBECDSA_do_sign()\fR:
296 .PP
297 .Vb 3
298 \& sig = ECDSA_do_sign(digest, 32, eckey);
299 \& if (sig == NULL)
300 \&     /* error */
301 .Ve
302 .PP
303 or using \fBECDSA_sign()\fR:
304 .PP
305 .Vb 2
306 \& unsigned char *buffer, *pp;
307 \& int buf_len;
308 \&
309 \& buf_len = ECDSA_size(eckey);
310 \& buffer = OPENSSL_malloc(buf_len);
311 \& pp = buffer;
312 \& if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
313 \&     /* error */
314 .Ve
315 .PP
316 Third step: verify the created \s-1ECDSA\s0 signature using \fBECDSA_do_verify()\fR:
317 .PP
318 .Vb 1
319 \& ret = ECDSA_do_verify(digest, 32, sig, eckey);
320 .Ve
321 .PP
322 or using \fBECDSA_verify()\fR:
323 .PP
324 .Vb 1
325 \& ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
326 .Ve
327 .PP
328 and finally evaluate the return value:
329 .PP
330 .Vb 6
331 \& if (ret == 1)
332 \&     /* signature ok */
333 \& else if (ret == 0)
334 \&     /* incorrect signature */
335 \& else
336 \&     /* error */
337 .Ve
338 .SH "CONFORMING TO"
339 .IX Header "CONFORMING TO"
340 \&\s-1ANSI X9.62, US\s0 Federal Information Processing Standard \s-1FIPS 186\-2\s0
341 (Digital Signature Standard, \s-1DSS\s0)
342 .SH "SEE ALSO"
343 .IX Header "SEE ALSO"
344 \&\fBDSA_new\fR\|(3),
345 \&\fBEVP_DigestSignInit\fR\|(3),
346 \&\fBEVP_DigestVerifyInit\fR\|(3)
347 .SH "COPYRIGHT"
348 .IX Header "COPYRIGHT"
349 Copyright 2004\-2018 The OpenSSL Project Authors. All Rights Reserved.
350 .PP
351 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
352 this file except in compliance with the License.  You can obtain a copy
353 in the file \s-1LICENSE\s0 in the source distribution or at
354 <https://www.openssl.org/source/license.html>.