1 //! Additional SRP types.
2 use crate::tools::powm;
7 /// SRP authentification error.
8 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
9 pub struct SrpAuthError {
10 pub(crate) description: &'static str,
13 impl fmt::Display for SrpAuthError {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 write!(f, "SRP authentification error")
19 impl error::Error for SrpAuthError {
20 fn description(&self) -> &str {
25 /// Group used for SRP computations
26 #[derive(Debug, Clone, Eq, PartialEq)]
28 /// A large safe prime (N = 2q+1, where q is prime)
30 /// A generator modulo N
35 pub(crate) fn powm(&self, v: &BigUint) -> BigUint {
36 powm(&self.g, v, &self.n)
39 /// Compute `k` with given hash function and return SRP parameters
40 pub(crate) fn compute_k<D: Digest>(&self) -> BigUint {
41 let n = self.n.to_bytes_be();
42 let g_bytes = self.g.to_bytes_be();
43 let mut buf = vec![0u8; n.len()];
44 let l = n.len() - g_bytes.len();
45 buf[l..].copy_from_slice(&g_bytes);
50 BigUint::from_bytes_be(&d.result())
56 use crate::groups::G_1024;
60 fn test_k_1024_sha1() {
61 let k = G_1024.compute_k::<Sha1>().to_bytes_be();
62 assert_eq!(&k, include_bytes!("k_sha1_1024.bin"));