1010//! ```rust
1111//! use crate::srp::groups::G_2048;
1212//! use sha2::Sha256; // Note: You should probably use a proper password KDF
13- //! # use crate::srp::client::SrpClient ;
13+ //! # use crate::srp::client::Client ;
1414//!
15- //! let client = SrpClient ::<Sha256>::new(&G_2048);
15+ //! let client = Client ::<Sha256>::new(&G_2048);
1616//! ```
1717//!
1818//! Next send handshake data (username and `a_pub`) to the server and receive
1919//! `salt` and `b_pub`:
2020//!
2121//! ```rust
22- //! # let client = crate::srp::client::SrpClient ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
22+ //! # let client = crate::srp::client::Client ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
2323//! # fn server_response()-> (Vec<u8>, Vec<u8>) { (vec![], vec![]) }
2424//!
2525//! let mut a = [0u8; 64];
3232//! `process_reply` can return error in case of malicious `b_pub`.
3333//!
3434//! ```rust
35- //! # let client = crate::srp::client::SrpClient ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
35+ //! # let client = crate::srp::client::Client ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
3636//! # let a = [0u8; 64];
3737//! # let username = b"username";
3838//! # let password = b"password";
4848//! `verify_server` method will return error in case of incorrect server reply.
4949//!
5050//! ```rust
51- //! # let client = crate::srp::client::SrpClient ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
51+ //! # let client = crate::srp::client::Client ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
5252//! # let verifier = client.process_reply(b"", b"", b"", b"", b"1").unwrap();
5353//! # fn send_proof(_: &[u8]) -> Vec<u8> { vec![173, 202, 13, 26, 207, 73, 0, 46, 121, 238, 48, 170, 96, 146, 60, 49, 88, 76, 12, 184, 152, 76, 207, 220, 140, 205, 190, 189, 117, 6, 131, 63] }
5454//!
6060//! `key` contains shared secret key between user and the server. You can extract shared secret
6161//! key using `key()` method.
6262//! ```rust
63- //! # let client = crate::srp::client::SrpClient ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
63+ //! # let client = crate::srp::client::Client ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
6464//! # let verifier = client.process_reply(b"", b"", b"", b"", b"1").unwrap();
6565//!
6666//! verifier.key();
7373//! key in case of correct server data.
7474//!
7575//! ```rust
76- //! # let client = crate::srp::client::SrpClient ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
76+ //! # let client = crate::srp::client::Client ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
7777//! # let verifier = client.process_reply_rfc5054(b"", b"", b"", b"", b"1").unwrap();
7878//! # fn send_proof(_: &[u8]) -> Vec<u8> { vec![10, 215, 214, 40, 136, 200, 122, 121, 68, 160, 38, 32, 85, 82, 128, 30, 199, 194, 126, 222, 61, 55, 2, 28, 120, 181, 155, 102, 141, 65, 17, 64] }
7979//!
8989//! Man-in-the-middle (MITM) attack for registration.
9090//!
9191//! ```rust
92- //! # let client = crate::srp::client::SrpClient ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
92+ //! # let client = crate::srp::client::Client ::<sha2::Sha256>::new(&crate::srp::groups::G_2048);
9393//! # let username = b"username";
9494//! # let password = b"password";
9595//! # let salt = b"salt";
@@ -107,37 +107,37 @@ use digest::{Digest, Output};
107107use subtle:: ConstantTimeEq ;
108108
109109use crate :: {
110- SrpGroup ,
111- errors:: SrpAuthError ,
110+ Group ,
111+ errors:: AuthError ,
112112 utils:: { compute_hash, compute_k, compute_m1, compute_m1_rfc5054, compute_m2, compute_u} ,
113113} ;
114114
115115/// SRP client state before handshake with the server.
116- pub struct SrpClient < D : Digest > {
117- params : & ' static SrpGroup ,
116+ pub struct Client < D : Digest > {
117+ params : & ' static Group ,
118118 username_in_x : bool ,
119119 d : PhantomData < D > ,
120120}
121121
122122/// SRP client state after handshake with the server.
123- pub struct SrpClientVerifier < D : Digest > {
123+ pub struct ClientVerifier < D : Digest > {
124124 m1 : Output < D > ,
125125 m2 : Output < D > ,
126126 key : Vec < u8 > ,
127127}
128128
129129/// RFC 5054 SRP client state after handshake with the server.
130- pub struct SrpClientVerifierRfc5054 < D : Digest > {
130+ pub struct ClientVerifierRfc5054 < D : Digest > {
131131 m1 : Output < D > ,
132132 m2 : Output < D > ,
133133 key : Vec < u8 > ,
134134 session_key : Vec < u8 > ,
135135}
136136
137- impl < D : Digest > SrpClient < D > {
137+ impl < D : Digest > Client < D > {
138138 /// Create new SRP client instance.
139139 #[ must_use]
140- pub const fn new ( params : & ' static SrpGroup ) -> Self {
140+ pub const fn new ( params : & ' static Group ) -> Self {
141141 Self {
142142 params,
143143 username_in_x : true ,
@@ -146,7 +146,7 @@ impl<D: Digest> SrpClient<D> {
146146 }
147147
148148 #[ must_use]
149- pub const fn new_with_options ( params : & ' static SrpGroup , username_in_x : bool ) -> Self {
149+ pub const fn new_with_options ( params : & ' static Group , username_in_x : bool ) -> Self {
150150 Self {
151151 params,
152152 username_in_x,
@@ -236,7 +236,7 @@ impl<D: Digest> SrpClient<D> {
236236 password : & [ u8 ] ,
237237 salt : & [ u8 ] ,
238238 b_pub : & [ u8 ] ,
239- ) -> Result < SrpClientVerifier < D > , SrpAuthError > {
239+ ) -> Result < ClientVerifier < D > , AuthError > {
240240 let a = BoxedUint :: from_be_slice_vartime ( a) ;
241241 let a_pub = self . compute_g_x ( & a) ;
242242 let b_pub = BoxedUint :: from_be_slice_vartime ( b_pub) ;
@@ -266,7 +266,7 @@ impl<D: Digest> SrpClient<D> {
266266 & key. to_be_bytes_trimmed_vartime ( ) ,
267267 ) ;
268268
269- Ok ( SrpClientVerifier {
269+ Ok ( ClientVerifier {
270270 m1,
271271 m2,
272272 key : key. to_be_bytes_trimmed_vartime ( ) . to_vec ( ) ,
@@ -284,7 +284,7 @@ impl<D: Digest> SrpClient<D> {
284284 password : & [ u8 ] ,
285285 salt : & [ u8 ] ,
286286 b_pub : & [ u8 ] ,
287- ) -> Result < SrpClientVerifierRfc5054 < D > , SrpAuthError > {
287+ ) -> Result < ClientVerifierRfc5054 < D > , AuthError > {
288288 let a = BoxedUint :: from_be_slice_vartime ( a) ;
289289 let a_pub = self . compute_g_x ( & a) ;
290290 let b_pub = BoxedUint :: from_be_slice_vartime ( b_pub) ;
@@ -321,7 +321,7 @@ impl<D: Digest> SrpClient<D> {
321321 session_key. as_slice ( ) ,
322322 ) ;
323323
324- Ok ( SrpClientVerifierRfc5054 {
324+ Ok ( ClientVerifierRfc5054 {
325325 m1,
326326 m2,
327327 key : premaster_secret. to_vec ( ) ,
@@ -330,11 +330,11 @@ impl<D: Digest> SrpClient<D> {
330330 }
331331
332332 /// Ensure `b_pub` is non-zero and therefore not maliciously crafted.
333- fn validate_b_pub ( & self , b_pub : & BoxedUint ) -> Result < ( ) , SrpAuthError > {
333+ fn validate_b_pub ( & self , b_pub : & BoxedUint ) -> Result < ( ) , AuthError > {
334334 let n = self . params . n . modulus ( ) . as_nz_ref ( ) ;
335335
336336 if ( b_pub. resize ( n. bits_precision ( ) ) % n) . is_zero ( ) . into ( ) {
337- return Err ( SrpAuthError :: IllegalParameter ( "b_pub" . to_owned ( ) ) ) ;
337+ return Err ( AuthError :: IllegalParameter ( "b_pub" . to_owned ( ) ) ) ;
338338 }
339339
340340 Ok ( ( ) )
@@ -346,7 +346,7 @@ impl<D: Digest> SrpClient<D> {
346346 }
347347}
348348
349- impl < D : Digest > SrpClientVerifier < D > {
349+ impl < D : Digest > ClientVerifier < D > {
350350 /// Get shared secret key without authenticating server, e.g. for using with
351351 /// authenticated encryption modes. DO NOT USE this method without
352352 /// some kind of secure authentication
@@ -360,16 +360,16 @@ impl<D: Digest> SrpClientVerifier<D> {
360360 }
361361
362362 /// Verify server reply to verification data.
363- pub fn verify_server ( & self , reply : & [ u8 ] ) -> Result < ( ) , SrpAuthError > {
363+ pub fn verify_server ( & self , reply : & [ u8 ] ) -> Result < ( ) , AuthError > {
364364 if self . m2 . ct_eq ( reply) . unwrap_u8 ( ) == 1 {
365365 Ok ( ( ) )
366366 } else {
367- Err ( SrpAuthError :: BadRecordMac ( "server" . to_owned ( ) ) )
367+ Err ( AuthError :: BadRecordMac ( "server" . to_owned ( ) ) )
368368 }
369369 }
370370}
371371
372- impl < D : Digest > SrpClientVerifierRfc5054 < D > {
372+ impl < D : Digest > ClientVerifierRfc5054 < D > {
373373 /// Get shared secret key without authenticating server, e.g. for using with
374374 /// authenticated encryption modes. DO NOT USE this method without
375375 /// some kind of secure authentication
@@ -383,11 +383,11 @@ impl<D: Digest> SrpClientVerifierRfc5054<D> {
383383 }
384384
385385 /// Verify server reply to verification data and return shared session key.
386- pub fn verify_server ( & self , reply : & [ u8 ] ) -> Result < & [ u8 ] , SrpAuthError > {
386+ pub fn verify_server ( & self , reply : & [ u8 ] ) -> Result < & [ u8 ] , AuthError > {
387387 if self . m2 . ct_eq ( reply) . unwrap_u8 ( ) == 1 {
388388 Ok ( self . session_key . as_slice ( ) )
389389 } else {
390- Err ( SrpAuthError :: BadRecordMac ( "server" . to_owned ( ) ) )
390+ Err ( AuthError :: BadRecordMac ( "server" . to_owned ( ) ) )
391391 }
392392 }
393393}
0 commit comments