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