Skip to content

Commit

Permalink
scram: generate random nonce with one call (#182)
Browse files Browse the repository at this point in the history
This has two benefits:
1. takes 1 lock instead of 18
2. generates multiple bytes per internal random invocation
  • Loading branch information
serprex authored Jun 1, 2024
1 parent 9bf611e commit 2f4ee5f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
6 changes: 1 addition & 5 deletions examples/scram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ impl SimpleQueryHandler for DummyProcessor {
}

pub fn random_salt() -> Vec<u8> {
let mut buf = vec![0u8; 10];
for v in buf.iter_mut() {
*v = rand::random::<u8>();
}
buf
Vec::from(rand::random::<[u8; 10]>())
}

const ITERATIONS: usize = 4096;
Expand Down
7 changes: 1 addition & 6 deletions src/api/auth/scram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ pub fn gen_salted_password(password: &str, salt: &[u8], iters: usize) -> Vec<u8>
}

pub fn random_nonce() -> String {
let mut buf = [0u8; 18];
for v in buf.iter_mut() {
*v = rand::random::<u8>();
}

STANDARD.encode(buf)
STANDARD.encode(rand::random::<[u8; 18]>())
}

impl<A, P> SASLScramAuthStartupHandler<A, P> {
Expand Down

0 comments on commit 2f4ee5f

Please sign in to comment.