From 29e95a958b0b8c767f9c1fca9d8fbd5777cd90c4 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 25 Jun 2022 12:19:05 -0400 Subject: Release the GIL during expensive crypto ops (#355) --- src/_bcrypt/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_bcrypt/src/lib.rs b/src/_bcrypt/src/lib.rs index ac1897f..8e61c3d 100644 --- a/src/_bcrypt/src/lib.rs +++ b/src/_bcrypt/src/lib.rs @@ -49,7 +49,7 @@ fn hashpass<'p>( .try_into() .map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?; - let hashed = bcrypt::hash_with_salt(password, cost, raw_salt).unwrap(); + let hashed = py.allow_threads(|| bcrypt::hash_with_salt(password, cost, raw_salt).unwrap()); Ok(pyo3::types::PyBytes::new( py, hashed.format_for_version(version).as_bytes(), @@ -65,7 +65,9 @@ fn pbkdf<'p>( desired_key_bytes: usize, ) -> pyo3::PyResult<&'p pyo3::types::PyBytes> { pyo3::types::PyBytes::new_with(py, desired_key_bytes, |output| { - bcrypt_pbkdf::bcrypt_pbkdf(password, salt, rounds, output).unwrap(); + py.allow_threads(|| { + bcrypt_pbkdf::bcrypt_pbkdf(password, salt, rounds, output).unwrap(); + }); Ok(()) }) } -- cgit v1.2.1