Skip to content

Commit

Permalink
set a threadpool number
Browse files Browse the repository at this point in the history
  • Loading branch information
reaperhulk committed Oct 29, 2024
1 parent 5a6a9fc commit 5942c95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rust/src/backend/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ impl Argon2id {
) -> CryptographyResult<Self> {
cfg_if::cfg_if! {
if #[cfg(not(CRYPTOGRAPHY_OPENSSL_320_OR_GREATER))] {
_ = py;
_ = salt;
_ = length;
_ = iterations;
_ = lanes;
_ = memory_cost;
Expand Down Expand Up @@ -274,7 +276,7 @@ impl Argon2id {
}
}

#[cfg(not(CRYPTOGRAPHY_IS_LIBRESSL))]
#[cfg(CRYPTOGRAPHY_OPENSSL_320_OR_GREATER)]
fn derive<'p>(
&mut self,
py: pyo3::Python<'p>,
Expand All @@ -284,7 +286,6 @@ impl Argon2id {
return Err(exceptions::already_finalized_error());
}
self.used = true;

Ok(pyo3::types::PyBytes::new_bound_with(
py,
self.length,
Expand All @@ -306,7 +307,7 @@ impl Argon2id {
)?)
}

#[cfg(not(CRYPTOGRAPHY_IS_LIBRESSL))]
#[cfg(CRYPTOGRAPHY_OPENSSL_320_OR_GREATER)]
fn verify(
&mut self,
py: pyo3::Python<'_>,
Expand Down
11 changes: 11 additions & 0 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ mod _rust {
openssl_mod.add("_legacy_provider_loaded", false)?;
}
}
cfg_if::cfg_if! {
if #[cfg(CRYPTOGRAPHY_OPENSSL_320_OR_GREATER)] {
use std::ptr;
if let Ok(available) = std::thread::available_parallelism() {
// SAFETY: This sets a libctx provider limit, but we always use the same libctx by passing NULL.
unsafe {
openssl_sys::OSSL_set_max_threads(ptr::null_mut(), available.get() as u64);
}
};
}
}

Ok(())
}
Expand Down

0 comments on commit 5942c95

Please sign in to comment.