Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions openssl/src/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ cfg_if::cfg_if! {
use crate::error::ErrorStack;
use crate::ossl_param::OsslParamBuilder;

// Safety: these all have null terminators.
// We cen remove these CStr::from_bytes_with_nul_unchecked calls
// when we upgrade to Rust 1.77+ with literal c"" syntax.
cstr_const!(OSSL_KDF_PARAM_PASSWORD, b"pass\0");
cstr_const!(OSSL_KDF_PARAM_SALT, b"salt\0");
cstr_const!(OSSL_KDF_PARAM_SECRET, b"secret\0");
cstr_const!(OSSL_KDF_PARAM_ITER, b"iter\0");
cstr_const!(OSSL_KDF_PARAM_SIZE, b"size\0");
cstr_const!(OSSL_KDF_PARAM_THREADS, b"threads\0");
cstr_const!(OSSL_KDF_PARAM_ARGON2_AD, b"ad\0");
cstr_const!(OSSL_KDF_PARAM_ARGON2_LANES, b"lanes\0");
cstr_const!(OSSL_KDF_PARAM_ARGON2_MEMCOST, b"memcost\0");

const OSSL_KDF_PARAM_PASSWORD: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"pass\0") };
const OSSL_KDF_PARAM_SALT: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"salt\0") };
const OSSL_KDF_PARAM_SECRET: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"secret\0") };
const OSSL_KDF_PARAM_ITER: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"iter\0") };
const OSSL_KDF_PARAM_SIZE: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"size\0") };
const OSSL_KDF_PARAM_THREADS: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"threads\0") };
const OSSL_KDF_PARAM_ARGON2_AD: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"ad\0") };
const OSSL_KDF_PARAM_ARGON2_LANES: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"lanes\0") };
const OSSL_KDF_PARAM_ARGON2_MEMCOST: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"memcost\0") };
cstr_const!(KDF_ARGON2D, b"ARGON2D\0");
cstr_const!(KDF_ARGON2I, b"ARGON2I\0");
cstr_const!(KDF_ARGON2ID, b"ARGON2ID\0");

#[allow(clippy::too_many_arguments)]
pub fn argon2d(
Expand All @@ -60,7 +60,7 @@ cfg_if::cfg_if! {
memcost: u32,
out: &mut [u8],
) -> Result<(), ErrorStack> {
return argon2_helper(CStr::from_bytes_with_nul(b"ARGON2D\0").unwrap(), ctx, pass, salt, ad, secret, iter, lanes, memcost, out);
argon2_helper(KDF_ARGON2D, ctx, pass, salt, ad, secret, iter, lanes, memcost, out)
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -75,7 +75,7 @@ cfg_if::cfg_if! {
memcost: u32,
out: &mut [u8],
) -> Result<(), ErrorStack> {
return argon2_helper(CStr::from_bytes_with_nul(b"ARGON2I\0").unwrap(), ctx, pass, salt, ad, secret, iter, lanes, memcost, out);
argon2_helper(KDF_ARGON2I, ctx, pass, salt, ad, secret, iter, lanes, memcost, out)
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -90,7 +90,7 @@ cfg_if::cfg_if! {
memcost: u32,
out: &mut [u8],
) -> Result<(), ErrorStack> {
return argon2_helper(CStr::from_bytes_with_nul(b"ARGON2ID\0").unwrap(), ctx, pass, salt, ad, secret, iter, lanes, memcost, out);
argon2_helper(KDF_ARGON2ID, ctx, pass, salt, ad, secret, iter, lanes, memcost, out)
}

/// Derives a key using the argon2* algorithms.
Expand Down
2 changes: 2 additions & 0 deletions openssl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub mod nid;
#[cfg(not(osslconf = "OPENSSL_NO_OCSP"))]
pub mod ocsp;
#[cfg(ossl300)]
mod ossl_encdec;
#[cfg(ossl300)]
mod ossl_param;
pub mod pkcs12;
pub mod pkcs5;
Expand Down
11 changes: 11 additions & 0 deletions openssl/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,14 @@ macro_rules! generic_foreign_type_and_impl_send_sync {
unsafe impl<T> Sync for $borrowed<T>{}
};
}

#[cfg_attr(not(ossl300), allow(unused_macros))]
macro_rules! cstr_const {
// Safety: these all have null terminators.
// We cen remove these CStr::from_bytes_with_nul_unchecked calls
// when we upgrade to Rust 1.77+ with literal c"" syntax.
($vis:vis $name:ident, $key:literal) => {
#[allow(dead_code)]
$vis const $name: &std::ffi::CStr = unsafe { std::ffi::CStr::from_bytes_with_nul_unchecked($key) };
}
}
Loading