Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct descriptions of M1 & M2 per RFC 5054 #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions srp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
//! |`a_pub = g^a` | — `a_pub`, `I` —> | (lookup `s`, `v` for given `I`) |
//! |`x = PH(P, s)` | <— `b_pub`, `s` — | `b_pub = k*v + g^b` |
//! |`u = H(a_pub ‖ b_pub)` | | `u = H(a_pub ‖ b_pub)` |
//! |`s = (b_pub - k*g^x)^(a+u*x)` | | `S = (b_pub - k*g^x)^(a+u*x)` |
//! |`K = H(s)` | | `K = H(s)` |
//! |`M1 = H(A ‖ B ‖ K)` | — `M1` —> | (verify `M1`) |
//! |(verify `M2`) | <— `M2` — | `M2 = H(A ‖ M1 ‖ K)` |
//! |`S = (b_pub - k*g^x)^(a+u*x)` | | `S = (b_pub - k*g^x)^(a+u*x)` |
//! |`M1 = H(A ‖ B ‖ S)` | — `M1` —> | (verify `M1`) |
//! |(verify `M2`) | <— `M2` — | `M2 = H(A ‖ M1 ‖ S)` |
//!
//! Variables and notations have the following meaning:
//!
Expand Down
8 changes: 5 additions & 3 deletions srp/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ pub fn compute_k<D: Digest>(params: &SrpGroup) -> BigUint {
BigUint::from_bytes_be(d.finalize().as_slice())
}

// M1 = H(A, B, K) this doesn't follow the spec but apparently no one does for M1
// M1 should equal = H(H(N) XOR H(g) | H(U) | s | A | B | K) according to the spec
// M1 = H(A, B, S) follows SRP-6 required by a strict interpretation of RFC
// 5054; this doesn't follow RFC 2945, where
// M1 = H(H(N) XOR H(g) | H(U) | s | A | B | K)
// as RFC 5054 doesn't mandate its use.
#[must_use]
pub fn compute_m1<D: Digest>(a_pub: &[u8], b_pub: &[u8], key: &[u8]) -> Output<D> {
let mut d = D::new();
Expand All @@ -38,7 +40,7 @@ pub fn compute_m1<D: Digest>(a_pub: &[u8], b_pub: &[u8], key: &[u8]) -> Output<D
d.finalize()
}

// M2 = H(A, M1, K)
// M2 = H(A, M1, S)
#[must_use]
pub fn compute_m2<D: Digest>(a_pub: &[u8], m1: &Output<D>, key: &[u8]) -> Output<D> {
let mut d = D::new();
Expand Down