]> git.lizzy.rs Git - PAKEs.git/blob - srp/src/types.rs
srp: rebuild library (#79)
[PAKEs.git] / srp / src / types.rs
1 //! Additional SRP types.
2 use num_bigint::BigUint;
3 use std::fmt;
4
5 /// SRP authentication error.
6 #[derive(Debug, Clone, Eq, PartialEq)]
7 pub enum SrpAuthError {
8     IllegalParameter(String),
9     BadRecordMac(String),
10 }
11
12 impl fmt::Display for SrpAuthError {
13     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14         match self {
15             SrpAuthError::IllegalParameter(param) => {
16                 write!(f, "illegal_parameter: bad '{}' value", param)
17             }
18             SrpAuthError::BadRecordMac(param) => {
19                 write!(f, "bad_record_mac: incorrect '{}'  proof", param)
20             }
21         }
22     }
23 }
24
25 /// Group used for SRP computations
26 #[derive(Debug, Clone, Eq, PartialEq)]
27 pub struct SrpGroup {
28     /// A large safe prime (N = 2q+1, where q is prime)
29     pub n: BigUint,
30     /// A generator modulo N
31     pub g: BigUint,
32 }
33
34 #[cfg(test)]
35 mod tests {
36     use crate::groups::G_1024;
37     use crate::utils::compute_k;
38     use sha1::Sha1;
39
40     #[test]
41     fn test_k_1024_sha1() {
42         let k = compute_k::<Sha1>(&G_1024).to_bytes_be();
43         assert_eq!(&k, include_bytes!("test/k_sha1_1024.bin"));
44     }
45 }