Skip to content

Commit

Permalink
base64_simd and mimalloc optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
GPeaky committed Oct 8, 2024
1 parent 436285e commit b769e49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ memchr = "2"
ring = "0.17"
prost = "0.13"
tracing = "0.1"
base64 = "0.22"
ntex-cors = "2"
dotenvy = "0.15"
sailfish = "0.9"
mimalloc = "0.1"
serde_trim = "1"
jsonwebtoken = "9"
quick_cache = "0.6"
base64-simd = "0.8"
postgres-derive = "0.4"
deadpool-postgres = "0.14"
tokio = { version = "1", features = ["full"] }
Expand All @@ -40,6 +39,11 @@ dashmap = { version = "6", features = ["inline", "raw-api"] }
postgres-types = { version = "0.2", features = ["with-chrono-0_4"] }
parking_lot = { version = "0.12", features = ["arc_lock", "nightly"] }
garde = { version = "0.20", features = ["derive", "email", "email-idna"] }
mimalloc = { version = "0.1", features = [
"extended",
"local_dynamic_tls",
"override",
] }
tracing-subscriber = { version = "0.3", features = [
"parking_lot",
"env-filter",
Expand Down
6 changes: 3 additions & 3 deletions src/utils/password_hash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use base64::{engine::general_purpose::STANDARD, Engine};
use base64_simd::{Out, STANDARD};
use ring::{
pbkdf2,
rand::{SecureRandom, SystemRandom},
Expand Down Expand Up @@ -46,7 +46,7 @@ impl PasswordHasher {
hashed_password[..PASS_SALT_LEN].copy_from_slice(&salt);
hashed_password[PASS_SALT_LEN..].copy_from_slice(&hash);

Ok(STANDARD.encode(hashed_password))
Ok(STANDARD.encode_to_string(hashed_password))
})
.await
.unwrap_or_else(|_| Err(CommonError::InternalServerError)?)
Expand All @@ -59,7 +59,7 @@ impl PasswordHasher {
let mut combined = [0u8; PASS_SALT_LEN + PASS_CREDENTIAL_LEN];

STANDARD
.decode_slice_unchecked(encoded, &mut combined) // Unchecked because the size of the hash is static
.decode(encoded.as_bytes(), Out::from_slice(&mut combined)) // Unchecked because the size of the hash is static
.map_err(|_| CommonError::HashingFailed)?;

let (salt, hash) = unsafe { combined.split_at_unchecked(PASS_SALT_LEN) };
Expand Down

0 comments on commit b769e49

Please sign in to comment.