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(A, B, K) this doesn't follow the spec but apparently no one does for M1
29 // M1 should equal = H(H(N) XOR H(g) | H(U) | s | A | B | K) according to the spec
30 pub fn compute_m1<D: Digest>(a_pub: &[u8], b_pub: &[u8], key: &[u8]) -> Output<D> {
39 pub fn compute_m2<D: Digest>(a_pub: &[u8], m1: &Output<D>, key: &[u8]) -> Output<D> {