Skip to content
Merged
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
20 changes: 17 additions & 3 deletions srp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ use crate::utils::{
/// SRP client state before handshake with the server.
pub struct SrpClient<'a, D: Digest> {
params: &'a SrpGroup,
no_user_in_x: bool,
d: PhantomData<D>,
}

Expand All @@ -138,6 +139,16 @@ impl<'a, D: Digest> SrpClient<'a, D> {
pub const fn new(params: &'a SrpGroup) -> Self {
Self {
params,
no_user_in_x: false,
d: PhantomData,
}
}

#[must_use]
pub const fn new_with_options(params: &'a SrpGroup, no_user_in_x: bool) -> Self {
Self {
params,
no_user_in_x,
d: PhantomData,
}
}
Expand Down Expand Up @@ -197,7 +208,8 @@ impl<'a, D: Digest> SrpClient<'a, D> {
/// Get password verifier (v in RFC5054) for user registration on the server.
#[must_use]
pub fn compute_verifier(&self, username: &[u8], password: &[u8], salt: &[u8]) -> Vec<u8> {
let identity_hash = Self::compute_identity_hash(username, password);
let identity_username = if self.no_user_in_x { &[] } else { username };
let identity_hash = Self::compute_identity_hash(identity_username, password);
let x = Self::compute_x(identity_hash.as_slice(), salt);
self.compute_v(&x).to_bytes_be()
}
Expand Down Expand Up @@ -232,7 +244,8 @@ impl<'a, D: Digest> SrpClient<'a, D> {

let u = compute_u::<D>(&a_pub.to_bytes_be(), &b_pub.to_bytes_be());
let k = compute_k::<D>(self.params);
let identity_hash = Self::compute_identity_hash(username, password);
let identity_username = if self.no_user_in_x { &[] } else { username };
let identity_hash = Self::compute_identity_hash(identity_username, password);
let x = Self::compute_x(identity_hash.as_slice(), salt);

let key = self.compute_premaster_secret(&b_pub, &k, &x, &a, &u);
Expand Down Expand Up @@ -275,7 +288,8 @@ impl<'a, D: Digest> SrpClient<'a, D> {

let u = compute_u::<D>(&a_pub.to_bytes_be(), &b_pub.to_bytes_be());
let k = compute_k::<D>(self.params);
let identity_hash = Self::compute_identity_hash(username, password);
let identity_username = if self.no_user_in_x { &[] } else { username };
let identity_hash = Self::compute_identity_hash(identity_username, password);
let x = Self::compute_x(identity_hash.as_slice(), salt);

let premaster_secret = self
Expand Down