Debian Codegraph @

upstream/debian-unstable/man3/ECDSA_SIG_new.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_SIG_NEW 3SSL"
58 .TH ECDSA_SIG_NEW 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_SIG_new, ECDSA_SIG_free,
65 ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0
66 \&\- Functions for creating, destroying and manipulating ECDSA_SIG objects
67 .SH SYNOPSIS
68 .IX Header "SYNOPSIS"
69 .Vb 1
70 \& #include <openssl/ecdsa.h>
71 \&
72 \& ECDSA_SIG *ECDSA_SIG_new(void);
73 \& void ECDSA_SIG_free(ECDSA_SIG *sig);
74 \& void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
75 \& const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
76 \& const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
77 \& int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
78 .Ve
79 .SH DESCRIPTION
80 .IX Header "DESCRIPTION"
81 \&\fBECDSA_SIG\fR is an opaque structure consisting of two BIGNUMs for the
82 \&\fIr\fR and \fIs\fR value of an Elliptic Curve Digital Signature Algorithm (ECDSA) signature
83 (see FIPS186\-4 or X9.62).
84 The \fBECDSA_SIG\fR object was mainly used by the deprecated low level functions described in
85 \&\fBECDSA_sign\fR\|(3), it is still required in order to be able to set or get the values of
86 \&\fIr\fR and \fIs\fR into or from a signature. This is mainly used for testing purposes as shown
87 in the "EXAMPLES".
88 .PP
89 \&\fBECDSA_SIG_new()\fR allocates an empty \fBECDSA_SIG\fR structure.
90 Note: before OpenSSL 1.1.0, the \fIr\fR and \fIs\fR components were initialised.
91 .PP
92 \&\fBECDSA_SIG_free()\fR frees the \fBECDSA_SIG\fR structure \fIsig\fR.
93 If the argument is NULL, nothing is done.
94 .PP
95 \&\fBECDSA_SIG_get0()\fR returns internal pointers the \fIr\fR and \fIs\fR values contained
96 in \fIsig\fR and stores them in \fI*pr\fR and \fI*ps\fR, respectively.
97 The pointer \fIpr\fR or \fIps\fR can be NULL, in which case the corresponding value
98 is not returned.
99 .PP
100 The values \fIr\fR, \fIs\fR can also be retrieved separately by the corresponding
101 function \fBECDSA_SIG_get0_r()\fR and \fBECDSA_SIG_get0_s()\fR, respectively.
102 .PP
103 Non-NULL \fIr\fR and \fIs\fR values can be set on the \fIsig\fR by calling
104 \&\fBECDSA_SIG_set0()\fR. Calling this function transfers the memory management of the
105 values to the \fBECDSA_SIG\fR object, and therefore the values that have been
106 passed in should not be freed by the caller.
107 .PP
108 See \fBi2d_ECDSA_SIG\fR\|(3) and \fBd2i_ECDSA_SIG\fR\|(3) for information about encoding
109 and decoding ECDSA signatures to/from DER.
110 .SH "RETURN VALUES"
111 .IX Header "RETURN VALUES"
112 \&\fBECDSA_SIG_new()\fR returns NULL if the allocation fails.
113 .PP
114 \&\fBECDSA_SIG_set0()\fR returns 1 on success or 0 on failure.
115 .PP
116 \&\fBECDSA_SIG_get0_r()\fR and \fBECDSA_SIG_get0_s()\fR return the corresponding value,
117 or NULL if it is unset.
118 .SH EXAMPLES
119 .IX Header "EXAMPLES"
120 Extract signature \fIr\fR and \fIs\fR values from a ECDSA \fIsignature\fR
121 of size \fIsignaturelen\fR:
122 .PP
123 .Vb 2
124 \& ECDSA_SIG *obj;
125 \& const BIGNUM *r, *s;
126 \&
127 \& /* Load a signature into the ECDSA_SIG object */
128 \& obj = d2i_ECDSA_SIG(NULL, &signature, signaturelen);
129 \& if (obj == NULL)
130 \& /* error */
131 \&
132 \& r = ECDSA_SIG_get0_r(obj);
133 \& s = ECDSA_SIG_get0_s(obj);
134 \& if (r == NULL || s == NULL)
135 \& /* error */
136 \&
137 \& /* Use BN_bn2binpad() here to convert to r and s into byte arrays */
138 \&
139 \& /*
140 \& * Do not try to access I<r> or I<s> after calling ECDSA_SIG_free(),
141 \& * as they are both freed by this call.
142 \& */
143 \& ECDSA_SIG_free(obj);
144 .Ve
145 .PP
146 Convert \fIr\fR and \fIs\fR byte arrays into an ECDSA_SIG \fIsignature\fR of
147 size \fIsignaturelen\fR:
148 .PP
149 .Vb 4
150 \& ECDSA_SIG *obj = NULL;
151 \& unsigned char *signature = NULL;
152 \& size_t signaturelen;
153 \& BIGNUM *rbn = NULL, *sbn = NULL;
154 \&
155 \& obj = ECDSA_SIG_new();
156 \& if (obj == NULL)
157 \& /* error */
158 \& rbn = BN_bin2bn(r, rlen, NULL);
159 \& sbn = BN_bin2bn(s, slen, NULL);
160 \& if (rbn == NULL || sbn == NULL)
161 \& /* error */
162 \&
163 \& if (!ECDSA_SIG_set0(obj, rbn, sbn))
164 \& /* error */
165 \& /* Set these to NULL since they are now owned by obj */
166 \& rbn = sbn = NULL;
167 \&
168 \& signaturelen = i2d_ECDSA_SIG(obj, &signature);
169 \& if (signaturelen <= 0)
170 \& /* error */
171 \&
172 \& /*
173 \& * This signature could now be passed to L<EVP_DigestVerify(3)>
174 \& * or L<EVP_DigestVerifyFinal(3)>
175 \& */
176 \&
177 \& BN_free(rbn);
178 \& BN_free(sbn);
179 \& OPENSSL_free(signature);
180 \& ECDSA_SIG_free(obj);
181 .Ve
182 .SH "CONFORMING TO"
183 .IX Header "CONFORMING TO"
184 ANSI X9.62,
185 US Federal Information Processing Standard FIPS186\-4
186 (Digital Signature Standard, DSS)
187 .SH "SEE ALSO"
188 .IX Header "SEE ALSO"
189 \&\fBEC_KEY_new\fR\|(3),
190 \&\fBEVP_DigestSignInit\fR\|(3),
191 \&\fBEVP_DigestVerifyInit\fR\|(3),
192 \&\fBEVP_PKEY_sign\fR\|(3)
193 \&\fBi2d_ECDSA_SIG\fR\|(3),
194 \&\fBd2i_ECDSA_SIG\fR\|(3),
195 \&\fBECDSA_sign\fR\|(3)
196 .SH COPYRIGHT
197 .IX Header "COPYRIGHT"
198 Copyright 2004\-2024 The OpenSSL Project Authors. All Rights Reserved.
199 .PP
200 Licensed under the Apache License 2.0 (the "License"). You may not use
201 this file except in compliance with the License. You can obtain a copy
202 in the file LICENSE in the source distribution or at
203 <https://www.openssl.org/source/license.html>.