Coverage Report

Created: 2025-10-29 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/openssl-sys-0.9.98/src/evp.rs
Line
Count
Source
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
#[cfg(any(ossl111, libressl310, boringssl))]
11
pub const EVP_PKEY_RSA_PSS: c_int = NID_rsassaPss;
12
pub const EVP_PKEY_DSA: c_int = NID_dsa;
13
pub const EVP_PKEY_DH: c_int = NID_dhKeyAgreement;
14
#[cfg(ossl110)]
15
pub const EVP_PKEY_DHX: c_int = NID_dhpublicnumber;
16
pub const EVP_PKEY_EC: c_int = NID_X9_62_id_ecPublicKey;
17
#[cfg(ossl111)]
18
pub const EVP_PKEY_SM2: c_int = NID_sm2;
19
#[cfg(any(ossl111, libressl370))]
20
pub const EVP_PKEY_X25519: c_int = NID_X25519;
21
#[cfg(any(ossl111, libressl370))]
22
pub const EVP_PKEY_ED25519: c_int = NID_ED25519;
23
#[cfg(ossl111)]
24
pub const EVP_PKEY_X448: c_int = NID_X448;
25
#[cfg(ossl111)]
26
pub const EVP_PKEY_ED448: c_int = NID_ED448;
27
pub const EVP_PKEY_HMAC: c_int = NID_hmac;
28
pub const EVP_PKEY_CMAC: c_int = NID_cmac;
29
#[cfg(ossl111)]
30
pub const EVP_PKEY_POLY1305: c_int = NID_poly1305;
31
#[cfg(any(ossl110, libressl360))]
32
pub const EVP_PKEY_HKDF: c_int = NID_hkdf;
33
34
#[cfg(ossl102)]
35
pub const EVP_CIPHER_CTX_FLAG_WRAP_ALLOW: c_int = 0x1;
36
37
pub const EVP_CTRL_GCM_SET_IVLEN: c_int = 0x9;
38
pub const EVP_CTRL_GCM_GET_TAG: c_int = 0x10;
39
pub const EVP_CTRL_GCM_SET_TAG: c_int = 0x11;
40
41
0
pub unsafe fn EVP_get_digestbynid(type_: c_int) -> *const EVP_MD {
42
0
    EVP_get_digestbyname(OBJ_nid2sn(type_))
43
0
}
44
45
cfg_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
0
        pub unsafe fn EVP_MD_CTX_size(ctx: *const EVP_MD_CTX) -> c_int {
118
0
            EVP_MD_size(EVP_MD_CTX_md(ctx))
119
0
        }
120
    }
