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