From 826f2a0a82e57ccd16941f75daa5e7bc24b5e89e Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 1 Sep 2024 06:56:40 -0700 Subject: [PATCH] use c_char --- openssl/src/argon2.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/openssl/src/argon2.rs b/openssl/src/argon2.rs index f28c17794..836b45dce 100644 --- a/openssl/src/argon2.rs +++ b/openssl/src/argon2.rs @@ -1,4 +1,4 @@ -use std::ffi::{c_void, CStr}; +use std::ffi::{c_char, c_void}; use std::mem::MaybeUninit; use std::ptr; @@ -49,33 +49,36 @@ pub fn argon2id( core::array::from_fn(|_| MaybeUninit::::zeroed().assume_init()); let mut idx = 0; params[idx] = ffi::OSSL_PARAM_construct_octet_string( - b"pass\0".as_ptr() as *const i8, + b"pass\0".as_ptr() as *const c_char, pass.as_ptr() as *mut c_void, pass.len(), ); idx += 1; params[idx] = ffi::OSSL_PARAM_construct_octet_string( - b"salt\0".as_ptr() as *const i8, + b"salt\0".as_ptr() as *const c_char, salt.as_ptr() as *mut c_void, salt.len(), ); idx += 1; params[idx] = - ffi::OSSL_PARAM_construct_uint(b"threads\0".as_ptr() as *const i8, &mut threads); + ffi::OSSL_PARAM_construct_uint(b"threads\0".as_ptr() as *const c_char, &mut threads); idx += 1; - params[idx] = ffi::OSSL_PARAM_construct_uint(b"lanes\0".as_ptr() as *const i8, &mut lanes); + params[idx] = + ffi::OSSL_PARAM_construct_uint(b"lanes\0".as_ptr() as *const c_char, &mut lanes); idx += 1; params[idx] = - ffi::OSSL_PARAM_construct_uint(b"memcost\0".as_ptr() as *const i8, &mut memcost); + ffi::OSSL_PARAM_construct_uint(b"memcost\0".as_ptr() as *const c_char, &mut memcost); idx += 1; - params[idx] = ffi::OSSL_PARAM_construct_uint(b"iter\0".as_ptr() as *const i8, &mut iter); + params[idx] = + ffi::OSSL_PARAM_construct_uint(b"iter\0".as_ptr() as *const c_char, &mut iter); idx += 1; let mut size = out.len() as u32; - params[idx] = ffi::OSSL_PARAM_construct_uint(b"size\0".as_ptr() as *const i8, &mut size); + params[idx] = + ffi::OSSL_PARAM_construct_uint(b"size\0".as_ptr() as *const c_char, &mut size); idx += 1; if let Some(ad) = ad { params[idx] = ffi::OSSL_PARAM_construct_octet_string( - b"ad\0".as_ptr() as *const i8, + b"ad\0".as_ptr() as *const c_char, ad.as_ptr() as *mut c_void, ad.len(), ); @@ -83,7 +86,7 @@ pub fn argon2id( } if let Some(secret) = secret { params[idx] = ffi::OSSL_PARAM_construct_octet_string( - b"secret\0".as_ptr() as *const i8, + b"secret\0".as_ptr() as *const c_char, secret.as_ptr() as *mut c_void, secret.len(), ); @@ -91,10 +94,9 @@ pub fn argon2id( } params[idx] = ffi::OSSL_PARAM_construct_end(); - let argon2id = CStr::from_bytes_with_nul(b"ARGON2ID\0").unwrap(); let argon2_p = cvt_p(ffi::EVP_KDF_fetch( ptr::null_mut(), - argon2id.as_ptr(), + b"ARGON2ID\0".as_ptr() as *const c_char, ptr::null(), ))?; let argon2 = EvpKdf(argon2_p);