diff options
author | Brian Warner <warner@lothar.com> | 2018-10-16 15:07:07 -0700 |
---|---|---|
committer | Brian Warner <warner@lothar.com> | 2018-10-16 15:11:15 -0700 |
commit | 5d9ca6ab306e713fc0282aebde5c9196ad86b7ab (patch) | |
tree | 18bfcce06f61da5aaee6c8f940d712c0b916dbed /srp/src/server.rs | |
parent | 6516978c0baa72df8ad0b6b66c07081eaa47cb18 (diff) | |
download | PAKEs-5d9ca6ab306e713fc0282aebde5c9196ad86b7ab.tar.xz |
reformat all code to match rustfmt-1.29.0
Diffstat (limited to 'srp/src/server.rs')
-rw-r--r-- | srp/src/server.rs | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/srp/src/server.rs b/srp/src/server.rs index 137d6b3..a5d49ab 100644 --- a/srp/src/server.rs +++ b/srp/src/server.rs @@ -4,7 +4,7 @@ //! First receive user's username and public value `a_pub`, retrieve from a //! database `UserRecord` for a given username, generate `b` (e.g. 512 bits //! long) and initialize SRP server instance: -//! +//! //! ```ignore //! use srp::groups::G_2048; //! @@ -13,31 +13,31 @@ //! let b = rng.gen_iter::<u8>().take(64).collect::<Vec<u8>>(); //! let server = SrpServer::<Sha256>::new(&user, &a_pub, &b, &G_2048)?; //! ``` -//! +//! //! Next send to user `b_pub` and `salt` from user record: -//! +//! //! ```ignore //! let b_pub = server.get_b_pub(); //! conn.reply_to_handshake(&user.salt, b_pub); //! ``` -//! +//! //! And finally recieve user proof, verify it and send server proof in the //! reply: -//! +//! //! ```ignore //! let user_proof = conn.receive_proof(); //! let server_proof = server.verify(user_proof)?; //! conn.send_proof(server_proof); //! ``` -//! +//! //! To get the shared secret use `get_key` method. As alternative to using //! `verify` method it's also possible to use this key for authentificated //! encryption. use std::marker::PhantomData; -use num::{BigUint, Zero}; use digest::Digest; use generic_array::GenericArray; +use num::{BigUint, Zero}; use tools::powm; use types::{SrpAuthError, SrpGroup}; @@ -58,21 +58,26 @@ pub struct SrpServer<D: Digest> { key: GenericArray<u8, D::OutputSize>, - d: PhantomData<D> + d: PhantomData<D>, } -impl< D: Digest> SrpServer< D> { +impl<D: Digest> SrpServer<D> { /// Create new server state. - pub fn new(user: &UserRecord, a_pub: &[u8], b: &[u8], params: &SrpGroup) - -> Result<Self, SrpAuthError> - { + pub fn new( + user: &UserRecord, + a_pub: &[u8], + b: &[u8], + params: &SrpGroup, + ) -> Result<Self, SrpAuthError> { let a_pub = BigUint::from_bytes_be(a_pub); // Safeguard against malicious A if &a_pub % ¶ms.n == BigUint::zero() { - return Err(SrpAuthError { description: "Malicious a_pub value" }) + return Err(SrpAuthError { + description: "Malicious a_pub value", + }); } let v = BigUint::from_bytes_be(user.verifier); - let b = BigUint::from_bytes_be(b) % ¶ms.n; + let b = BigUint::from_bytes_be(b) % ¶ms.n; let k = params.compute_k::<D>(); // kv + g^b let interm = (k * &v) % ¶ms.n; @@ -87,12 +92,18 @@ impl< D: Digest> SrpServer< D> { let d = Default::default(); //(Av^u) ^ b let key = { - let u = BigUint::from_bytes_be(&u); + let u = BigUint::from_bytes_be(&u); let t = (&a_pub * powm(&v, &u, ¶ms.n)) % ¶ms.n; let s = powm(&t, &b, ¶ms.n); D::digest(&s.to_bytes_be()) }; - Ok(Self { b, a_pub, b_pub, key, d}) + Ok(Self { + b, + a_pub, + b_pub, + key, + d, + }) } /// Get private `b` value. (see `new_with_b` documentation) @@ -113,9 +124,10 @@ impl< D: Digest> SrpServer< D> { /// Process user proof of having the same shared secret and compute /// server proof for sending to the user. - pub fn verify(&self, user_proof: &[u8]) - -> Result<GenericArray<u8, D::OutputSize>, SrpAuthError> - { + pub fn verify( + &self, + user_proof: &[u8], + ) -> Result<GenericArray<u8, D::OutputSize>, SrpAuthError> { // M = H(A, B, K) let mut d = D::new(); d.input(&self.a_pub.to_bytes_be()); @@ -130,7 +142,9 @@ impl< D: Digest> SrpServer< D> { d.input(&self.key); Ok(d.result()) } else { - Err(SrpAuthError { description: "Incorrect user proof" }) + Err(SrpAuthError { + description: "Incorrect user proof", + }) } } } |