121
}
122
#[cfg(not(ossl300))]
123
#[inline]
124
0
pub unsafe fn EVP_DigestSignUpdate(
125
0
    ctx: *mut EVP_MD_CTX,
126
0
    data: *const c_void,
127
0
    dsize: size_t,
128
0
) -> c_int {
129
0
    EVP_DigestUpdate(ctx, data, dsize)
130
0
}
131
#[cfg(not(ossl300))]
132
#[inline]
133
0
pub unsafe fn EVP_DigestVerifyUpdate(
134
0
    ctx: *mut EVP_MD_CTX,
135
0
    data: *const c_void,
136
0
    dsize: size_t,
137
0
) -> c_int {
138
0
    EVP_DigestUpdate(ctx, data, dsize)
139
0
}
140
#[cfg(ossl300)]
141
#[inline]
142
pub unsafe fn EVP_PKEY_size(pkey: *const EVP_PKEY) -> c_int {
143
    EVP_PKEY_get_size(pkey)
144
}
145
146
cfg_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
165
pub const EVP_PKEY_OP_KEYGEN: c_int = 1 << 2;
166
cfg_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
188
pub 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
194
pub const EVP_PKEY_OP_TYPE_CRYPT: c_int = EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT;
195
196
pub const EVP_PKEY_CTRL_MD: c_int = 1;
197
198
pub const EVP_PKEY_CTRL_SET_MAC_KEY: c_int = 6;
199
200
pub const EVP_PKEY_CTRL_CIPHER: c_int = 12;
201
202
pub const EVP_PKEY_ALG_CTRL: c_int = 0x1000;
203
204
#[cfg(any(ossl111, libressl360))]
205
pub const EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND: c_int = 0;
206
207
#[cfg(any(ossl111, libressl360))]
208
pub const EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY: c_int = 1;
209
210
#[cfg(any(ossl111, libressl360))]
211
pub const EVP_PKEY_HKDEF_MODE_EXPAND_ONLY: c_int = 2;
212
213
#[cfg(any(ossl110, libressl360))]
214
pub const EVP_PKEY_CTRL_HKDF_MD: c_int = EVP_PKEY_ALG_CTRL + 3;
215
216
#[cfg(any(ossl110, libressl360))]
217
pub const EVP_PKEY_CTRL_HKDF_SALT: c_int = EVP_PKEY_ALG_CTRL + 4;
218
219
#[cfg(any(ossl110, libressl360))]
220
pub const EVP_PKEY_CTRL_HKDF_KEY: c_int = EVP_PKEY_ALG_CTRL + 5;
221
222
#[cfg(any(ossl110, libressl360))]
223
pub const EVP_PKEY_CTRL_HKDF_INFO: c_int = EVP_PKEY_ALG_CTRL + 6;
224
225
#[cfg(any(ossl111, libressl360))]
226
pub const EVP_PKEY_CTRL_HKDF_MODE: c_int = EVP_PKEY_ALG_CTRL + 7;
227
228
#[cfg(any(all(ossl111, not(ossl300)), libressl360))]
229
0
pub unsafe fn EVP_PKEY_CTX_set_hkdf_mode(ctx: *mut EVP_PKEY_CTX, mode: c_int) -> c_int {
230
0
    EVP_PKEY_CTX_ctrl(
231
0
        ctx,
232
        -1,
233
        EVP_PKEY_OP_DERIVE,
234
        EVP_PKEY_CTRL_HKDF_MODE,
235
0
        mode,
236
0
        std::ptr::null_mut(),
237
    )
238
0
}
239
240
#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
241
0
pub unsafe fn EVP_PKEY_CTX_set_hkdf_md(ctx: *mut EVP_PKEY_CTX, md: *const EVP_MD) -> c_int {
242
0
    EVP_PKEY_CTX_ctrl(
243
0
        ctx,
244
        -1,
245
        EVP_PKEY_OP_DERIVE,
246
        EVP_PKEY_CTRL_HKDF_MD,
247
        0,
248
0
        md as *mut c_void,
249
    )
250
0
}
251
252
#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
253
0
pub unsafe fn EVP_PKEY_CTX_set1_hkdf_salt(
254
0
    ctx: *mut EVP_PKEY_CTX,
255
0
    salt: *const u8,
256
0
    saltlen: c_int,
257
0
) -> c_int {
258
0
    EVP_PKEY_CTX_ctrl(
259
0
        ctx,
260
        -1,
261
        EVP_PKEY_OP_DERIVE,
262
        EVP_PKEY_CTRL_HKDF_SALT,
263
0
        saltlen,
264
0
        salt as *mut c_void,
265
    )
266
0
}
267
268
#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
269
0
pub unsafe fn EVP_PKEY_CTX_set1_hkdf_key(
270
0
    ctx: *mut EVP_PKEY_CTX,
271
0
    key: *const u8,
272
0
    keylen: c_int,
273
0
) -> c_int {
274
0
    EVP_PKEY_CTX_ctrl(
275
0
        ctx,
276
        -1,
277
        EVP_PKEY_OP_DERIVE,
278
        EVP_PKEY_CTRL_HKDF_KEY,
279
0
        keylen,
280
0
        key as *mut c_void,
281
    )
282
0
}
283
284
#[cfg(any(all(ossl110, not(ossl300)), libressl360))]
285
0
pub unsafe fn EVP_PKEY_CTX_add1_hkdf_info(
286
0
    ctx: *mut EVP_PKEY_CTX,
287
0
    info: *const u8,
288
0
    infolen: c_int,
289
0
) -> c_int {
290
0
    EVP_PKEY_CTX_ctrl(
291
0
        ctx,
292
        -1,
293
        EVP_PKEY_OP_DERIVE,
294
        EVP_PKEY_CTRL_HKDF_INFO,
295
0
        infolen,
296
0
        info as *mut c_void,
297
    )
298
0
}
299
300
#[cfg(all(not(ossl300), not(boringssl)))]
301
0
pub unsafe fn EVP_PKEY_CTX_set_signature_md(cxt: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
302
0
    EVP_PKEY_CTX_ctrl(
303
0
        cxt,
304
        -1,
305
        EVP_PKEY_OP_TYPE_SIG,
306
        EVP_PKEY_CTRL_MD,
307
        0,
308
0
        md as *mut c_void,
309
    )
310
0
}
311
312
0
pub unsafe fn EVP_PKEY_assign_RSA(pkey: *mut EVP_PKEY, rsa: *mut RSA) -> c_int {
313
0
    EVP_PKEY_assign(pkey, EVP_PKEY_RSA, rsa as *mut c_void)
314
0
}
315
316
0
pub unsafe fn EVP_PKEY_assign_DSA(pkey: *mut EVP_PKEY, dsa: *mut DSA) -> c_int {
317
0
    EVP_PKEY_assign(pkey, EVP_PKEY_DSA, dsa as *mut c_void)
318
0
}
319
320
0
pub unsafe fn EVP_PKEY_assign_DH(pkey: *mut EVP_PKEY, dh: *mut DH) -> c_int {
321
0
    EVP_PKEY_assign(pkey, EVP_PKEY_DH, dh as *mut c_void)
322
0
}
323
324
0
pub unsafe fn EVP_PKEY_assign_EC_KEY(pkey: *mut EVP_PKEY, ec_key: *mut EC_KEY) -> c_int {
325
0
    EVP_PKEY_assign(pkey, EVP_PKEY_EC, ec_key as *mut c_void)
326
0
}