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
use crate::ffi_types::*;

use crate::pubkey::{botan_privkey_t, botan_pubkey_t};
use crate::rng::botan_rng_t;

pub enum botan_pk_op_encrypt_struct {}
pub type botan_pk_op_encrypt_t = *mut botan_pk_op_encrypt_struct;

pub enum botan_pk_op_decrypt_struct {}
pub type botan_pk_op_decrypt_t = *mut botan_pk_op_decrypt_struct;

pub enum botan_pk_op_sign_struct {}
pub type botan_pk_op_sign_t = *mut botan_pk_op_sign_struct;

pub enum botan_pk_op_verify_struct {}
pub type botan_pk_op_verify_t = *mut botan_pk_op_verify_struct;

pub enum botan_pk_op_ka_struct {}
pub type botan_pk_op_ka_t = *mut botan_pk_op_ka_struct;

pub enum botan_pk_op_kem_encrypt_struct {}
pub type botan_pk_op_kem_encrypt_t = *mut botan_pk_op_kem_encrypt_struct;

pub enum botan_pk_op_kem_decrypt_struct {}
pub type botan_pk_op_kem_decrypt_t = *mut botan_pk_op_kem_decrypt_struct;

extern "C" {
    pub fn botan_pk_op_encrypt_create(
        op: *mut botan_pk_op_encrypt_t,
        key: botan_pubkey_t,
        padding: *const c_char,
        flags: u32,
    ) -> c_int;
    pub fn botan_pk_op_encrypt_destroy(op: botan_pk_op_encrypt_t) -> c_int;

    pub fn botan_pk_op_encrypt_output_length(
        op: botan_pk_op_encrypt_t,
        inlen: usize,
        outlen: *mut usize,
    ) -> c_int;

    pub fn botan_pk_op_encrypt(
        op: botan_pk_op_encrypt_t,
        rng: botan_rng_t,
        out: *mut u8,
        out_len: *mut usize,
        plaintext: *const u8,
        plaintext_len: usize,
    ) -> c_int;

    pub fn botan_pk_op_decrypt_create(
        op: *mut botan_pk_op_decrypt_t,
        key: botan_privkey_t,
        padding: *const c_char,
        flags: u32,
    ) -> c_int;
    pub fn botan_pk_op_decrypt_output_length(
        op: botan_pk_op_decrypt_t,
        inlen: usize,
        outlen: *mut usize,
    ) -> c_int;
    pub fn botan_pk_op_decrypt_destroy(op: botan_pk_op_decrypt_t) -> c_int;
    pub fn botan_pk_op_decrypt(
        op: botan_pk_op_decrypt_t,
        out: *mut u8,
        out_len: *mut usize,
        ciphertext: *const u8,
        ciphertext_len: usize,
    ) -> c_int;

    pub fn botan_pk_op_sign_create(
        op: *mut botan_pk_op_sign_t,
        key: botan_privkey_t,
        hash_and_padding: *const c_char,
        flags: u32,
    ) -> c_int;
    pub fn botan_pk_op_sign_output_length(op: botan_pk_op_sign_t, siglen: *mut usize) -> c_int;
    pub fn botan_pk_op_sign_destroy(op: botan_pk_op_sign_t) -> c_int;
    pub fn botan_pk_op_sign_update(op: botan_pk_op_sign_t, in_: *const u8, in_len: usize) -> c_int;
    pub fn botan_pk_op_sign_finish(
        op: botan_pk_op_sign_t,
        rng: botan_rng_t,
        sig: *mut u8,
        sig_len: *mut usize,
    ) -> c_int;

    pub fn botan_pk_op_verify_create(
        op: *mut botan_pk_op_verify_t,
        key: botan_pubkey_t,
        hash_and_padding: *const c_char,
        flags: u32,
    ) -> c_int;
    pub fn botan_pk_op_verify_destroy(op: botan_pk_op_verify_t) -> c_int;
    pub fn botan_pk_op_verify_update(
        op: botan_pk_op_verify_t,
        in_: *const u8,
        in_len: usize,
    ) -> c_int;
    pub fn botan_pk_op_verify_finish(
        op: botan_pk_op_verify_t,
        sig: *const u8,
        sig_len: usize,
    ) -> c_int;

    pub fn botan_pk_op_key_agreement_create(
        op: *mut botan_pk_op_ka_t,
        key: botan_privkey_t,
        kdf: *const c_char,
        flags: u32,
    ) -> c_int;
    pub fn botan_pk_op_key_agreement_destroy(op: botan_pk_op_ka_t) -> c_int;
    pub fn botan_pk_op_key_agreement_size(op: botan_pk_op_ka_t, agreed_len: *mut usize) -> c_int;
    pub fn botan_pk_op_key_agreement_export_public(
        key: botan_privkey_t,
        out: *mut u8,
        out_len: *mut usize,
    ) -> c_int;

    pub fn botan_pk_op_key_agreement(
        op: botan_pk_op_ka_t,
        out: *mut u8,
        out_len: *mut usize,
        other_key: *const u8,
        other_key_len: usize,
        salt: *const u8,
        salt_len: usize,
    ) -> c_int;
    pub fn botan_pkcs_hash_id(
        hash_name: *const c_char,
        pkcs_id: *mut u8,
        pkcs_id_len: *mut usize,
    ) -> c_int;
}

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

    pub fn botan_pk_op_kem_encrypt_create(
        op: *mut botan_pk_op_kem_encrypt_t,
        key: botan_pubkey_t,
        kdf: *const c_char,
    ) -> c_int;

    pub fn botan_pk_op_kem_encrypt_destroy(op: botan_pk_op_kem_encrypt_t) -> c_int;

    pub fn botan_pk_op_kem_encrypt_shared_key_length(
        op: botan_pk_op_kem_encrypt_t,
        desired_shared_key_length: usize,
        output_shared_key_length: *mut usize,
    ) -> c_int;

    pub fn botan_pk_op_kem_encrypt_encapsulated_key_length(
        op: botan_pk_op_kem_encrypt_t,
        output_encapsulated_key_length: *mut usize,
    ) -> c_int;

    pub fn botan_pk_op_kem_encrypt_create_shared_key(
        op: botan_pk_op_kem_encrypt_t,
        rng: botan_rng_t,
        salt: *const u8,
        salt_len: usize,
        desired_shared_key_len: usize,
        shared_key: *mut u8,
        shared_key_len: *mut usize,
        encapsulated_key: *mut u8,
        encapsulated_key_len: *mut usize,
    ) -> c_int;

    pub fn botan_pk_op_kem_decrypt_destroy(op: botan_pk_op_kem_decrypt_t) -> c_int;

    pub fn botan_pk_op_kem_decrypt_create(
        op: *mut botan_pk_op_kem_decrypt_t,
        key: botan_privkey_t,
        kdf: *const c_char,
    ) -> c_int;

    pub fn botan_pk_op_kem_decrypt_shared_key_length(
        op: botan_pk_op_kem_decrypt_t,
        desired_shared_key_length: usize,
        output_shared_key_length: *mut usize,
    ) -> c_int;

    pub fn botan_pk_op_kem_decrypt_shared_key(
        op: botan_pk_op_kem_decrypt_t,
        salt: *const u8,
        salt_len: usize,
        encapsulated_key: *const u8,
        encapsulated_key_len: usize,
        desired_shared_key_len: usize,
        shared_key: *mut u8,
        shared_key_len: *mut usize,
    ) -> c_int;
}