Debian Codegraph @

upstream/debian-unstable/man3/ECDSA_sign.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "ECDSA_SIGN 3SSL"
58 .TH ECDSA_SIGN 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 ECDSA_size, ECDSA_sign, ECDSA_do_sign,
65 ECDSA_verify, ECDSA_do_verify, ECDSA_sign_setup, ECDSA_sign_ex,
66 ECDSA_do_sign_ex \- deprecated low\-level elliptic curve digital signature algorithm
67 (ECDSA) functions
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& #include <openssl/ecdsa.h>
72 .Ve
73 .PP
74 The following functions have been deprecated since OpenSSL 3.0, and can be
75 hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
76 see \fBopenssl_user_macros\fR\|(7):
77 .PP
78 .Vb 1
79 \& int ECDSA_size(const EC_KEY *eckey);
80 \&
81 \& int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
82 \& unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
83 \& ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
84 \& EC_KEY *eckey);
85 \&
86 \& int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
87 \& const unsigned char *sig, int siglen, EC_KEY *eckey);
88 \& int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
89 \& const ECDSA_SIG *sig, EC_KEY* eckey);
90 \&
91 \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
92 \& const BIGNUM *kinv, const BIGNUM *rp,
93 \& EC_KEY *eckey);
94 \& int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
95 \& int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
96 \& unsigned char *sig, unsigned int *siglen,
97 \& const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
98 .Ve
99 .SH DESCRIPTION
100 .IX Header "DESCRIPTION"
101 See \fBECDSA_SIG_new\fR\|(3) for a description of the \fBECDSA_SIG\fR object.
102 .PP
103 See \fBi2d_ECDSA_SIG\fR\|(3) and \fBd2i_ECDSA_SIG\fR\|(3) for information about encoding
104 and decoding ECDSA signatures to/from DER.
105 .PP
106 All of the functions described below are deprecated. Applications should
107 use the higher level \fBEVP\fR interface such as \fBEVP_DigestSignInit\fR\|(3)
108 or \fBEVP_DigestVerifyInit\fR\|(3) instead.
109 .PP
110 \&\fBECDSA_size()\fR returns the maximum length of a DER encoded ECDSA signature
111 created with the private EC key \fIeckey\fR. To obtain the actual signature
112 size use \fBEVP_PKEY_sign\fR\|(3) with a NULL \fIsig\fR parameter.
113 .PP
114 \&\fBECDSA_sign()\fR computes a digital signature of the \fIdgstlen\fR bytes hash value
115 \&\fIdgst\fR using the private EC key \fIeckey\fR. The DER encoded signatures is
116 stored in \fIsig\fR and its length is returned in \fIsiglen\fR. Note: \fIsig\fR must
117 point to ECDSA_size(eckey) bytes of memory. The parameter \fItype\fR is currently
118 ignored. \fBECDSA_sign()\fR is wrapper function for \fBECDSA_sign_ex()\fR with \fIkinv\fR
119 and \fIrp\fR set to NULL.
120 .PP
121 \&\fBECDSA_do_sign()\fR is similar to \fBECDSA_sign()\fR except the signature is returned
122 as a newly allocated \fBECDSA_SIG\fR structure (or NULL on error). \fBECDSA_do_sign()\fR
123 is a wrapper function for \fBECDSA_do_sign_ex()\fR with \fIkinv\fR and \fIrp\fR set to
124 NULL.
125 .PP
126 \&\fBECDSA_verify()\fR verifies that the signature in \fIsig\fR of size \fIsiglen\fR is a
127 valid ECDSA signature of the hash value \fIdgst\fR of size \fIdgstlen\fR using the
128 public key \fIeckey\fR. The parameter \fItype\fR is ignored.
129 .PP
130 \&\fBECDSA_do_verify()\fR is similar to \fBECDSA_verify()\fR except the signature is
131 presented in the form of a pointer to an \fBECDSA_SIG\fR structure.
132 .PP
133 The remaining functions utilise the internal \fIkinv\fR and \fIr\fR values used
134 during signature computation. Most applications will never need to call these
135 and some external ECDSA ENGINE implementations may not support them at all if
136 either \fIkinv\fR or \fIr\fR is not NULL.
137 .PP
138 \&\fBECDSA_sign_setup()\fR may be used to precompute parts of the signing operation.
139 \&\fIeckey\fR is the private EC key and \fIctx\fR is a pointer to \fBBN_CTX\fR structure
140 (or NULL). The precomputed values or returned in \fIkinv\fR and \fIrp\fR and can be
141 used in a later call to \fBECDSA_sign_ex()\fR or \fBECDSA_do_sign_ex()\fR.
142 .PP
143 \&\fBECDSA_sign_ex()\fR computes a digital signature of the \fIdgstlen\fR bytes hash value
144 \&\fIdgst\fR using the private EC key \fIeckey\fR and the optional pre-computed values
145 \&\fIkinv\fR and \fIrp\fR. The DER encoded signature is stored in \fIsig\fR and its
146 length is returned in \fIsiglen\fR. Note: \fIsig\fR must point to ECDSA_size(eckey)
147 bytes of memory. The parameter \fItype\fR is ignored.
148 .PP
149 \&\fBECDSA_do_sign_ex()\fR is similar to \fBECDSA_sign_ex()\fR except the signature is
150 returned as a newly allocated \fBECDSA_SIG\fR structure (or NULL on error).
151 .SH "RETURN VALUES"
152 .IX Header "RETURN VALUES"
153 \&\fBECDSA_size()\fR returns the maximum length signature or 0 on error.
154 .PP
155 \&\fBECDSA_sign()\fR, \fBECDSA_sign_ex()\fR and \fBECDSA_sign_setup()\fR return 1 if successful
156 or 0 on error.
157 .PP
158 \&\fBECDSA_do_sign()\fR and \fBECDSA_do_sign_ex()\fR return a pointer to an allocated
159 \&\fBECDSA_SIG\fR structure or NULL on error.
160 .PP
161 \&\fBECDSA_verify()\fR and \fBECDSA_do_verify()\fR return 1 for a valid
162 signature, 0 for an invalid signature and \-1 on error.
163 The error codes can be obtained by \fBERR_get_error\fR\|(3).
164 .SH EXAMPLES
165 .IX Header "EXAMPLES"
166 Creating an ECDSA signature of a given SHA\-256 hash value using the
167 named curve prime256v1 (aka P\-256).
168 This example uses deprecated functionality. See "DESCRIPTION".
169 .PP
170 First step: create an EC_KEY object (note: this part is \fBnot\fR ECDSA
171 specific)
172 .PP
173 .Vb 3
174 \& int ret;
175 \& ECDSA_SIG *sig;
176 \& EC_KEY *eckey;
177 \&
178 \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
179 \& if (eckey == NULL)
180 \& /* error */
181 \& if (EC_KEY_generate_key(eckey) == 0)
182 \& /* error */
183 .Ve
184 .PP
185 Second step: compute the ECDSA signature of a SHA\-256 hash value
186 using \fBECDSA_do_sign()\fR:
187 .PP
188 .Vb 3
189 \& sig = ECDSA_do_sign(digest, 32, eckey);
190 \& if (sig == NULL)
191 \& /* error */
192 .Ve
193 .PP
194 or using \fBECDSA_sign()\fR:
195 .PP
196 .Vb 2
197 \& unsigned char *buffer, *pp;
198 \& int buf_len;
199 \&
200 \& buf_len = ECDSA_size(eckey);
201 \& buffer = OPENSSL_malloc(buf_len);
202 \& pp = buffer;
203 \& if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
204 \& /* error */
205 .Ve
206 .PP
207 Third step: verify the created ECDSA signature using \fBECDSA_do_verify()\fR:
208 .PP
209 .Vb 1
210 \& ret = ECDSA_do_verify(digest, 32, sig, eckey);
211 .Ve
212 .PP
213 or using \fBECDSA_verify()\fR:
214 .PP
215 .Vb 1
216 \& ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
217 .Ve
218 .PP
219 and finally evaluate the return value:
220 .PP
221 .Vb 6
222 \& if (ret == 1)
223 \& /* signature ok */
224 \& else if (ret == 0)
225 \& /* incorrect signature */
226 \& else
227 \& /* error */
228 .Ve
229 .SH "CONFORMING TO"
230 .IX Header "CONFORMING TO"
231 ANSI X9.62, US Federal Information Processing Standard FIPS186\-2
232 (Digital Signature Standard, DSS)
233 .SH "SEE ALSO"
234 .IX Header "SEE ALSO"
235 \&\fBEC_KEY_new\fR\|(3),
236 \&\fBEVP_DigestSignInit\fR\|(3),
237 \&\fBEVP_DigestVerifyInit\fR\|(3),
238 \&\fBEVP_PKEY_sign\fR\|(3)
239 \&\fBi2d_ECDSA_SIG\fR\|(3),
240 \&\fBd2i_ECDSA_SIG\fR\|(3)
241 .SH HISTORY
242 .IX Header "HISTORY"
243 All functionality described here was deprecated in OpenSSL 3.0.
244 .SH COPYRIGHT
245 .IX Header "COPYRIGHT"
246 Copyright 2004\-2022 The OpenSSL Project Authors. All Rights Reserved.
247 .PP
248 Licensed under the Apache License 2.0 (the "License"). You may not use
249 this file except in compliance with the License. You can obtain a copy
250 in the file LICENSE in the source distribution or at
251 <https://www.openssl.org/source/license.html>.