1use super::*;
2use libc::*;
3
4pub const EVP_MAX_MD_SIZE: c_uint = 64;
5
6pub const PKCS5_SALT_LEN: c_int = 8;
7pub const PKCS12_DEFAULT_ITER: c_int = 2048;
8
9pub const EVP_PKEY_RSA: c_int = NID_rsaEncryption;
10#[cfg(any(ossl111, libressl310, boringssl))]
11pub const EVP_PKEY_RSA_PSS: c_int = NID_rsassaPss;
12pub const EVP_PKEY_DSA: c_int = NID_dsa;
13pub const EVP_PKEY_DH: c_int = NID_dhKeyAgreement;
14#[cfg(ossl110)]
15pub const EVP_PKEY_DHX: c_int = NID_dhpublicnumber;
16pub const EVP_PKEY_EC: c_int = NID_X9_62_id_ecPublicKey;
17#[cfg(ossl111)]
18pub const EVP_PKEY_SM2: c_int = NID_sm2;
19#[cfg(any(ossl111, libressl370))]
20pub const EVP_PKEY_X25519: c_int = NID_X25519;
21#[cfg(any(ossl111, libressl370))]
22pub const EVP_PKEY_ED25519: c_int = NID_ED25519;
23#[cfg(ossl111)]
24pub const EVP_PKEY_X448: c_int = NID_X448;
25#[cfg(ossl111)]
26pub const EVP_PKEY_ED448: c_int = NID_ED448;
27pub const EVP_PKEY_HMAC: c_int = NID_hmac;
28pub const EVP_PKEY_CMAC: c_int = NID_cmac;
29#[cfg(ossl111)]
30pub const EVP_PKEY_POLY1305: c_int = NID_poly1305;
31#[cfg(any(ossl110, libressl360))]
32pub const EVP_PKEY_HKDF: c_int = NID_hkdf;
33
34#[cfg(ossl102)]
35pub const EVP_CIPHER_CTX_FLAG_WRAP_ALLOW: c_int = 0x1;
36
37pub const EVP_CTRL_GCM_SET_IVLEN: c_int = 0x9;
38pub const EVP_CTRL_GCM_GET_TAG: c_int = 0x10;
39pub const EVP_CTRL_GCM_SET_TAG: c_int = 0x11;
40
41pub unsafe fn EVP_get_digestbynid(type_: c_int) -> *const EVP_MD {
42 EVP_get_digestbyname(name:OBJ_nid2sn(nid:type_))
43}
44
45cfg_if! {
46 if #[cfg(ossl300)] {
47 #[inline]
48 pub unsafe fn EVP_MD_CTX_md(ctx: *const EVP_MD_CTX) -> *const EVP_MD {
49 EVP_MD_CTX_get0_md(ctx)
50 }
51
52 #[inline]
53 pub unsafe fn EVP_MD_CTX_get_size(ctx: *const EVP_MD_CTX) -> c_int {
54 EVP_MD_get_size(EVP_MD_CTX_get0_md(ctx))
55 }
56
57 #[inline]
58 pub unsafe fn EVP_MD_CTX_size(ctx: *const EVP_MD_CTX) -> c_int {
59 EVP_MD_CTX_get_size(ctx)
60 }
61
62 #[inline]
63 pub unsafe fn EVP_MD_block_size(md: *const EVP_MD) -> c_int {
64 EVP_MD_get_block_size(md)
65 }
66
67 #[inline]
68 pub unsafe fn EVP_MD_size(md: *const EVP_MD) -> c_int {
69 EVP_MD_get_size(md)
70 }
71
72 #[inline]
73 pub unsafe fn EVP_MD_type(md: *const EVP_MD) -> c_int {
74 EVP_MD_get_type(md)
75 }
76
77 #[inline]
78 pub unsafe fn EVP_CIPHER_key_length(cipher: *const EVP_CIPHER) -> c_int {
79 EVP_CIPHER_get_key_length(cipher)
80 }
81
82 #[inline]
83 pub unsafe fn EVP_CIPHER_block_size(cipher: *const EVP_CIPHER) -> c_int {
84 EVP_CIPHER_get_block_size(cipher)
85 }
86
87 #[inline]
88 pub unsafe fn EVP_CIPHER_iv_length(cipher: *const EVP_CIPHER) -> c_int {
89 EVP_CIPHER_get_iv_length(cipher)
90 }
91
92 #[inline]
93 pub unsafe fn EVP_CIPHER_nid(cipher: *const EVP_CIPHER) -> c_int {
94 EVP_CIPHER_get_nid(cipher)
95 }
96
97 #[inline]
98 pub unsafe fn EVP_CIPHER_CTX_block_size(ctx: *const EVP_CIPHER_CTX) -> c_int {
99 EVP_CIPHER_CTX_get_block_size(ctx)
100 }
101
102 #[inline]
103 pub unsafe fn EVP_CIPHER_CTX_key_length(ctx: *const EVP_CIPHER_CTX) -> c_int {
104 EVP_CIPHER_CTX_get_key_length(ctx)
105 }
106
107 #[inline]
108 pub unsafe fn EVP_CIPHER_CTX_iv_length(ctx: *const EVP_CIPHER_CTX) -> c_int {
109 EVP_CIPHER_CTX_get_iv_length(ctx)
110 }
111
112 #[inline]
113 pub unsafe fn EVP_CIPHER_CTX_num(ctx: *const EVP_CIPHER_CTX) -> c_int {
114 EVP_CIPHER_CTX_get_num(ctx)
115 }
116 } else {
117 pub unsafe fn EVP_MD_CTX_size(ctx: *const EVP_MD_CTX) -> c_int {
118 EVP_MD_size(EVP_MD_CTX_md(ctx))
119 }
120 }
121}
122#[cfg(not(ossl300))]
123#[inline]
124pub unsafe fn EVP_DigestSignUpdate(
125 ctx: *mut EVP_MD_CTX,
126 data: *const c_void,
127 dsize: size_t,
128) -> c_int {
129 EVP_DigestUpdate(ctx, data, dsize)
130}
131#[cfg(not(ossl300))]
132#[inline]
133pub unsafe fn EVP_DigestVerifyUpdate(
134 ctx: *mut EVP_MD_CTX,
135 data: *const c_void,
136 dsize: size_t,
137) -> c_int {
138 EVP_DigestUpdate(ctx, data, dsize)
139}
140#[cfg(ossl300)]
141#[inline]
142pub unsafe fn EVP_PKEY_size(pkey: *const EVP_PKEY) -> c_int {
143 EVP_PKEY_get_size(pkey)
144}
145
146cfg_if! {
147 if #[cfg(ossl300)] {
148 #[inline]
149 pub unsafe fn EVP_PKEY_id(pkey: *const EVP_PKEY) -> c_int {
150 EVP_PKEY_get_id(pkey)
151 }
152
153 #[inline]
154 pub unsafe fn EVP_PKEY_bits(pkey: *const EVP_PKEY) -> c_int {
155 EVP_PKEY_get_bits(pkey)
156 }
157
158 #[inline]
159 pub unsafe fn EVP_PKEY_security_bits(pkey: *const EVP_PKEY) -> c_int {
160 EVP_PKEY_get_security_bits(pkey)
161 }
162 }
163}
164
165pub const EVP_PKEY_OP_KEYGEN: c_int = 1 << 2;
166cfg_if! {
167 if #[cfg(ossl300)] {
168 pub const EVP_PKEY_OP_SIGN: c_int = 1 << 4;
169 pub const EVP_PKEY_OP_VERIFY: c_int = 1 << 5;
170 pub const EVP_PKEY_OP_VERIFYRECOVER: c_int = 1 << 6;
171 pub const EVP_PKEY_OP_SIGNCTX: c_int = 1 << 7;
172 pub const EVP_PKEY_OP_VERIFYCTX: c_int = 1 << 8;
173 pub const EVP_PKEY_OP_ENCRYPT: c_int = 1 << 9;
174 pub const EVP_PKEY_OP_DECRYPT: c_int = 1 << 10;
175 pub const EVP_PKEY_OP_DERIVE: c_int = 1 << 11;
176 } else {
177 pub const EVP_PKEY_OP_SIGN: c_int = 1 << 3;
178 pub const EVP_PKEY_OP_VERIFY: c_int = 1 << 4;
179 pub const EVP_PKEY_OP_VERIFYRECOVER: c_int = 1 << 5;
180 pub const EVP_PKEY_OP_SIGNCTX: c_int = 1 << 6;
181 pub const EVP_PKEY_OP_VERIFYCTX: c_int = 1 << 7;
182 pub const EVP_PKEY_OP_ENCRYPT: c_int = 1 << 8;
183 pub const EVP_PKEY_OP_DECRYPT: c_int = 1 << 9;
184 pub const EVP_PKEY_OP_DERIVE: c_int = 1 << 10;
185 }
186}
187
188pub const EVP_PKEY_OP_TYPE_SIG: c_int = EVP_PKEY_OP_SIGN
189 | EVP_PKEY_OP_VERIFY
190 | EVP_PKEY_OP_VERIFYRECOVER
191 | EVP_PKEY_OP_SIGNCTX
192 | EVP_PKEY_OP_VERIFYCTX;
193
194pub const EVP_PKEY_OP_TYPE_CRYPT: c_int = EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT;
195
196pub const EVP_PKEY_CTRL_MD: c_int = 1;
197
198pub const EVP_PKEY_CTRL_SET_MAC_KEY: c_int = 6;
199
200pub const EVP_PKEY_CTRL_CIPHER: c_int = 12;
201
202pub const EVP_PKEY_ALG_CTRL: c_int = 0x1000;
203
204#[cfg(any(ossl111, libressl360))]
205pub const EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND: c_int = 0;
206
207#[cfg(any(ossl111, libressl360))]
208pub const EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY: c_int = 1;
209
210#[cfg(any(ossl111, libressl360))]
211pub const EVP_PKEY_HKDEF_MODE_EXPAND_ONLY: c_int = 2;
212
213#[cfg(any(ossl110, libressl360))]
214pub const EVP_PKEY_CTRL_HKDF_MD: c_int = EVP_PKEY_ALG_CTRL + 3;
215
216#[cfg(any(ossl110, libressl360))]
217pub const EVP_PKEY_CTRL_HKDF_SALT: c_int = EVP_PKEY_ALG_CTRL + 4;
218
219#[cfg(any(ossl110, libressl360))]
220pub const EVP_PKEY_CTRL_HKDF_KEY: c_int = EVP_PKEY_ALG_CTRL + 5;
221
222#[cfg(any(ossl110, libressl360))]
223pub const EVP_PKEY_CTRL_HKDF_INFO: c_int = EVP_PKEY_ALG_CTRL + 6;
224
225#[cfg(any(ossl111, libressl360))]
226pub const EVP_PKEY_CTRL_HKDF_MODE: c_int = EVP_PKEY_ALG_CTRL + 7;
227
228#[cfg(any(all(ossl111, not(ossl300)), libressl360))]
229pub unsafe fn EVP_PKEY_CTX_set_hkdf_mode(ctx: *mut EVP_PKEY_CTX, mode: c_int) -> c_int {
230 EVP_PKEY_CTX_ctrl(
231 ctx,
232 -1,
233 EVP_PKEY_OP_DERIVE,
234 EVP_PKEY_CTRL_HKDF_MODE,
235 mode,
236 std::ptr::null_mut(),
237 )
238}
239
240#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
241pub unsafe fn EVP_PKEY_CTX_set_hkdf_md(ctx: *mut EVP_PKEY_CTX, md: *const EVP_MD) -> c_int {
242 EVP_PKEY_CTX_ctrl(
243 ctx,
244 -1,
245 EVP_PKEY_OP_DERIVE,
246 EVP_PKEY_CTRL_HKDF_MD,
247 0,
248 md as *mut c_void,
249 )
250}
251
252#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
253pub unsafe fn EVP_PKEY_CTX_set1_hkdf_salt(
254 ctx: *mut EVP_PKEY_CTX,
255 salt: *const u8,
256 saltlen: c_int,
257) -> c_int {
258 EVP_PKEY_CTX_ctrl(
259 ctx,
260 -1,
261 EVP_PKEY_OP_DERIVE,
262 EVP_PKEY_CTRL_HKDF_SALT,
263 saltlen,
264 salt as *mut c_void,
265 )
266}
267
268#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
269pub unsafe fn EVP_PKEY_CTX_set1_hkdf_key(
270 ctx: *mut EVP_PKEY_CTX,
271 key: *const u8,
272 keylen: c_int,
273) -> c_int {
274 EVP_PKEY_CTX_ctrl(
275 ctx,
276 -1,
277 EVP_PKEY_OP_DERIVE,
278 EVP_PKEY_CTRL_HKDF_KEY,
279 keylen,
280 key as *mut c_void,
281 )
282}
283
284#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
285pub unsafe fn EVP_PKEY_CTX_add1_hkdf_info(
286 ctx: *mut EVP_PKEY_CTX,
287 info: *const u8,
288 infolen: c_int,
289) -> c_int {
290 EVP_PKEY_CTX_ctrl(
291 ctx,
292 -1,
293 EVP_PKEY_OP_DERIVE,
294 EVP_PKEY_CTRL_HKDF_INFO,
295 infolen,
296 info as *mut c_void,
297 )
298}
299
300#[cfg(all(not(ossl300), not(boringssl)))]
301pub unsafe fn EVP_PKEY_CTX_set_signature_md(cxt: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
302 EVP_PKEY_CTX_ctrl(
303 cxt,
304 -1,
305 EVP_PKEY_OP_TYPE_SIG,
306 EVP_PKEY_CTRL_MD,
307 0,
308 md as *mut c_void,
309 )
310}
311
312pub unsafe fn EVP_PKEY_assign_RSA(pkey: *mut EVP_PKEY, rsa: *mut RSA) -> c_int {
313 EVP_PKEY_assign(pkey, EVP_PKEY_RSA, key:rsa as *mut c_void)
314}
315
316pub unsafe fn EVP_PKEY_assign_DSA(pkey: *mut EVP_PKEY, dsa: *mut DSA) -> c_int {
317 EVP_PKEY_assign(pkey, EVP_PKEY_DSA, key:dsa as *mut c_void)
318}
319
320pub unsafe fn EVP_PKEY_assign_DH(pkey: *mut EVP_PKEY, dh: *mut DH) -> c_int {
321 EVP_PKEY_assign(pkey, EVP_PKEY_DH, key:dh as *mut c_void)
322}
323
324pub unsafe fn EVP_PKEY_assign_EC_KEY(pkey: *mut EVP_PKEY, ec_key: *mut EC_KEY) -> c_int {
325 EVP_PKEY_assign(pkey, EVP_PKEY_EC, ec_key as *mut c_void)
326}
327