Skip to main content

openssl_sys/handwritten/
ec.rs

1use super::super::*;
2use libc::size_t;
3use std::ffi::{c_char, c_int, c_long, c_uchar};
4
5#[cfg(ossl300)]
6extern "C" {
7    pub fn EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx: *mut EVP_PKEY_CTX, nid: c_int) -> c_int;
8}
9
10#[repr(C)]
11#[derive(Copy, Clone)]
12pub enum point_conversion_form_t {
13    POINT_CONVERSION_COMPRESSED = 2,
14    POINT_CONVERSION_UNCOMPRESSED = 4,
15    POINT_CONVERSION_HYBRID = 6,
16}
17
18#[cfg(not(any(libressl410, osslconf = "OPENSSL_NO_DEPRECATED_3_0")))]
19pub enum EC_METHOD {}
20pub enum EC_GROUP {}
21pub enum EC_POINT {}
22
23extern "C" {
24    #[cfg(not(any(libressl410, osslconf = "OPENSSL_NO_DEPRECATED_3_0")))]
25    pub fn EC_GROUP_new(meth: *const EC_METHOD) -> *mut EC_GROUP;
26
27    pub fn EC_GROUP_dup(group: *const EC_GROUP) -> *mut EC_GROUP;
28
29    pub fn EC_GROUP_free(group: *mut EC_GROUP);
30
31    pub fn EC_GROUP_get_order(
32        group: *const EC_GROUP,
33        order: *mut BIGNUM,
34        ctx: *mut BN_CTX,
35    ) -> c_int;
36
37    pub fn EC_GROUP_get_cofactor(
38        group: *const EC_GROUP,
39        cofactor: *mut BIGNUM,
40        ctx: *mut BN_CTX,
41    ) -> c_int;
42
43    pub fn EC_GROUP_get0_generator(group: *const EC_GROUP) -> *const EC_POINT;
44
45    pub fn EC_GROUP_set_generator(
46        group: *mut EC_GROUP,
47        generator: *const EC_POINT,
48        order: *const BIGNUM,
49        cofactor: *const BIGNUM,
50    ) -> c_int;
51
52    pub fn EC_GROUP_get_curve_name(group: *const EC_GROUP) -> c_int;
53
54    pub fn EC_GROUP_set_asn1_flag(key: *mut EC_GROUP, flag: c_int);
55
56    pub fn EC_GROUP_get_asn1_flag(group: *const EC_GROUP) -> c_int;
57
58    pub fn EC_GROUP_get_degree(group: *const EC_GROUP) -> c_int;
59
60    pub fn EC_GROUP_order_bits(group: *const EC_GROUP) -> c_int;
61
62    pub fn EC_GROUP_new_curve_GFp(
63        p: *const BIGNUM,
64        a: *const BIGNUM,
65        b: *const BIGNUM,
66        ctx: *mut BN_CTX,
67    ) -> *mut EC_GROUP;
68
69    #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
70    pub fn EC_GROUP_new_curve_GF2m(
71        p: *const BIGNUM,
72        a: *const BIGNUM,
73        b: *const BIGNUM,
74        ctx: *mut BN_CTX,
75    ) -> *mut EC_GROUP;
76
77    pub fn EC_GROUP_new_by_curve_name(nid: c_int) -> *mut EC_GROUP;
78
79    pub fn EC_POINT_is_at_infinity(group: *const EC_GROUP, point: *const EC_POINT) -> c_int;
80
81    pub fn EC_POINT_is_on_curve(
82        group: *const EC_GROUP,
83        point: *const EC_POINT,
84        ctx: *mut BN_CTX,
85    ) -> c_int;
86
87    pub fn EC_POINT_new(group: *const EC_GROUP) -> *mut EC_POINT;
88
89    pub fn EC_POINT_free(point: *mut EC_POINT);
90
91    pub fn EC_POINT_dup(p: *const EC_POINT, group: *const EC_GROUP) -> *mut EC_POINT;
92
93    #[cfg(any(ossl111, libressl))]
94    pub fn EC_POINT_get_affine_coordinates(
95        group: *const EC_GROUP,
96        p: *const EC_POINT,
97        x: *mut BIGNUM,
98        y: *mut BIGNUM,
99        ctx: *mut BN_CTX,
100    ) -> c_int;
101
102    #[cfg(any(ossl111, libressl))]
103    pub fn EC_POINT_set_affine_coordinates(
104        group: *const EC_GROUP,
105        p: *mut EC_POINT,
106        x: *const BIGNUM,
107        y: *const BIGNUM,
108        ctx: *mut BN_CTX,
109    ) -> c_int;
110
111    pub fn EC_POINT_point2oct(
112        group: *const EC_GROUP,
113        p: *const EC_POINT,
114        form: point_conversion_form_t,
115        buf: *mut c_uchar,
116        len: size_t,
117        ctx: *mut BN_CTX,
118    ) -> size_t;
119
120    pub fn EC_POINT_oct2point(
121        group: *const EC_GROUP,
122        p: *mut EC_POINT,
123        buf: *const c_uchar,
124        len: size_t,
125        ctx: *mut BN_CTX,
126    ) -> c_int;
127
128    pub fn EC_POINT_point2hex(
129        group: *const EC_GROUP,
130        p: *const EC_POINT,
131        form: point_conversion_form_t,
132        ctx: *mut BN_CTX,
133    ) -> *mut c_char;
134
135    pub fn EC_POINT_hex2point(
136        group: *const EC_GROUP,
137        s: *const c_char,
138        p: *mut EC_POINT,
139        ctx: *mut BN_CTX,
140    ) -> *mut EC_POINT;
141
142    pub fn EC_POINT_add(
143        group: *const EC_GROUP,
144        r: *mut EC_POINT,
145        a: *const EC_POINT,
146        b: *const EC_POINT,
147        ctx: *mut BN_CTX,
148    ) -> c_int;
149
150    pub fn EC_POINT_invert(group: *const EC_GROUP, r: *mut EC_POINT, ctx: *mut BN_CTX) -> c_int;
151
152    pub fn EC_POINT_cmp(
153        group: *const EC_GROUP,
154        a: *const EC_POINT,
155        b: *const EC_POINT,
156        ctx: *mut BN_CTX,
157    ) -> c_int;
158
159    pub fn EC_POINT_mul(
160        group: *const EC_GROUP,
161        r: *mut EC_POINT,
162        n: *const BIGNUM,
163        q: *const EC_POINT,
164        m: *const BIGNUM,
165        ctx: *mut BN_CTX,
166    ) -> c_int;
167}
168
169#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
170extern "C" {
171    #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
172    pub fn EC_GF2m_simple_method() -> *const EC_METHOD;
173
174    pub fn EC_GROUP_get_curve_GFp(
175        group: *const EC_GROUP,
176        p: *mut BIGNUM,
177        a: *mut BIGNUM,
178        b: *mut BIGNUM,
179        ctx: *mut BN_CTX,
180    ) -> c_int;
181
182    #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
183    pub fn EC_GROUP_get_curve_GF2m(
184        group: *const EC_GROUP,
185        p: *mut BIGNUM,
186        a: *mut BIGNUM,
187        b: *mut BIGNUM,
188        ctx: *mut BN_CTX,
189    ) -> c_int;
190
191    pub fn EC_POINT_get_affine_coordinates_GFp(
192        group: *const EC_GROUP,
193        p: *const EC_POINT,
194        x: *mut BIGNUM,
195        y: *mut BIGNUM,
196        ctx: *mut BN_CTX,
197    ) -> c_int;
198
199    pub fn EC_POINT_set_affine_coordinates_GFp(
200        group: *const EC_GROUP,
201        p: *mut EC_POINT,
202        x: *const BIGNUM,
203        y: *const BIGNUM,
204        ctx: *mut BN_CTX,
205    ) -> c_int;
206
207    #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
208    pub fn EC_POINT_get_affine_coordinates_GF2m(
209        group: *const EC_GROUP,
210        p: *const EC_POINT,
211        x: *mut BIGNUM,
212        y: *mut BIGNUM,
213        ctx: *mut BN_CTX,
214    ) -> c_int;
215
216    pub fn EC_KEY_new() -> *mut EC_KEY;
217
218    pub fn EC_KEY_new_by_curve_name(nid: c_int) -> *mut EC_KEY;
219
220    pub fn EC_KEY_free(key: *mut EC_KEY);
221
222    pub fn EC_KEY_dup(key: *const EC_KEY) -> *mut EC_KEY;
223
224    pub fn EC_KEY_up_ref(key: *mut EC_KEY) -> c_int;
225
226    pub fn EC_KEY_get0_group(key: *const EC_KEY) -> *const EC_GROUP;
227
228    pub fn EC_KEY_set_group(key: *mut EC_KEY, group: *const EC_GROUP) -> c_int;
229
230    pub fn EC_KEY_get0_private_key(key: *const EC_KEY) -> *const BIGNUM;
231
232    pub fn EC_KEY_set_private_key(key: *mut EC_KEY, key: *const BIGNUM) -> c_int;
233
234    pub fn EC_KEY_get0_public_key(key: *const EC_KEY) -> *const EC_POINT;
235
236    pub fn EC_KEY_set_public_key(key: *mut EC_KEY, key: *const EC_POINT) -> c_int;
237
238    pub fn EC_KEY_generate_key(key: *mut EC_KEY) -> c_int;
239
240    pub fn EC_KEY_check_key(key: *const EC_KEY) -> c_int;
241
242    pub fn EC_KEY_set_public_key_affine_coordinates(
243        key: *mut EC_KEY,
244        x: *mut BIGNUM,
245        y: *mut BIGNUM,
246    ) -> c_int;
247}
248
249pub enum ECDSA_SIG {}
250
251extern "C" {
252    pub fn ECDSA_SIG_new() -> *mut ECDSA_SIG;
253
254    pub fn ECDSA_SIG_free(sig: *mut ECDSA_SIG);
255
256    pub fn ECDSA_SIG_get0(sig: *const ECDSA_SIG, pr: *mut *const BIGNUM, ps: *mut *const BIGNUM);
257
258    pub fn ECDSA_SIG_set0(sig: *mut ECDSA_SIG, pr: *mut BIGNUM, ps: *mut BIGNUM) -> c_int;
259
260    pub fn d2i_ECDSA_SIG(
261        sig: *mut *mut ECDSA_SIG,
262        inp: *mut *const c_uchar,
263        length: c_long,
264    ) -> *mut ECDSA_SIG;
265
266    pub fn i2d_ECDSA_SIG(sig: *const ECDSA_SIG, out: *mut *mut c_uchar) -> c_int;
267}
268
269#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
270extern "C" {
271    pub fn ECDSA_do_sign(
272        dgst: *const c_uchar,
273        dgst_len: c_int,
274        eckey: *mut EC_KEY,
275    ) -> *mut ECDSA_SIG;
276
277    pub fn ECDSA_do_verify(
278        dgst: *const c_uchar,
279        dgst_len: c_int,
280        sig: *const ECDSA_SIG,
281        eckey: *mut EC_KEY,
282    ) -> c_int;
283}