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