//! Additional SRP types.
-use crate::tools::powm;
use digest::Digest;
-use num::BigUint;
+use num_bigint::BigUint;
use std::{error, fmt};
/// SRP authentication error.
}
impl SrpGroup {
- pub(crate) fn powm(&self, v: &BigUint) -> BigUint {
- powm(&self.g, v, &self.n)
+ pub(crate) fn modpow(&self, v: &BigUint) -> BigUint {
+ self.g.modpow(v, &self.n)
}
/// Compute `k` with given hash function and return SRP parameters
buf[l..].copy_from_slice(&g_bytes);
let mut d = D::new();
- d.input(&n);
- d.input(&buf);
- BigUint::from_bytes_be(&d.result())
+ d.update(&n);
+ d.update(&buf);
+ BigUint::from_bytes_be(&d.finalize().as_slice())
+ }
+
+ /// Compute `Hash(N) xor Hash(g)` with given hash function and return SRP parameters
+ pub(crate) fn compute_hash_n_xor_hash_g<D: Digest>(&self) -> Vec<u8> {
+ let n = self.n.to_bytes_be();
+ let g_bytes = self.g.to_bytes_be();
+ let mut buf = vec![0u8; n.len()];
+ let l = n.len() - g_bytes.len();
+ buf[l..].copy_from_slice(&g_bytes);
+
+ let mut d = D::new();
+ d.update(&n);
+ let h = d.finalize_reset();
+ let h_n: &[u8] = h.as_slice();
+ d.update(&buf);
+ let h = d.finalize_reset();
+ let h_g: &[u8] = h.as_slice();
+
+ h_n.iter()
+ .zip(h_g.iter())
+ .map(|(&x1, &x2)| x1 ^ x2)
+ .collect()
}
}