Skip to content

Commit 838f2bd

Browse files
authored
srp: remove Srp* prefix from type names (#234)
This follows RFC 356 which suggests that type names should not include redundant prefixes: https://rust-lang.github.io/rfcs/0356-no-module-prefixes.html
1 parent a3e3e7e commit 838f2bd

File tree

9 files changed

+90
-90
lines changed

9 files changed

+90
-90
lines changed

srp/src/client.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
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];
@@ -32,7 +32,7 @@
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";
@@ -48,7 +48,7 @@
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
//!
@@ -60,7 +60,7 @@
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();
@@ -73,7 +73,7 @@
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
//!
@@ -89,7 +89,7 @@
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};
107107
use subtle::ConstantTimeEq;
108108

109109
use 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
}

srp/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use core::{error, fmt};
55

66
/// SRP authentication error.
77
#[derive(Debug, Clone, Eq, PartialEq)]
8-
pub enum SrpAuthError {
8+
pub enum AuthError {
99
IllegalParameter(String),
1010
BadRecordMac(String),
1111
}
1212

13-
impl fmt::Display for SrpAuthError {
13+
impl fmt::Display for AuthError {
1414
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1515
match self {
1616
Self::IllegalParameter(param) => {
@@ -23,4 +23,4 @@ impl fmt::Display for SrpAuthError {
2323
}
2424
}
2525

26-
impl error::Error for SrpAuthError {}
26+
impl error::Error for AuthError {}

srp/src/groups.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use once_cell::sync::Lazy;
1212

1313
/// Group used for SRP computations
1414
#[derive(Debug, Clone, Eq, PartialEq)]
15-
pub struct SrpGroup {
15+
pub struct Group {
1616
/// A large safe prime (N = 2q+1, where q is prime)
1717
pub n: BoxedMontyParams,
1818
/// A generator modulo N
1919
pub g: BoxedMontyForm,
2020
}
2121

22-
impl SrpGroup {
22+
impl Group {
2323
/// Initialize a new group from the given boxed integers.
2424
pub fn new(n: BoxedUint, g: BoxedUint) -> Self {
2525
let n = BoxedMontyParams::new(Odd::new(n).expect("n should be odd"));
@@ -28,36 +28,36 @@ impl SrpGroup {
2828
}
2929
}
3030

31-
pub static G_1024: Lazy<SrpGroup> = Lazy::new(|| {
32-
SrpGroup::new(
31+
pub static G_1024: Lazy<Group> = Lazy::new(|| {
32+
Group::new(
3333
BoxedUint::from_be_slice_vartime(include_bytes!("groups/1024.bin")),
3434
BoxedUint::from_be_slice_vartime(&[2]),
3535
)
3636
});
3737

38-
pub static G_1536: Lazy<SrpGroup> = Lazy::new(|| {
39-
SrpGroup::new(
38+
pub static G_1536: Lazy<Group> = Lazy::new(|| {
39+
Group::new(
4040
BoxedUint::from_be_slice_vartime(include_bytes!("groups/1536.bin")),
4141
BoxedUint::from_be_slice_vartime(&[2]),
4242
)
4343
});
4444

45-
pub static G_2048: Lazy<SrpGroup> = Lazy::new(|| {
46-
SrpGroup::new(
45+
pub static G_2048: Lazy<Group> = Lazy::new(|| {
46+
Group::new(
4747
BoxedUint::from_be_slice_vartime(include_bytes!("groups/2048.bin")),
4848
BoxedUint::from_be_slice_vartime(&[2]),
4949
)
5050
});
5151

52-
pub static G_3072: Lazy<SrpGroup> = Lazy::new(|| {
53-
SrpGroup::new(
52+
pub static G_3072: Lazy<Group> = Lazy::new(|| {
53+
Group::new(
5454
BoxedUint::from_be_slice_vartime(include_bytes!("groups/3072.bin")),
5555
BoxedUint::from_be_slice_vartime(&[5]),
5656
)
5757
});
5858

59-
pub static G_4096: Lazy<SrpGroup> = Lazy::new(|| {
60-
SrpGroup::new(
59+
pub static G_4096: Lazy<Group> = Lazy::new(|| {
60+
Group::new(
6161
BoxedUint::from_be_slice_vartime(include_bytes!("groups/4096.bin")),
6262
BoxedUint::from_be_slice_vartime(&[5]),
6363
)

srp/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ pub mod groups;
6363
pub mod server;
6464
pub mod utils;
6565

66-
pub use groups::SrpGroup;
66+
pub use groups::Group;

0 commit comments

Comments
 (0)