Skip to content

Commit 252e743

Browse files
authored
Merge pull request #2295 from reaperhulk/argon2-libctx
add libctx arg to argon2id
2 parents 01fe6f0 + 5ea9a12 commit 252e743

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

openssl/src/kdf.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ cfg_if::cfg_if! {
2727
use std::ffi::{c_char, c_void};
2828
use std::mem::MaybeUninit;
2929
use std::ptr;
30+
use foreign_types::ForeignTypeRef;
3031
use crate::{cvt, cvt_p};
32+
use crate::lib_ctx::LibCtxRef;
3133
use crate::error::ErrorStack;
3234

3335
/// Derives a key using the argon2id algorithm.
@@ -38,6 +40,7 @@ cfg_if::cfg_if! {
3840
/// Requires OpenSSL 3.2.0 or newer.
3941
#[allow(clippy::too_many_arguments)]
4042
pub fn argon2id(
43+
ctx: Option<&LibCtxRef>,
4144
pass: &[u8],
4245
salt: &[u8],
4346
ad: Option<&[u8]>,
@@ -49,6 +52,8 @@ cfg_if::cfg_if! {
4952
) -> Result<(), ErrorStack> {
5053
unsafe {
5154
ffi::init();
55+
let libctx = ctx.map_or(ptr::null_mut(), ForeignTypeRef::as_ptr);
56+
5257
let mut threads = 1;
5358
let mut params: [ffi::OSSL_PARAM; 10] =
5459
core::array::from_fn(|_| MaybeUninit::<ffi::OSSL_PARAM>::zeroed().assume_init());
@@ -100,7 +105,7 @@ cfg_if::cfg_if! {
100105
params[idx] = ffi::OSSL_PARAM_construct_end();
101106

102107
let argon2 = EvpKdf(cvt_p(ffi::EVP_KDF_fetch(
103-
ptr::null_mut(),
108+
libctx,
104109
b"ARGON2ID\0".as_ptr() as *const c_char,
105110
ptr::null(),
106111
))?);
@@ -132,6 +137,7 @@ mod tests {
132137

133138
let mut actual = [0u8; 32];
134139
super::argon2id(
140+
None,
135141
&pass,
136142
&salt,
137143
Some(&ad),
@@ -154,7 +160,7 @@ mod tests {
154160
let expected = "0a34f1abde67086c82e785eaf17c68382259a264f4e61b91cd2763cb75ac189a";
155161

156162
let mut actual = [0u8; 32];
157-
super::argon2id(pass, &salt, None, None, 3, 4, 32, &mut actual).unwrap();
163+
super::argon2id(None, pass, &salt, None, None, 3, 4, 32, &mut actual).unwrap();
158164
assert_eq!(hex::encode(&actual[..]), expected);
159165
}
160166
}

0 commit comments

Comments
 (0)