1 use libc::*;
2 use std::ptr;
3 
4 use *;
5 
6 #[repr(C)]
7 #[derive(Copy, Clone)]
8 pub enum point_conversion_form_t {
9     POINT_CONVERSION_COMPRESSED = 2,
10     POINT_CONVERSION_UNCOMPRESSED = 4,
11     POINT_CONVERSION_HYBRID = 6,
12 }
13 
14 pub enum EC_METHOD {}
15 pub enum EC_GROUP {}
16 pub enum EC_POINT {}
17 
18 pub const OPENSSL_EC_NAMED_CURVE: c_int = 1;
19 
20 extern "C" {
21     #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
EC_GF2m_simple_method() -> *const EC_METHOD22     pub fn EC_GF2m_simple_method() -> *const EC_METHOD;
23 
EC_GROUP_new(meth: *const EC_METHOD) -> *mut EC_GROUP24     pub fn EC_GROUP_new(meth: *const EC_METHOD) -> *mut EC_GROUP;
25 
EC_GROUP_free(group: *mut EC_GROUP)26     pub fn EC_GROUP_free(group: *mut EC_GROUP);
27 
EC_GROUP_get_order( group: *const EC_GROUP, order: *mut BIGNUM, ctx: *mut BN_CTX, ) -> c_int28     pub fn EC_GROUP_get_order(
29         group: *const EC_GROUP,
30         order: *mut BIGNUM,
31         ctx: *mut BN_CTX,
32     ) -> c_int;
33 
EC_GROUP_get_cofactor( group: *const EC_GROUP, cofactor: *mut BIGNUM, ctx: *mut BN_CTX, ) -> c_int34     pub fn EC_GROUP_get_cofactor(
35         group: *const EC_GROUP,
36         cofactor: *mut BIGNUM,
37         ctx: *mut BN_CTX,
38     ) -> c_int;
39 
EC_GROUP_get0_generator(group: *const EC_GROUP) -> *const EC_POINT40     pub fn EC_GROUP_get0_generator(group: *const EC_GROUP) -> *const EC_POINT;
41 
EC_GROUP_get_curve_name(group: *const EC_GROUP) -> c_int42     pub fn EC_GROUP_get_curve_name(group: *const EC_GROUP) -> c_int;
43 
EC_GROUP_set_asn1_flag(key: *mut EC_GROUP, flag: c_int)44     pub fn EC_GROUP_set_asn1_flag(key: *mut EC_GROUP, flag: c_int);
45 
EC_GROUP_get_curve_GFp( group: *const EC_GROUP, p: *mut BIGNUM, a: *mut BIGNUM, b: *mut BIGNUM, ctx: *mut BN_CTX, ) -> c_int46     pub fn EC_GROUP_get_curve_GFp(
47         group: *const EC_GROUP,
48         p: *mut BIGNUM,
49         a: *mut BIGNUM,
50         b: *mut BIGNUM,
51         ctx: *mut BN_CTX,
52     ) -> c_int;
53 
54     #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
EC_GROUP_get_curve_GF2m( group: *const EC_GROUP, p: *mut BIGNUM, a: *mut BIGNUM, b: *mut BIGNUM, ctx: *mut BN_CTX, ) -> c_int55     pub fn EC_GROUP_get_curve_GF2m(
56         group: *const EC_GROUP,
57         p: *mut BIGNUM,
58         a: *mut BIGNUM,
59         b: *mut BIGNUM,
60         ctx: *mut BN_CTX,
61     ) -> c_int;
62 
EC_GROUP_get_degree(group: *const EC_GROUP) -> c_int63     pub fn EC_GROUP_get_degree(group: *const EC_GROUP) -> c_int;
64 
65     #[cfg(ossl110)]
EC_GROUP_order_bits(group: *const EC_GROUP) -> c_int66     pub fn EC_GROUP_order_bits(group: *const EC_GROUP) -> c_int;
67 
EC_GROUP_new_curve_GFp( p: *const BIGNUM, a: *const BIGNUM, b: *const BIGNUM, ctx: *mut BN_CTX, ) -> *mut EC_GROUP68     pub fn EC_GROUP_new_curve_GFp(
69         p: *const BIGNUM,
70         a: *const BIGNUM,
71         b: *const BIGNUM,
72         ctx: *mut BN_CTX,
73     ) -> *mut EC_GROUP;
74 
75     #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
EC_GROUP_new_curve_GF2m( p: *const BIGNUM, a: *const BIGNUM, b: *const BIGNUM, ctx: *mut BN_CTX, ) -> *mut EC_GROUP76     pub fn EC_GROUP_new_curve_GF2m(
77         p: *const BIGNUM,
78         a: *const BIGNUM,
79         b: *const BIGNUM,
80         ctx: *mut BN_CTX,
81     ) -> *mut EC_GROUP;
82 
EC_GROUP_new_by_curve_name(nid: c_int) -> *mut EC_GROUP83     pub fn EC_GROUP_new_by_curve_name(nid: c_int) -> *mut EC_GROUP;
84 
EC_POINT_is_at_infinity(group: *const EC_GROUP, point: *const EC_POINT) -> c_int85     pub fn EC_POINT_is_at_infinity(group: *const EC_GROUP, point: *const EC_POINT) -> c_int;
86 
EC_POINT_is_on_curve( group: *const EC_GROUP, point: *const EC_POINT, ctx: *mut BN_CTX, ) -> c_int87     pub fn EC_POINT_is_on_curve(
88         group: *const EC_GROUP,
89         point: *const EC_POINT,
90         ctx: *mut BN_CTX,
91     ) -> c_int;
92 
EC_POINT_new(group: *const EC_GROUP) -> *mut EC_POINT93     pub fn EC_POINT_new(group: *const EC_GROUP) -> *mut EC_POINT;
94 
EC_POINT_free(point: *mut EC_POINT)95     pub fn EC_POINT_free(point: *mut EC_POINT);
96 
EC_POINT_dup(p: *const EC_POINT, group: *const EC_GROUP) -> *mut EC_POINT97     pub fn EC_POINT_dup(p: *const EC_POINT, group: *const EC_GROUP) -> *mut EC_POINT;
98 
99     #[cfg(ossl111)]
EC_POINT_get_affine_coordinates( group: *const EC_GROUP, p: *const EC_POINT, x: *mut BIGNUM, y: *mut BIGNUM, ctx: *mut BN_CTX, ) -> c_int100     pub fn EC_POINT_get_affine_coordinates(
101         group: *const EC_GROUP,
102         p: *const EC_POINT,
103         x: *mut BIGNUM,
104         y: *mut BIGNUM,
105         ctx: *mut BN_CTX,
106     ) -> c_int;
107 
EC_POINT_get_affine_coordinates_GFp( group: *const EC_GROUP, p: *const EC_POINT, x: *mut BIGNUM, y: *mut BIGNUM, ctx: *mut BN_CTX, ) -> c_int108     pub fn EC_POINT_get_affine_coordinates_GFp(
109         group: *const EC_GROUP,
110         p: *const EC_POINT,
111         x: *mut BIGNUM,
112         y: *mut BIGNUM,
113         ctx: *mut BN_CTX,
114     ) -> c_int;
115 
116     #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
EC_POINT_get_affine_coordinates_GF2m( group: *const EC_GROUP, p: *const EC_POINT, x: *mut BIGNUM, y: *mut BIGNUM, ctx: *mut BN_CTX, ) -> c_int117     pub fn EC_POINT_get_affine_coordinates_GF2m(
118         group: *const EC_GROUP,
119         p: *const EC_POINT,
120         x: *mut BIGNUM,
121         y: *mut BIGNUM,
122         ctx: *mut BN_CTX,
123     ) -> c_int;
124 
EC_POINT_point2oct( group: *const EC_GROUP, p: *const EC_POINT, form: point_conversion_form_t, buf: *mut c_uchar, len: size_t, ctx: *mut BN_CTX, ) -> size_t125     pub fn EC_POINT_point2oct(
126         group: *const EC_GROUP,
127         p: *const EC_POINT,
128         form: point_conversion_form_t,
129         buf: *mut c_uchar,
130         len: size_t,
131         ctx: *mut BN_CTX,
132     ) -> size_t;
133 
EC_POINT_oct2point( group: *const EC_GROUP, p: *mut EC_POINT, buf: *const c_uchar, len: size_t, ctx: *mut BN_CTX, ) -> c_int134     pub fn EC_POINT_oct2point(
135         group: *const EC_GROUP,
136         p: *mut EC_POINT,
137         buf: *const c_uchar,
138         len: size_t,
139         ctx: *mut BN_CTX,
140     ) -> c_int;
141 
EC_POINT_add( group: *const EC_GROUP, r: *mut EC_POINT, a: *const EC_POINT, b: *const EC_POINT, ctx: *mut BN_CTX, ) -> c_int142     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 
EC_POINT_invert(group: *const EC_GROUP, r: *mut EC_POINT, ctx: *mut BN_CTX) -> c_int150     pub fn EC_POINT_invert(group: *const EC_GROUP, r: *mut EC_POINT, ctx: *mut BN_CTX) -> c_int;
151 
EC_POINT_cmp( group: *const EC_GROUP, a: *const EC_POINT, b: *const EC_POINT, ctx: *mut BN_CTX, ) -> c_int152     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 
EC_POINT_mul( group: *const EC_GROUP, r: *mut EC_POINT, n: *const BIGNUM, q: *const EC_POINT, m: *const BIGNUM, ctx: *mut BN_CTX, ) -> c_int159     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 
EC_KEY_new() -> *mut EC_KEY168     pub fn EC_KEY_new() -> *mut EC_KEY;
169 
EC_KEY_new_by_curve_name(nid: c_int) -> *mut EC_KEY170     pub fn EC_KEY_new_by_curve_name(nid: c_int) -> *mut EC_KEY;
171 
EC_KEY_free(key: *mut EC_KEY)172     pub fn EC_KEY_free(key: *mut EC_KEY);
173 
EC_KEY_dup(key: *const EC_KEY) -> *mut EC_KEY174     pub fn EC_KEY_dup(key: *const EC_KEY) -> *mut EC_KEY;
175 
EC_KEY_up_ref(key: *mut EC_KEY) -> c_int176     pub fn EC_KEY_up_ref(key: *mut EC_KEY) -> c_int;
177 
EC_KEY_get0_group(key: *const EC_KEY) -> *const EC_GROUP178     pub fn EC_KEY_get0_group(key: *const EC_KEY) -> *const EC_GROUP;
179 
EC_KEY_set_group(key: *mut EC_KEY, group: *const EC_GROUP) -> c_int180     pub fn EC_KEY_set_group(key: *mut EC_KEY, group: *const EC_GROUP) -> c_int;
181 
EC_KEY_get0_private_key(key: *const EC_KEY) -> *const BIGNUM182     pub fn EC_KEY_get0_private_key(key: *const EC_KEY) -> *const BIGNUM;
183 
EC_KEY_set_private_key(key: *mut EC_KEY, key: *const BIGNUM) -> c_int184     pub fn EC_KEY_set_private_key(key: *mut EC_KEY, key: *const BIGNUM) -> c_int;
185 
EC_KEY_get0_public_key(key: *const EC_KEY) -> *const EC_POINT186     pub fn EC_KEY_get0_public_key(key: *const EC_KEY) -> *const EC_POINT;
187 
EC_KEY_set_public_key(key: *mut EC_KEY, key: *const EC_POINT) -> c_int188     pub fn EC_KEY_set_public_key(key: *mut EC_KEY, key: *const EC_POINT) -> c_int;
189 
EC_KEY_generate_key(key: *mut EC_KEY) -> c_int190     pub fn EC_KEY_generate_key(key: *mut EC_KEY) -> c_int;
191 
EC_KEY_check_key(key: *const EC_KEY) -> c_int192     pub fn EC_KEY_check_key(key: *const EC_KEY) -> c_int;
193 
EC_KEY_set_public_key_affine_coordinates( key: *mut EC_KEY, x: *mut BIGNUM, y: *mut BIGNUM, ) -> c_int194     pub fn EC_KEY_set_public_key_affine_coordinates(
195         key: *mut EC_KEY,
196         x: *mut BIGNUM,
197         y: *mut BIGNUM,
198     ) -> c_int;
199 }
200 
201 cfg_if! {
202     if #[cfg(any(ossl110, libressl280))] {
203         pub enum ECDSA_SIG {}
204     } else {
205         #[repr(C)]
206         pub struct ECDSA_SIG {
207             pub r: *mut BIGNUM,
208             pub s: *mut BIGNUM,
209         }
210     }
211 }
212 
213 extern "C" {
ECDSA_SIG_new() -> *mut ECDSA_SIG214     pub fn ECDSA_SIG_new() -> *mut ECDSA_SIG;
215 
ECDSA_SIG_free(sig: *mut ECDSA_SIG)216     pub fn ECDSA_SIG_free(sig: *mut ECDSA_SIG);
217 
218     #[cfg(any(ossl110, libressl273))]
ECDSA_SIG_get0(sig: *const ECDSA_SIG, pr: *mut *const BIGNUM, ps: *mut *const BIGNUM)219     pub fn ECDSA_SIG_get0(sig: *const ECDSA_SIG, pr: *mut *const BIGNUM, ps: *mut *const BIGNUM);
220 
221     #[cfg(any(ossl110, libressl273))]
ECDSA_SIG_set0(sig: *mut ECDSA_SIG, pr: *mut BIGNUM, ps: *mut BIGNUM) -> c_int222     pub fn ECDSA_SIG_set0(sig: *mut ECDSA_SIG, pr: *mut BIGNUM, ps: *mut BIGNUM) -> c_int;
223 
ECDSA_do_sign( dgst: *const c_uchar, dgst_len: c_int, eckey: *mut EC_KEY, ) -> *mut ECDSA_SIG224     pub fn ECDSA_do_sign(
225         dgst: *const c_uchar,
226         dgst_len: c_int,
227         eckey: *mut EC_KEY,
228     ) -> *mut ECDSA_SIG;
229 
ECDSA_do_verify( dgst: *const c_uchar, dgst_len: c_int, sig: *const ECDSA_SIG, eckey: *mut EC_KEY, ) -> c_int230     pub fn ECDSA_do_verify(
231         dgst: *const c_uchar,
232         dgst_len: c_int,
233         sig: *const ECDSA_SIG,
234         eckey: *mut EC_KEY,
235     ) -> c_int;
236 
d2i_ECDSA_SIG( sig: *mut *mut ECDSA_SIG, inp: *mut *const c_uchar, length: c_long, ) -> *mut ECDSA_SIG237     pub fn d2i_ECDSA_SIG(
238         sig: *mut *mut ECDSA_SIG,
239         inp: *mut *const c_uchar,
240         length: c_long,
241     ) -> *mut ECDSA_SIG;
242 
i2d_ECDSA_SIG(sig: *const ECDSA_SIG, out: *mut *mut c_uchar) -> c_int243     pub fn i2d_ECDSA_SIG(sig: *const ECDSA_SIG, out: *mut *mut c_uchar) -> c_int;
244 }
245 
246 #[cfg(ossl300)]
EVP_EC_gen(curve: *const c_char) -> *mut EVP_PKEY247 pub unsafe fn EVP_EC_gen(curve: *const c_char) -> *mut EVP_PKEY {
248     EVP_PKEY_Q_keygen(
249         ptr::null_mut(),
250         ptr::null_mut(),
251         "EC\0".as_ptr().cast(),
252         curve,
253     )
254 }
255