libgcrypt_sys/
funcs.rs

1use libc::{c_char, c_int, c_uchar, c_uint, c_ulong, c_void, size_t};
2use std::ptr;
3
4pub use libgpg_error_sys::gpg_err_code as gcry_err_code;
5pub use libgpg_error_sys::gpg_err_code_from_errno as gcry_err_code_from_errno;
6pub use libgpg_error_sys::gpg_err_code_from_syserror as gcry_err_code_from_syserror;
7pub use libgpg_error_sys::gpg_err_code_to_errno as gcry_err_code_to_errno;
8pub use libgpg_error_sys::gpg_err_make as gcry_err_make;
9pub use libgpg_error_sys::gpg_err_make_from_errno as gcry_err_make_from_errno;
10pub use libgpg_error_sys::gpg_err_set_errno as gcry_err_set_errno;
11pub use libgpg_error_sys::gpg_err_source as gcry_err_source;
12pub use libgpg_error_sys::gpg_error_from_errno as gcry_error_from_errno;
13pub use libgpg_error_sys::gpg_error_from_syserror as gcry_error_from_syserror;
14pub use libgpg_error_sys::gpg_strerror as gcry_strerror;
15pub use libgpg_error_sys::gpg_strerror_r as gcry_strerror_r;
16pub use libgpg_error_sys::gpg_strsource as gcry_strsource;
17
18use crate::consts::*;
19use crate::types::*;
20
21extern "C" {
22    #[cfg(feature = "shim")]
23    pub fn gcry_threads_pthread_shim() -> *mut gcry_thread_cbs;
24
25    pub fn gcry_check_version(req_version: *const c_char) -> *const c_char;
26    pub fn gcry_control(cmd: gcry_ctl_cmds, ...) -> gcry_error_t;
27
28    pub fn gcry_sexp_new(
29        retsexp: *mut gcry_sexp_t, buffer: *const c_void, length: size_t, autodetect: c_int,
30    ) -> gcry_error_t;
31    pub fn gcry_sexp_create(
32        retsexp: *mut gcry_sexp_t, buffer: *mut c_void, length: size_t, autodetect: c_int,
33        freefnc: extern "C" fn(*mut c_void),
34    ) -> gcry_error_t;
35    pub fn gcry_sexp_sscan(
36        retsexp: *mut gcry_sexp_t, erroff: *mut size_t, buffer: *const c_char, length: size_t,
37    ) -> gcry_error_t;
38    pub fn gcry_sexp_build(
39        retsexp: *mut gcry_sexp_t, erroff: *mut size_t, format: *const c_char, ...
40    ) -> gcry_error_t;
41    pub fn gcry_sexp_build_array(
42        retsexp: *mut gcry_sexp_t, erroff: *mut size_t, format: *const c_char,
43        arg_list: *mut *mut c_void,
44    ) -> gcry_error_t;
45    pub fn gcry_sexp_release(sexp: gcry_sexp_t);
46    pub fn gcry_sexp_canon_len(
47        buffer: *const c_uchar, length: size_t, erroff: *mut size_t, errcode: *mut gcry_error_t,
48    ) -> size_t;
49    pub fn gcry_sexp_sprint(
50        sexp: gcry_sexp_t, mode: c_int, buffer: *mut c_void, maxlength: size_t,
51    ) -> size_t;
52    pub fn gcry_sexp_dump(a: gcry_sexp_t);
53    pub fn gcry_sexp_cons(a: gcry_sexp_t, b: gcry_sexp_t) -> gcry_sexp_t;
54    pub fn gcry_sexp_alist(array: *const gcry_sexp_t) -> gcry_sexp_t;
55    pub fn gcry_sexp_vlist(a: gcry_sexp_t, ...) -> gcry_sexp_t;
56    pub fn gcry_sexp_append(a: gcry_sexp_t, n: gcry_sexp_t) -> gcry_sexp_t;
57    pub fn gcry_sexp_prepend(a: gcry_sexp_t, n: gcry_sexp_t) -> gcry_sexp_t;
58    pub fn gcry_sexp_find_token(
59        list: gcry_sexp_t, tok: *const c_char, toklen: size_t,
60    ) -> gcry_sexp_t;
61    pub fn gcry_sexp_length(list: gcry_sexp_t) -> c_int;
62    pub fn gcry_sexp_nth(list: gcry_sexp_t, number: c_int) -> gcry_sexp_t;
63    pub fn gcry_sexp_car(list: gcry_sexp_t) -> gcry_sexp_t;
64    pub fn gcry_sexp_cdr(list: gcry_sexp_t) -> gcry_sexp_t;
65    pub fn gcry_sexp_cadr(list: gcry_sexp_t) -> gcry_sexp_t;
66    pub fn gcry_sexp_nth_data(
67        list: gcry_sexp_t, number: c_int, datalen: *mut size_t,
68    ) -> *const c_char;
69    pub fn gcry_sexp_nth_buffer(
70        list: gcry_sexp_t, number: c_int, rlength: *mut size_t,
71    ) -> *mut c_void;
72    pub fn gcry_sexp_nth_string(list: gcry_sexp_t, number: c_int) -> *mut c_char;
73    pub fn gcry_sexp_nth_mpi(list: gcry_sexp_t, number: c_int, mpifmt: c_int) -> gcry_mpi_t;
74    pub fn gcry_sexp_extract_param(
75        sexp: gcry_sexp_t, path: *const c_char, list: *const c_char, ...
76    ) -> gcry_error_t;
77
78    pub fn gcry_mpi_new(nbits: c_uint) -> gcry_mpi_t;
79    pub fn gcry_mpi_snew(nbits: c_uint) -> gcry_mpi_t;
80    pub fn gcry_mpi_release(a: gcry_mpi_t);
81    pub fn gcry_mpi_copy(a: gcry_mpi_t) -> gcry_mpi_t;
82    pub fn gcry_mpi_snatch(w: gcry_mpi_t, u: gcry_mpi_t);
83    pub fn gcry_mpi_set(w: gcry_mpi_t, u: gcry_mpi_t) -> gcry_mpi_t;
84    pub fn gcry_mpi_set_ui(w: gcry_mpi_t, u: c_ulong) -> gcry_mpi_t;
85    pub fn gcry_mpi_swap(a: gcry_mpi_t, b: gcry_mpi_t);
86    pub fn gcry_mpi_is_neg(a: gcry_mpi_t) -> c_int;
87    pub fn gcry_mpi_neg(w: gcry_mpi_t, u: gcry_mpi_t);
88    pub fn gcry_mpi_abs(w: gcry_mpi_t);
89    pub fn gcry_mpi_cmp(u: gcry_mpi_t, v: gcry_mpi_t) -> c_int;
90    pub fn gcry_mpi_cmp_ui(u: gcry_mpi_t, v: c_ulong) -> c_int;
91    pub fn gcry_mpi_scan(
92        ret_mpi: *mut gcry_mpi_t, format: gcry_mpi_format, buffer: *const c_void, buflen: size_t,
93        nscanned: *mut size_t,
94    ) -> gcry_error_t;
95    pub fn gcry_mpi_print(
96        format: gcry_mpi_format, buffer: *mut c_uchar, buflen: size_t, nwritten: *mut size_t,
97        a: gcry_mpi_t,
98    ) -> gcry_error_t;
99    pub fn gcry_mpi_aprint(
100        format: gcry_mpi_format, buffer: *mut *mut c_uchar, nwritten: *mut size_t, a: gcry_mpi_t,
101    ) -> gcry_error_t;
102    pub fn gcry_mpi_dump(a: gcry_mpi_t);
103    pub fn gcry_mpi_add(w: gcry_mpi_t, u: gcry_mpi_t, v: gcry_mpi_t);
104    pub fn gcry_mpi_add_ui(w: gcry_mpi_t, u: gcry_mpi_t, v: c_ulong);
105    pub fn gcry_mpi_addm(w: gcry_mpi_t, u: gcry_mpi_t, v: gcry_mpi_t, m: gcry_mpi_t);
106    pub fn gcry_mpi_sub(w: gcry_mpi_t, u: gcry_mpi_t, v: gcry_mpi_t);
107    pub fn gcry_mpi_sub_ui(w: gcry_mpi_t, u: gcry_mpi_t, v: c_ulong);
108    pub fn gcry_mpi_subm(w: gcry_mpi_t, u: gcry_mpi_t, v: gcry_mpi_t, m: gcry_mpi_t);
109    pub fn gcry_mpi_mul(w: gcry_mpi_t, u: gcry_mpi_t, v: gcry_mpi_t);
110    pub fn gcry_mpi_mul_ui(w: gcry_mpi_t, u: gcry_mpi_t, v: c_ulong);
111    pub fn gcry_mpi_mulm(w: gcry_mpi_t, u: gcry_mpi_t, v: gcry_mpi_t, m: gcry_mpi_t);
112    pub fn gcry_mpi_mul_2exp(w: gcry_mpi_t, u: gcry_mpi_t, cnt: c_ulong);
113    pub fn gcry_mpi_div(
114        q: gcry_mpi_t, r: gcry_mpi_t, dividend: gcry_mpi_t, divisor: gcry_mpi_t, round: c_int,
115    );
116    pub fn gcry_mpi_mod(r: gcry_mpi_t, dividend: gcry_mpi_t, divisor: gcry_mpi_t);
117    pub fn gcry_mpi_powm(w: gcry_mpi_t, b: gcry_mpi_t, e: gcry_mpi_t, m: gcry_mpi_t);
118    pub fn gcry_mpi_gcd(g: gcry_mpi_t, a: gcry_mpi_t, b: gcry_mpi_t) -> c_int;
119    pub fn gcry_mpi_invm(x: gcry_mpi_t, a: gcry_mpi_t, m: gcry_mpi_t) -> c_int;
120    pub fn gcry_mpi_point_new(nbits: c_uint) -> gcry_mpi_point_t;
121    pub fn gcry_mpi_point_release(point: gcry_mpi_point_t);
122    pub fn gcry_mpi_point_copy(point: gcry_mpi_point_t) -> gcry_mpi_point_t;
123    pub fn gcry_mpi_point_get(x: gcry_mpi_t, y: gcry_mpi_t, z: gcry_mpi_t, point: gcry_mpi_point_t);
124    pub fn gcry_mpi_point_snatch_get(
125        x: gcry_mpi_t, y: gcry_mpi_t, z: gcry_mpi_t, point: gcry_mpi_point_t,
126    );
127    pub fn gcry_mpi_point_set(
128        point: gcry_mpi_point_t, x: gcry_mpi_t, y: gcry_mpi_t, z: gcry_mpi_t,
129    ) -> gcry_mpi_point_t;
130    pub fn gcry_mpi_point_snatch_set(
131        point: gcry_mpi_point_t, x: gcry_mpi_t, y: gcry_mpi_t, z: gcry_mpi_t,
132    ) -> gcry_mpi_point_t;
133    pub fn gcry_mpi_ec_new(
134        r_ctx: *mut gcry_ctx_t, keyparam: gcry_sexp_t, curvename: *const c_char,
135    ) -> gcry_error_t;
136    pub fn gcry_mpi_ec_get_mpi(name: *const c_char, ctx: gcry_ctx_t, copy: c_int) -> gcry_mpi_t;
137    pub fn gcry_mpi_ec_get_point(
138        name: *const c_char, ctx: gcry_ctx_t, copy: c_int,
139    ) -> gcry_mpi_point_t;
140    pub fn gcry_mpi_ec_set_mpi(
141        name: *const c_char, newvalue: gcry_mpi_t, ctx: gcry_ctx_t,
142    ) -> gcry_error_t;
143    pub fn gcry_mpi_ec_set_point(
144        name: *const c_char, newvalue: gcry_mpi_point_t, ctx: gcry_ctx_t,
145    ) -> gcry_error_t;
146    pub fn gcry_mpi_ec_decode_point(
147        result: gcry_mpi_point_t, value: gcry_mpi_t, ctx: gcry_ctx_t,
148    ) -> gcry_error_t;
149    pub fn gcry_mpi_ec_get_affine(
150        x: gcry_mpi_t, y: gcry_mpi_t, point: gcry_mpi_point_t, ctx: gcry_ctx_t,
151    ) -> c_int;
152    pub fn gcry_mpi_ec_dup(w: gcry_mpi_point_t, u: gcry_mpi_point_t, ctx: gcry_ctx_t);
153    pub fn gcry_mpi_ec_add(
154        w: gcry_mpi_point_t, u: gcry_mpi_point_t, v: gcry_mpi_point_t, ctx: gcry_ctx_t,
155    );
156    pub fn gcry_mpi_ec_sub(
157        w: gcry_mpi_point_t, u: gcry_mpi_point_t, v: gcry_mpi_point_t, ctx: gcry_ctx_t,
158    );
159    pub fn gcry_mpi_ec_mul(
160        w: gcry_mpi_point_t, n: gcry_mpi_t, u: gcry_mpi_point_t, ctx: gcry_ctx_t,
161    );
162    pub fn gcry_mpi_ec_curve_point(w: gcry_mpi_point_t, ctx: gcry_ctx_t) -> c_int;
163    pub fn gcry_mpi_get_nbits(a: gcry_mpi_t) -> c_uint;
164    pub fn gcry_mpi_test_bit(a: gcry_mpi_t, n: c_uint) -> c_int;
165    pub fn gcry_mpi_set_bit(a: gcry_mpi_t, n: c_uint);
166    pub fn gcry_mpi_clear_bit(a: gcry_mpi_t, n: c_uint);
167    pub fn gcry_mpi_set_highbit(a: gcry_mpi_t, n: c_uint);
168    pub fn gcry_mpi_clear_highbit(a: gcry_mpi_t, n: c_uint);
169    pub fn gcry_mpi_rshift(x: gcry_mpi_t, a: gcry_mpi_t, n: c_uint);
170    pub fn gcry_mpi_lshift(x: gcry_mpi_t, a: gcry_mpi_t, n: c_uint);
171    pub fn gcry_mpi_set_opaque(a: gcry_mpi_t, p: *mut c_void, nbits: c_uint) -> gcry_mpi_t;
172    pub fn gcry_mpi_set_opaque_copy(a: gcry_mpi_t, p: *const c_void, nbits: c_uint) -> gcry_mpi_t;
173    pub fn gcry_mpi_get_opaque(a: gcry_mpi_t, nbits: *mut c_uint) -> *mut c_void;
174    pub fn gcry_mpi_set_flag(a: gcry_mpi_t, flag: gcry_mpi_flag);
175    pub fn gcry_mpi_clear_flag(a: gcry_mpi_t, flag: gcry_mpi_flag);
176    pub fn gcry_mpi_get_flag(a: gcry_mpi_t, flag: gcry_mpi_flag) -> c_int;
177
178    pub fn gcry_cipher_open(
179        handle: *mut gcry_cipher_hd_t, algo: c_int, mode: c_int, flags: c_uint,
180    ) -> gcry_error_t;
181    pub fn gcry_cipher_close(handle: gcry_cipher_hd_t);
182    pub fn gcry_cipher_ctl(
183        handle: gcry_cipher_hd_t, cmd: c_int, buffer: *mut c_void, buflen: size_t,
184    ) -> gcry_error_t;
185    pub fn gcry_cipher_info(
186        handle: gcry_cipher_hd_t, what: c_int, buffer: *mut c_void, nbytes: *mut size_t,
187    ) -> gcry_error_t;
188    pub fn gcry_cipher_algo_info(
189        algo: c_int, what: c_int, buffer: *mut c_void, nbytes: *mut size_t,
190    ) -> gcry_error_t;
191    pub fn gcry_cipher_algo_name(algo: c_int) -> *const c_char;
192    pub fn gcry_cipher_map_name(name: *const c_char) -> c_int;
193    pub fn gcry_cipher_mode_from_oid(string: *const c_char) -> c_int;
194    pub fn gcry_cipher_get_algo_keylen(algo: c_int) -> size_t;
195    pub fn gcry_cipher_get_algo_blklen(algo: c_int) -> size_t;
196    pub fn gcry_cipher_encrypt(
197        handle: gcry_cipher_hd_t, output: *mut c_void, outsize: size_t, input: *const c_void,
198        inlen: size_t,
199    ) -> gcry_error_t;
200    pub fn gcry_cipher_decrypt(
201        handle: gcry_cipher_hd_t, output: *mut c_void, outsize: size_t, input: *const c_void,
202        inlen: size_t,
203    ) -> gcry_error_t;
204    pub fn gcry_cipher_setkey(
205        handle: gcry_cipher_hd_t, key: *const c_void, keylen: size_t,
206    ) -> gcry_error_t;
207    pub fn gcry_cipher_setiv(
208        handle: gcry_cipher_hd_t, iv: *const c_void, ivlen: size_t,
209    ) -> gcry_error_t;
210    pub fn gcry_cipher_setctr(
211        handle: gcry_cipher_hd_t, ctr: *const c_void, ctrlen: size_t,
212    ) -> gcry_error_t;
213    pub fn gcry_cipher_authenticate(
214        handle: gcry_cipher_hd_t, abuf: *const c_void, abuflen: size_t,
215    ) -> gcry_error_t;
216    pub fn gcry_cipher_gettag(
217        handle: gcry_cipher_hd_t, outtag: *mut c_void, taglen: size_t,
218    ) -> gcry_error_t;
219    pub fn gcry_cipher_checktag(
220        handle: gcry_cipher_hd_t, in_tag: *const c_void, taglen: size_t,
221    ) -> gcry_error_t;
222
223    pub fn gcry_pk_encrypt(
224        result: *mut gcry_sexp_t, data: gcry_sexp_t, pkey: gcry_sexp_t,
225    ) -> gcry_error_t;
226    pub fn gcry_pk_decrypt(
227        result: *mut gcry_sexp_t, data: gcry_sexp_t, skey: gcry_sexp_t,
228    ) -> gcry_error_t;
229    pub fn gcry_pk_sign(
230        result: *mut gcry_sexp_t, data: gcry_sexp_t, skey: gcry_sexp_t,
231    ) -> gcry_error_t;
232    pub fn gcry_pk_verify(
233        sigval: gcry_sexp_t, data: gcry_sexp_t, pkey: gcry_sexp_t,
234    ) -> gcry_error_t;
235    pub fn gcry_pk_testkey(key: gcry_sexp_t) -> gcry_error_t;
236    pub fn gcry_pk_genkey(r_key: *mut gcry_sexp_t, s_parms: gcry_sexp_t) -> gcry_error_t;
237    pub fn gcry_pk_ctl(cmd: c_int, buffer: *mut c_void, buflen: size_t) -> gcry_error_t;
238    pub fn gcry_pk_algo_info(
239        algo: c_int, what: c_int, buffer: *mut c_void, nbytes: *mut size_t,
240    ) -> gcry_error_t;
241    pub fn gcry_pk_algo_name(algorithm: c_int) -> *const c_char;
242    pub fn gcry_pk_map_name(name: *const c_char) -> c_int;
243    pub fn gcry_pk_get_nbits(key: gcry_sexp_t) -> c_uint;
244    pub fn gcry_pk_get_keygrip(key: gcry_sexp_t, array: *mut c_uchar) -> *mut c_uchar;
245    pub fn gcry_pk_get_curve(
246        key: gcry_sexp_t, iterator: c_int, r_nbits: *mut c_uint,
247    ) -> *const c_char;
248    pub fn gcry_pk_get_param(algo: c_int, name: *const c_char) -> gcry_sexp_t;
249    pub fn gcry_pubkey_get_sexp(
250        r_sexp: *mut gcry_sexp_t, mode: c_int, ctx: gcry_ctx_t,
251    ) -> gcry_error_t;
252
253    pub fn gcry_md_open(h: *mut gcry_md_hd_t, algo: c_int, flags: c_uint) -> gcry_error_t;
254    pub fn gcry_md_close(h: gcry_md_hd_t);
255    pub fn gcry_md_enable(h: gcry_md_hd_t, algo: c_int) -> gcry_error_t;
256    pub fn gcry_md_copy(new: *mut gcry_md_hd_t, old: gcry_md_hd_t) -> gcry_error_t;
257    pub fn gcry_md_reset(h: gcry_md_hd_t);
258    pub fn gcry_md_ctl(
259        h: gcry_md_hd_t, cmd: c_int, buffer: *mut c_void, buflen: size_t,
260    ) -> gcry_error_t;
261    pub fn gcry_md_write(h: gcry_md_hd_t, buffer: *const c_void, length: size_t);
262    pub fn gcry_md_read(h: gcry_md_hd_t, algo: c_int) -> *mut u8;
263    pub fn gcry_md_extract(
264        hd: gcry_md_hd_t, algo: c_int, buffer: *mut c_void, length: size_t,
265    ) -> gcry_error_t;
266    pub fn gcry_md_hash_buffer(
267        algo: c_int, digest: *mut c_void, buffer: *const c_void, length: size_t,
268    );
269    pub fn gcry_md_get_algo(h: gcry_md_hd_t) -> c_int;
270    pub fn gcry_md_get_algo_dlen(algo: c_int) -> c_uint;
271    pub fn gcry_md_is_enabled(a: gcry_md_hd_t, algo: c_int) -> c_int;
272    pub fn gcry_md_is_secure(a: gcry_md_hd_t) -> c_int;
273    pub fn gcry_md_info(
274        h: gcry_md_hd_t, what: c_int, buffer: *mut c_void, nbytes: *mut size_t,
275    ) -> gcry_error_t;
276    pub fn gcry_md_algo_info(
277        algo: c_int, what: c_int, buffer: *mut c_void, nbytes: *mut size_t,
278    ) -> gcry_error_t;
279    pub fn gcry_md_algo_name(algo: c_int) -> *const c_char;
280    pub fn gcry_md_map_name(name: *const c_char) -> c_int;
281    pub fn gcry_md_setkey(h: gcry_md_hd_t, key: *const c_void, keylen: size_t) -> gcry_error_t;
282
283    pub fn gcry_mac_open(
284        handle: *mut gcry_mac_hd_t, algo: c_int, flags: c_uint, ctx: gcry_ctx_t,
285    ) -> gcry_error_t;
286    pub fn gcry_mac_close(h: gcry_mac_hd_t);
287    pub fn gcry_mac_ctl(
288        h: gcry_mac_hd_t, cmd: c_int, buffer: *mut c_void, buflen: size_t,
289    ) -> gcry_error_t;
290    pub fn gcry_mac_algo_info(
291        algo: c_int, what: c_int, buffer: *mut c_void, nbytes: *mut size_t,
292    ) -> gcry_error_t;
293    pub fn gcry_mac_setkey(h: gcry_mac_hd_t, key: *const c_void, keylen: size_t) -> gcry_error_t;
294    pub fn gcry_mac_setiv(h: gcry_mac_hd_t, iv: *const c_void, ivlen: size_t) -> gcry_error_t;
295    pub fn gcry_mac_write(h: gcry_mac_hd_t, buffer: *const c_void, length: size_t) -> gcry_error_t;
296    pub fn gcry_mac_read(
297        h: gcry_mac_hd_t, buffer: *mut c_void, buflen: *mut size_t,
298    ) -> gcry_error_t;
299    pub fn gcry_mac_verify(h: gcry_mac_hd_t, buffer: *const c_void, buflen: size_t)
300        -> gcry_error_t;
301    pub fn gcry_mac_get_algo(hd: gcry_mac_hd_t) -> c_int;
302    pub fn gcry_mac_get_algo_maclen(algo: c_int) -> c_uint;
303    pub fn gcry_mac_get_algo_keylen(algo: c_int) -> c_uint;
304    pub fn gcry_mac_algo_name(algorithm: c_int) -> *const c_char;
305    pub fn gcry_mac_map_name(name: *const c_char) -> c_int;
306
307    pub fn gcry_kdf_derive(
308        passphrase: *const c_void, passphraselen: size_t, algo: c_int, subalgo: c_int,
309        salt: *const c_void, saltlen: size_t, iterations: c_ulong, keysize: size_t,
310        keybuffer: *mut c_void,
311    ) -> gcry_error_t;
312
313    pub fn gcry_randomize(buffer: *mut c_void, length: size_t, level: gcry_random_level_t);
314    pub fn gcry_random_add_bytes(
315        buffer: *const c_void, length: size_t, quality: c_int,
316    ) -> gcry_error_t;
317    pub fn gcry_random_bytes(nbytes: size_t, level: gcry_random_level_t) -> *mut c_void;
318    pub fn gcry_random_bytes_secure(nbytes: size_t, level: gcry_random_level_t) -> *mut c_void;
319    pub fn gcry_create_nonce(buffer: *mut c_void, length: size_t);
320    pub fn gcry_mpi_randomize(w: gcry_mpi_t, nbits: c_uint, level: gcry_random_level_t);
321
322    pub fn gcry_prime_generate(
323        prime: *mut gcry_mpi_t, prime_bits: c_uint, factor_bits: c_uint,
324        factors: *mut *mut gcry_mpi_t, cb: gcry_prime_check_func_t, cb_arg: *mut c_void,
325        random_level: gcry_random_level_t, flags: c_uint,
326    ) -> gcry_error_t;
327    pub fn gcry_prime_group_generator(
328        r_g: *mut gcry_mpi_t, prime: gcry_mpi_t, factors: *mut gcry_mpi_t, start_g: gcry_mpi_t,
329    ) -> gcry_error_t;
330    pub fn gcry_prime_release_factors(factors: *mut gcry_mpi_t);
331    pub fn gcry_prime_check(x: gcry_mpi_t, flags: c_uint) -> gcry_error_t;
332
333    pub fn gcry_ctx_release(ctx: gcry_ctx_t);
334
335    pub fn gcry_log_debug(fmt: *const c_char, ...);
336    pub fn gcry_log_debughex(text: *const c_char, buffer: *const c_void, length: size_t);
337    pub fn gcry_log_debugmpi(text: *const c_char, mpi: gcry_mpi_t);
338    pub fn gcry_log_debugpnt(text: *const c_char, point: gcry_mpi_point_t, ctx: gcry_ctx_t);
339    pub fn gcry_log_debugsxp(text: *const c_char, sexp: gcry_sexp_t);
340
341    pub fn gcry_get_config(mode: c_int, what: *const c_char) -> *mut c_char;
342
343    pub fn gcry_set_progress_handler(cb: gcry_handler_progress_t, cb_data: *mut c_void);
344    pub fn gcry_set_allocation_handler(
345        func_alloc: gcry_handler_alloc_t, func_alloc_secure: gcry_handler_alloc_t,
346        func_secure_check: gcry_handler_secure_check_t, func_realloc: gcry_handler_realloc_t,
347        func_free: gcry_handler_free_t,
348    );
349    pub fn gcry_set_outofcore_handler(h: gcry_handler_no_mem_t, opaque: *mut c_void);
350    pub fn gcry_set_fatalerror_handler(fnc: gcry_handler_error_t, opaque: *mut c_void);
351    //pub fn gcry_set_log_handler(f: gcry_handler_log_t, opaque: *mut c_void);
352
353    pub fn gcry_malloc(n: size_t) -> *mut c_void;
354    pub fn gcry_calloc(n: size_t, m: size_t) -> *mut c_void;
355    pub fn gcry_malloc_secure(n: size_t) -> *mut c_void;
356    pub fn gcry_calloc_secure(n: size_t, m: size_t) -> *mut c_void;
357    pub fn gcry_realloc(a: *mut c_void, n: size_t) -> *mut c_void;
358    pub fn gcry_strdup(string: *const c_char) -> *mut c_char;
359    pub fn gcry_xmalloc(n: size_t) -> *mut c_void;
360    pub fn gcry_xcalloc(n: size_t, m: size_t) -> *mut c_void;
361    pub fn gcry_xmalloc_secure(n: size_t) -> *mut c_void;
362    pub fn gcry_xcalloc_secure(n: size_t, m: size_t) -> *mut c_void;
363    pub fn gcry_xrealloc(a: *mut c_void, n: size_t) -> *mut c_void;
364    pub fn gcry_xstrdup(a: *const c_char) -> *mut c_char;
365    pub fn gcry_free(a: *mut c_void);
366    pub fn gcry_is_secure(a: *const c_void) -> c_int;
367
368    #[doc(hidden)]
369    pub fn _gcry_mpi_get_const(n: c_int) -> gcry_mpi_t;
370}
371
372#[inline]
373pub unsafe fn gcry_fips_mode_active() -> bool {
374    gcry_control(GCRYCTL_FIPS_MODE_P, 0) != 0
375}
376#[inline]
377pub unsafe fn gcry_fast_random_poll() -> gcry_error_t {
378    gcry_control(GCRYCTL_FAST_POLL, 0)
379}
380
381#[inline]
382pub unsafe fn gcry_cipher_test_algo(a: c_int) -> gcry_error_t {
383    gcry_cipher_algo_info(
384        a,
385        GCRYCTL_TEST_ALGO as c_int,
386        ptr::null_mut(),
387        ptr::null_mut(),
388    )
389}
390#[inline]
391pub unsafe fn gcry_md_test_algo(a: c_int) -> gcry_error_t {
392    gcry_md_algo_info(
393        a,
394        GCRYCTL_TEST_ALGO as c_int,
395        ptr::null_mut(),
396        ptr::null_mut(),
397    )
398}
399#[inline]
400pub unsafe fn gcry_mac_test_algo(a: c_int) -> gcry_error_t {
401    gcry_mac_algo_info(
402        a,
403        GCRYCTL_TEST_ALGO as c_int,
404        ptr::null_mut(),
405        ptr::null_mut(),
406    )
407}
408#[inline]
409pub unsafe fn gcry_pk_test_algo(a: c_int) -> gcry_error_t {
410    gcry_pk_algo_info(
411        a,
412        GCRYCTL_TEST_ALGO as c_int,
413        ptr::null_mut(),
414        ptr::null_mut(),
415    )
416}
417
418#[inline]
419pub unsafe fn gcry_cipher_reset(h: gcry_cipher_hd_t) -> gcry_error_t {
420    gcry_cipher_ctl(h, GCRYCTL_RESET as c_int, ptr::null_mut(), 0)
421}
422#[inline]
423pub unsafe fn gcry_cipher_sync(h: gcry_cipher_hd_t) -> gcry_error_t {
424    gcry_cipher_ctl(h, GCRYCTL_CFB_SYNC as c_int, ptr::null_mut(), 0)
425}
426#[inline]
427pub unsafe fn gcry_cipher_cts(h: gcry_cipher_hd_t, on: bool) -> gcry_error_t {
428    gcry_cipher_ctl(
429        h,
430        GCRYCTL_SET_CBC_CTS as c_int,
431        ptr::null_mut(),
432        if on { 1 } else { 0 },
433    )
434}
435#[inline]
436pub unsafe fn gcry_cipher_set_sbox(h: gcry_cipher_hd_t, oid: *const c_char) -> gcry_error_t {
437    gcry_cipher_ctl(h, GCRYCTL_SET_SBOX as c_int, oid as *mut _, 0)
438}
439#[inline]
440pub unsafe fn gcry_cipher_final(h: gcry_cipher_hd_t) -> gcry_error_t {
441    gcry_cipher_ctl(h, GCRYCTL_FINALIZE as c_int, ptr::null_mut(), 0)
442}
443
444#[inline]
445pub unsafe fn gcry_md_final(h: gcry_md_hd_t) -> gcry_error_t {
446    gcry_md_ctl(h, GCRYCTL_FINALIZE as c_int, ptr::null_mut(), 0)
447}
448#[inline]
449pub unsafe fn gcry_md_get_asnoid(a: c_int, b: *mut c_void, n: &mut size_t) -> gcry_error_t {
450    gcry_md_algo_info(a, GCRYCTL_GET_ASNOID as c_int, b, n)
451}
452
453#[inline]
454pub unsafe fn gcry_mac_reset(h: gcry_mac_hd_t) -> gcry_error_t {
455    gcry_mac_ctl(h, GCRYCTL_RESET as c_int, ptr::null_mut(), 0)
456}
457
458#[inline]
459pub unsafe fn gcrympi_const_one() -> gcry_mpi_t {
460    _gcry_mpi_get_const(1)
461}
462
463#[inline]
464pub unsafe fn gcrympi_const_two() -> gcry_mpi_t {
465    _gcry_mpi_get_const(2)
466}
467
468#[inline]
469pub unsafe fn gcrympi_const_three() -> gcry_mpi_t {
470    _gcry_mpi_get_const(3)
471}
472
473#[inline]
474pub unsafe fn gcrympi_const_four() -> gcry_mpi_t {
475    _gcry_mpi_get_const(4)
476}
477
478#[inline]
479pub unsafe fn gcrympi_const_eight() -> gcry_mpi_t {
480    _gcry_mpi_get_const(8)
481}