Merge branch 'vendor/OPENSSL'
[dragonfly.git] / secure / lib / libcrypto / man / ecdsa.3
CommitLineData
e257b235 1.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05)
a561f9ff
SS
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
e257b235
PA
28.\" double quote, and \*(R" will give a right double quote. \*(C+ will
29.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
30.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
31.\" nothing in troff, for use with C<>.
32.tr \(*W-
a561f9ff
SS
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
e257b235
PA
51.\" Escape single quotes in literal strings from groff's Unicode transform.
52.ie \n(.g .ds Aq \(aq
53.el .ds Aq '
54.\"
a561f9ff
SS
55.\" If the F register is turned on, we'll generate index entries on stderr for
56.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
57.\" entries marked with X<> in POD. Of course, you'll have to process the
58.\" output yourself in some meaningful fashion.
e257b235 59.ie \nF \{\
a561f9ff
SS
60. de IX
61. tm Index:\\$1\t\\n%\t"\\$2"
62..
63. nr % 0
64. rr F
65.\}
e257b235
PA
66.el \{\
67. de IX
68..
69.\}
aac4ff6f 70.\"
a561f9ff
SS
71.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
72.\" Fear. Run. Save yourself. No user-serviceable parts.
73. \" fudge factors for nroff and troff
74.if n \{\
75. ds #H 0
76. ds #V .8m
77. ds #F .3m
78. ds #[ \f1
79. ds #] \fP
80.\}
81.if t \{\
82. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
83. ds #V .6m
84. ds #F 0
85. ds #[ \&
86. ds #] \&
87.\}
88. \" simple accents for nroff and troff
89.if n \{\
90. ds ' \&
91. ds ` \&
92. ds ^ \&
93. ds , \&
94. ds ~ ~
95. ds /
96.\}
97.if t \{\
98. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
99. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
100. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
101. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
102. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
103. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
104.\}
105. \" troff and (daisy-wheel) nroff accents
106.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
107.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
108.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
109.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
110.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
111.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
112.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
113.ds ae a\h'-(\w'a'u*4/10)'e
114.ds Ae A\h'-(\w'A'u*4/10)'E
115. \" corrections for vroff
116.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
117.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
118. \" for low resolution devices (crt and lpr)
119.if \n(.H>23 .if \n(.V>19 \
120\{\
121. ds : e
122. ds 8 ss
123. ds o a
124. ds d- d\h'-1'\(ga
125. ds D- D\h'-1'\(hy
126. ds th \o'bp'
127. ds Th \o'LP'
128. ds ae ae
129. ds Ae AE
130.\}
131.rm #[ #] #H #V #F C
132.\" ========================================================================
133.\"
134.IX Title "ecdsa 3"
fc468453 135.TH ecdsa 3 "2010-02-27" "0.9.8m" "OpenSSL"
e257b235
PA
136.\" For nroff, turn off justification. Always turn off hyphenation; it makes
137.\" way too many mistakes in technical documents.
138.if n .ad l
139.nh
a561f9ff
SS
140.SH "NAME"
141ecdsa \- Elliptic Curve Digital Signature Algorithm
142.SH "SYNOPSIS"
143.IX Header "SYNOPSIS"
144.Vb 1
145\& #include <openssl/ecdsa.h>
e257b235 146\&
a561f9ff
SS
147\& ECDSA_SIG* ECDSA_SIG_new(void);
148\& void ECDSA_SIG_free(ECDSA_SIG *sig);
149\& int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
150\& ECDSA_SIG* d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp,
151\& long len);
e257b235 152\&
a561f9ff
SS
153\& ECDSA_SIG* ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
154\& EC_KEY *eckey);
155\& ECDSA_SIG* ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
156\& const BIGNUM *kinv, const BIGNUM *rp,
157\& EC_KEY *eckey);
158\& int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
159\& const ECDSA_SIG *sig, EC_KEY* eckey);
160\& int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx,
161\& BIGNUM **kinv, BIGNUM **rp);
162\& int ECDSA_sign(int type, const unsigned char *dgst,
163\& int dgstlen, unsigned char *sig,
164\& unsigned int *siglen, EC_KEY *eckey);
165\& int ECDSA_sign_ex(int type, const unsigned char *dgst,
166\& int dgstlen, unsigned char *sig,
167\& unsigned int *siglen, const BIGNUM *kinv,
168\& const BIGNUM *rp, EC_KEY *eckey);
169\& int ECDSA_verify(int type, const unsigned char *dgst,
170\& int dgstlen, const unsigned char *sig,
171\& int siglen, EC_KEY *eckey);
172\& int ECDSA_size(const EC_KEY *eckey);
e257b235 173\&
a561f9ff
SS
174\& const ECDSA_METHOD* ECDSA_OpenSSL(void);
175\& void ECDSA_set_default_method(const ECDSA_METHOD *meth);
176\& const ECDSA_METHOD* ECDSA_get_default_method(void);
177\& int ECDSA_set_method(EC_KEY *eckey,const ECDSA_METHOD *meth);
e257b235 178\&
a561f9ff
SS
179\& int ECDSA_get_ex_new_index(long argl, void *argp,
180\& CRYPTO_EX_new *new_func,
181\& CRYPTO_EX_dup *dup_func,
182\& CRYPTO_EX_free *free_func);
183\& int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);
184\& void* ECDSA_get_ex_data(EC_KEY *d, int idx);
185.Ve
186.SH "DESCRIPTION"
187.IX Header "DESCRIPTION"
188The \fB\s-1ECDSA_SIG\s0\fR structure consists of two BIGNUMs for the
189r and s value of a \s-1ECDSA\s0 signature (see X9.62 or \s-1FIPS\s0 186\-2).
190.PP
191.Vb 5
192\& struct
193\& {
194\& BIGNUM *r;
195\& BIGNUM *s;
196\& } ECDSA_SIG;
197.Ve
198.PP
199\&\fIECDSA_SIG_new()\fR allocates a new \fB\s-1ECDSA_SIG\s0\fR structure (note: this
200function also allocates the BIGNUMs) and initialize it.
201.PP
202\&\fIECDSA_SIG_free()\fR frees the \fB\s-1ECDSA_SIG\s0\fR structure \fBsig\fR.
203.PP
204\&\fIi2d_ECDSA_SIG()\fR creates the \s-1DER\s0 encoding of the \s-1ECDSA\s0 signature
205\&\fBsig\fR and writes the encoded signature to \fB*pp\fR (note: if \fBpp\fR
206is \s-1NULL\s0 \fBi2d_ECDSA_SIG\fR returns the expected length in bytes of
207the \s-1DER\s0 encoded signature). \fBi2d_ECDSA_SIG\fR returns the length
208of the \s-1DER\s0 encoded signature (or 0 on error).
209.PP
210\&\fId2i_ECDSA_SIG()\fR decodes a \s-1DER\s0 encoded \s-1ECDSA\s0 signature and returns
211the decoded signature in a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure.
212\&\fB*sig\fR points to the buffer containing the \s-1DER\s0 encoded signature
213of size \fBlen\fR.
214.PP
215\&\fIECDSA_size()\fR returns the maximum length of a \s-1DER\s0 encoded
216\&\s-1ECDSA\s0 signature created with the private \s-1EC\s0 key \fBeckey\fR.
217.PP
218\&\fIECDSA_sign_setup()\fR may be used to precompute parts of the
219signing operation. \fBeckey\fR is the private \s-1EC\s0 key and \fBctx\fR
220is a pointer to \fB\s-1BN_CTX\s0\fR structure (or \s-1NULL\s0). The precomputed
221values or returned in \fBkinv\fR and \fBrp\fR and can be used in a
222later call to \fBECDSA_sign_ex\fR or \fBECDSA_do_sign_ex\fR.
223.PP
224\&\fIECDSA_sign()\fR is wrapper function for ECDSA_sign_ex with \fBkinv\fR
225and \fBrp\fR set to \s-1NULL\s0.
226.PP
227\&\fIECDSA_sign_ex()\fR computes a digital signature of the \fBdgstlen\fR bytes
228hash value \fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR and the optional
229pre-computed values \fBkinv\fR and \fBrp\fR. The \s-1DER\s0 encoded signatures is
230stored in \fBsig\fR and it's length is returned in \fBsig_len\fR. Note: \fBsig\fR
231must point to \fBECDSA_size\fR bytes of memory. The parameter \fBtype\fR
232is ignored.
233.PP
234\&\fIECDSA_verify()\fR verifies that the signature in \fBsig\fR of size
235\&\fBsiglen\fR is a valid \s-1ECDSA\s0 signature of the hash value
236value \fBdgst\fR of size \fBdgstlen\fR using the public key \fBeckey\fR.
237The parameter \fBtype\fR is ignored.
238.PP
239\&\fIECDSA_do_sign()\fR is wrapper function for ECDSA_do_sign_ex with \fBkinv\fR
240and \fBrp\fR set to \s-1NULL\s0.
241.PP
242\&\fIECDSA_do_sign_ex()\fR computes a digital signature of the \fBdgst_len\fR
243bytes hash value \fBdgst\fR using the private key \fBeckey\fR and the
244optional pre-computed values \fBkinv\fR and \fBrp\fR. The signature is
245returned in a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error).
246.PP
247\&\fIECDSA_do_verify()\fR verifies that the signature \fBsig\fR is a valid
248\&\s-1ECDSA\s0 signature of the hash value \fBdgst\fR of size \fBdgst_len\fR
249using the public key \fBeckey\fR.
250.SH "RETURN VALUES"
251.IX Header "RETURN VALUES"
252\&\fIECDSA_size()\fR returns the maximum length signature or 0 on error.
253.PP
254\&\fIECDSA_sign_setup()\fR and \fIECDSA_sign()\fR return 1 if successful or \-1
255on error.
256.PP
257\&\fIECDSA_verify()\fR and \fIECDSA_do_verify()\fR return 1 for a valid
258signature, 0 for an invalid signature and \-1 on error.
259The error codes can be obtained by \fIERR_get_error\fR\|(3).
260.SH "EXAMPLES"
261.IX Header "EXAMPLES"
262Creating a \s-1ECDSA\s0 signature of given \s-1SHA\-1\s0 hash value using the
263named curve secp192k1.
264.PP
265First step: create a \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
266specific)
267.PP
e257b235 268.Vb 10
a561f9ff
SS
269\& int ret;
270\& ECDSA_SIG *sig;
271\& EC_KEY *eckey = EC_KEY_new();
272\& if (eckey == NULL)
273\& {
274\& /* error */
275\& }
e257b235
PA
276\& key\->group = EC_GROUP_new_by_nid(NID_secp192k1);
277\& if (key\->group == NULL)
a561f9ff
SS
278\& {
279\& /* error */
280\& }
281\& if (!EC_KEY_generate_key(eckey))
282\& {
283\& /* error */
284\& }
285.Ve
286.PP
287Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-1\s0 hash value
e257b235 288using \fBECDSA_do_sign\fR
a561f9ff
SS
289.PP
290.Vb 5
291\& sig = ECDSA_do_sign(digest, 20, eckey);
292\& if (sig == NULL)
293\& {
294\& /* error */
295\& }
296.Ve
297.PP
298or using \fBECDSA_sign\fR
299.PP
300.Vb 9
301\& unsigned char *buffer, *pp;
302\& int buf_len;
303\& buf_len = ECDSA_size(eckey);
304\& buffer = OPENSSL_malloc(buf_len);
305\& pp = buffer;
306\& if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey);
307\& {
308\& /* error */
309\& }
310.Ve
311.PP
312Third step: verify the created \s-1ECDSA\s0 signature using \fBECDSA_do_verify\fR
313.PP
314.Vb 1
315\& ret = ECDSA_do_verify(digest, 20, sig, eckey);
316.Ve
317.PP
318or using \fBECDSA_verify\fR
319.PP
320.Vb 1
321\& ret = ECDSA_verify(0, digest, 20, buffer, buf_len, eckey);
322.Ve
323.PP
324and finally evaluate the return value:
325.PP
326.Vb 12
e257b235 327\& if (ret == \-1)
a561f9ff
SS
328\& {
329\& /* error */
330\& }
331\& else if (ret == 0)
332\& {
333\& /* incorrect signature */
334\& }
335\& else /* ret == 1 */
336\& {
337\& /* signature ok */
338\& }
339.Ve
340.SH "CONFORMING TO"
341.IX Header "CONFORMING TO"
342\&\s-1ANSI\s0 X9.62, \s-1US\s0 Federal Information Processing Standard \s-1FIPS\s0 186\-2
343(Digital Signature Standard, \s-1DSS\s0)
344.SH "SEE ALSO"
345.IX Header "SEE ALSO"
346\&\fIdsa\fR\|(3), \fIrsa\fR\|(3)
347.SH "HISTORY"
348.IX Header "HISTORY"
349The ecdsa implementation was first introduced in OpenSSL 0.9.8
350.SH "AUTHOR"
351.IX Header "AUTHOR"
352Nils Larsch for the OpenSSL project (http://www.openssl.org).