1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
use crate::ffi_types::*;

use crate::mp::botan_mp_t;
use crate::rng::botan_rng_t;

pub enum botan_pubkey_struct {}
pub type botan_pubkey_t = *mut botan_pubkey_struct;

pub enum botan_privkey_struct {}
pub type botan_privkey_t = *mut botan_privkey_struct;

extern "C" {
    pub fn botan_privkey_create(
        key: *mut botan_privkey_t,
        algo_name: *const c_char,
        algo_params: *const c_char,
        rng: botan_rng_t,
    ) -> c_int;
    pub fn botan_privkey_check_key(key: botan_privkey_t, rng: botan_rng_t, flags: u32) -> c_int;
    pub fn botan_privkey_create_rsa(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        n_bits: usize,
    ) -> c_int;
    pub fn botan_privkey_create_ecdsa(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        params: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_create_ecdh(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        params: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_create_mceliece(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        n: usize,
        t: usize,
    ) -> c_int;
    pub fn botan_privkey_create_dh(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        param: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_create_dsa(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        pbits: usize,
        qbits: usize,
    ) -> c_int;
    pub fn botan_privkey_create_elgamal(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        pbits: usize,
        qbits: usize,
    ) -> c_int;
    pub fn botan_privkey_load(
        key: *mut botan_privkey_t,
        rng: botan_rng_t,
        bits: *const u8,
        len: usize,
        password: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_destroy(key: botan_privkey_t) -> c_int;
    pub fn botan_privkey_export(
        key: botan_privkey_t,
        out: *mut u8,
        out_len: *mut usize,
        flags: u32,
    ) -> c_int;
    pub fn botan_privkey_export_encrypted(
        key: botan_privkey_t,
        out: *mut u8,
        out_len: *mut usize,
        rng: botan_rng_t,
        passphrase: *const c_char,
        encryption_algo: *const c_char,
        flags: u32,
    ) -> c_int;
    pub fn botan_privkey_export_encrypted_pbkdf_msec(
        key: botan_privkey_t,
        out: *mut u8,
        out_len: *mut usize,
        rng: botan_rng_t,
        passphrase: *const c_char,
        pbkdf_msec_runtime: u32,
        pbkdf_iterations_out: *mut usize,
        cipher_algo: *const c_char,
        pbkdf_algo: *const c_char,
        flags: u32,
    ) -> c_int;
    pub fn botan_privkey_export_encrypted_pbkdf_iter(
        key: botan_privkey_t,
        out: *mut u8,
        out_len: *mut usize,
        rng: botan_rng_t,
        passphrase: *const c_char,
        pbkdf_iterations: usize,
        cipher_algo: *const c_char,
        pbkdf_algo: *const c_char,
        flags: u32,
    ) -> c_int;

    pub fn botan_pubkey_load(key: *mut botan_pubkey_t, bits: *const u8, len: usize) -> c_int;
    pub fn botan_privkey_export_pubkey(out: *mut botan_pubkey_t, in_: botan_privkey_t) -> c_int;
    pub fn botan_pubkey_export(
        key: botan_pubkey_t,
        out: *mut u8,
        out_len: *mut usize,
        flags: u32,
    ) -> c_int;
    pub fn botan_privkey_algo_name(
        key: botan_privkey_t,
        out: *mut c_char,
        out_len: *mut usize,
    ) -> c_int;
    pub fn botan_pubkey_algo_name(
        key: botan_pubkey_t,
        out: *mut c_char,
        out_len: *mut usize,
    ) -> c_int;
    pub fn botan_pubkey_check_key(key: botan_pubkey_t, rng: botan_rng_t, flags: u32) -> c_int;
    pub fn botan_pubkey_estimated_strength(key: botan_pubkey_t, estimate: *mut usize) -> c_int;
    pub fn botan_pubkey_fingerprint(
        key: botan_pubkey_t,
        hash: *const c_char,
        out: *mut u8,
        out_len: *mut usize,
    ) -> c_int;
    pub fn botan_pubkey_destroy(key: botan_pubkey_t) -> c_int;
    pub fn botan_pubkey_get_field(
        output: botan_mp_t,
        key: botan_pubkey_t,
        field_name: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_get_field(
        output: botan_mp_t,
        key: botan_privkey_t,
        field_name: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_load_rsa(
        key: *mut botan_privkey_t,
        p: botan_mp_t,
        q: botan_mp_t,
        e: botan_mp_t,
    ) -> c_int;
    pub fn botan_privkey_load_rsa_pkcs1(
        key: *mut botan_privkey_t,
        bits: *const u8,
        len: usize,
    ) -> c_int;
    pub fn botan_privkey_rsa_get_p(p: botan_mp_t, rsa_key: botan_privkey_t) -> c_int;
    pub fn botan_privkey_rsa_get_q(q: botan_mp_t, rsa_key: botan_privkey_t) -> c_int;
    pub fn botan_privkey_rsa_get_d(d: botan_mp_t, rsa_key: botan_privkey_t) -> c_int;
    pub fn botan_privkey_rsa_get_n(n: botan_mp_t, rsa_key: botan_privkey_t) -> c_int;
    pub fn botan_privkey_rsa_get_e(e: botan_mp_t, rsa_key: botan_privkey_t) -> c_int;
    pub fn botan_pubkey_load_rsa(key: *mut botan_pubkey_t, n: botan_mp_t, e: botan_mp_t) -> c_int;
    pub fn botan_pubkey_rsa_get_e(e: botan_mp_t, rsa_key: botan_pubkey_t) -> c_int;
    pub fn botan_pubkey_rsa_get_n(n: botan_mp_t, rsa_key: botan_pubkey_t) -> c_int;
    pub fn botan_privkey_load_dsa(
        key: *mut botan_privkey_t,
        p: botan_mp_t,
        q: botan_mp_t,
        g: botan_mp_t,
        x: botan_mp_t,
    ) -> c_int;
    pub fn botan_pubkey_load_dsa(
        key: *mut botan_pubkey_t,
        p: botan_mp_t,
        q: botan_mp_t,
        g: botan_mp_t,
        y: botan_mp_t,
    ) -> c_int;
    pub fn botan_privkey_dsa_get_x(n: botan_mp_t, key: botan_privkey_t) -> c_int;
    pub fn botan_pubkey_dsa_get_p(p: botan_mp_t, key: botan_pubkey_t) -> c_int;
    pub fn botan_pubkey_dsa_get_q(q: botan_mp_t, key: botan_pubkey_t) -> c_int;
    pub fn botan_pubkey_dsa_get_g(d: botan_mp_t, key: botan_pubkey_t) -> c_int;
    pub fn botan_pubkey_dsa_get_y(y: botan_mp_t, key: botan_pubkey_t) -> c_int;
    pub fn botan_privkey_load_dh(
        key: *mut botan_privkey_t,
        p: botan_mp_t,
        g: botan_mp_t,
        x: botan_mp_t,
    ) -> c_int;
    pub fn botan_pubkey_load_dh(
        key: *mut botan_pubkey_t,
        p: botan_mp_t,
        g: botan_mp_t,
        y: botan_mp_t,
    ) -> c_int;
    pub fn botan_pubkey_load_elgamal(
        key: *mut botan_pubkey_t,
        p: botan_mp_t,
        g: botan_mp_t,
        y: botan_mp_t,
    ) -> c_int;
    pub fn botan_privkey_load_elgamal(
        key: *mut botan_privkey_t,
        p: botan_mp_t,
        g: botan_mp_t,
        x: botan_mp_t,
    ) -> c_int;
    pub fn botan_privkey_load_ed25519(key: *mut botan_privkey_t, privkey: *const u8) -> c_int;
    pub fn botan_pubkey_load_ed25519(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int;
    pub fn botan_privkey_ed25519_get_privkey(key: botan_privkey_t, output: *mut u8) -> c_int;
    pub fn botan_pubkey_ed25519_get_pubkey(key: botan_pubkey_t, pubkey: *mut u8) -> c_int;

    pub fn botan_privkey_load_x25519(key: *mut botan_privkey_t, privkey: *const u8) -> c_int;
    pub fn botan_pubkey_load_x25519(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int;
    pub fn botan_privkey_x25519_get_privkey(key: botan_privkey_t, output: *mut u8) -> c_int;
    pub fn botan_pubkey_x25519_get_pubkey(key: botan_pubkey_t, pubkey: *mut u8) -> c_int;

    pub fn botan_privkey_load_ecdsa(
        key: *mut botan_privkey_t,
        scalar: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_pubkey_load_ecdsa(
        key: *mut botan_pubkey_t,
        public_x: botan_mp_t,
        public_y: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_pubkey_load_ecdh(
        key: *mut botan_pubkey_t,
        public_x: botan_mp_t,
        public_y: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_load_ecdh(
        key: *mut botan_privkey_t,
        scalar: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_pubkey_load_sm2(
        key: *mut botan_pubkey_t,
        public_x: botan_mp_t,
        public_y: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_load_sm2(
        key: *mut botan_privkey_t,
        scalar: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_pubkey_load_sm2_enc(
        key: *mut botan_pubkey_t,
        public_x: botan_mp_t,
        public_y: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_privkey_load_sm2_enc(
        key: *mut botan_privkey_t,
        scalar: botan_mp_t,
        curve_name: *const c_char,
    ) -> c_int;
    pub fn botan_pubkey_sm2_compute_za(
        out: *mut u8,
        out_len: *mut usize,
        ident: *const c_char,
        hash_algo: *const c_char,
        key: botan_pubkey_t,
    ) -> c_int;
}

#[cfg(feature = "botan3")]
extern "C" {
    pub fn botan_pubkey_view_der(
        key: botan_pubkey_t,
        view_ctx: botan_view_ctx,
        view_fn: botan_view_bin_fn,
    ) -> c_int;

    pub fn botan_pubkey_view_pem(
        key: botan_pubkey_t,
        view_ctx: botan_view_ctx,
        view_fn: botan_view_str_fn,
    ) -> c_int;

    pub fn botan_privkey_view_der(
        key: botan_privkey_t,
        view_ctx: botan_view_ctx,
        view_fn: botan_view_bin_fn,
    ) -> c_int;

    pub fn botan_privkey_view_pem(
        key: botan_privkey_t,
        view_ctx: botan_view_ctx,
        view_fn: botan_view_str_fn,
    ) -> c_int;

    pub fn botan_pubkey_view_ec_public_point(
        key: botan_pubkey_t,
        view_ctx: botan_view_ctx,
        view_fn: botan_view_bin_fn,
    ) -> c_int;

    pub fn botan_privkey_view_encrypted_der(
        key: botan_privkey_t,
        rng: botan_rng_t,
        passphrase: *const c_char,
        cipher_algo: *const c_char,
        pbkdf_algo: *const c_char,
        pbkdf_iterations: usize,
        view_ctx: botan_view_ctx,
        view_fn: botan_view_bin_fn,
    ) -> c_int;

    pub fn botan_privkey_view_encrypted_pem(
        key: botan_privkey_t,
        rng: botan_rng_t,
        passphrase: *const c_char,
        cipher_algo: *const c_char,
        pbkdf_algo: *const c_char,
        pbkdf_iterations: usize,
        view_ctx: botan_view_ctx,
        view_fn: botan_view_str_fn,
    ) -> c_int;
}