1 use digest::{Digest, Output};
2 use num_bigint::BigUint;
4 use crate::types::SrpGroup;
6 // u = H(PAD(A) | PAD(B))
7 pub fn compute_u<D: Digest>(a_pub: &[u8], b_pub: &[u8]) -> BigUint {
11 BigUint::from_bytes_be(&u.finalize())
15 pub fn compute_k<D: Digest>(params: &SrpGroup) -> BigUint {
16 let n = params.n.to_bytes_be();
17 let g_bytes = params.g.to_bytes_be();
18 let mut buf = vec![0u8; n.len()];
19 let l = n.len() - g_bytes.len();
20 buf[l..].copy_from_slice(&g_bytes);
25 BigUint::from_bytes_be(d.finalize().as_slice())
28 // M1 = H(H(N) XOR H(g) | H(U) | s | A | B | K)
29 pub fn compute_m1<D: Digest>(
35 let mut d_n = D::new();
36 d_n.update(params.n.to_bytes_be());
37 let h_n = d_n.finalize();
39 let mut d_g = D::new();
40 d_g.update(params.g.to_bytes_be());
41 let h_g = d_g.finalize();
43 let ng_xor: Vec<u8> = h_n.iter().zip(h_g.iter()).map(|(n, g)| n ^ g).collect();
54 pub fn compute_m2<D: Digest>(a_pub: &[u8], m1: &Output<D>, key: &[u8]) -> Output<D> {