diff --git a/proton-bridge/src/srp.rs b/proton-bridge/src/srp.rs index 31daa2a..98c02dd 100644 --- a/proton-bridge/src/srp.rs +++ b/proton-bridge/src/srp.rs @@ -42,10 +42,6 @@ fn to_le256(n: &BigUint) -> [u8; 256] { out } -/// Decode a little-endian byte slice into a BigUint. -fn from_le(b: &[u8]) -> BigUint { - BigUint::from_bytes_le(b) -} // ── main entry point ──────────────────────────────────────────────────────── @@ -60,9 +56,9 @@ pub fn generate_proofs( let b_bytes = B64.decode(server_ephemeral_b64).map_err(|e| e.to_string())?; let salt_bytes = B64.decode(salt_b64).map_err(|e| e.to_string())?; - let n = from_le(&n_bytes); + let n = BigUint::from_bytes_le(&n_bytes); let g = BigUint::from(2u32); - let b = from_le(&b_bytes); + let b = BigUint::from_bytes_le(&b_bytes); // k = expandHash(g || N) mod N // go-srp uses fromInt(bitLength, N) — always exactly 256 bytes, not raw decoded bytes. @@ -71,18 +67,18 @@ pub fn generate_proofs( let mut kh = Vec::with_capacity(512); kh.extend_from_slice(&g_le); kh.extend_from_slice(&n_le); - let k = from_le(&expand_hash(&kh)) % &n; + let k = BigUint::from_bytes_le(&expand_hash(&kh)) %&n; // x = password hash (ProtonMail-specific, see hash_password) let x_bytes = hash_password(version, password, &salt_bytes, &n_bytes)?; - let x = from_le(&x_bytes); + let x = BigUint::from_bytes_le(&x_bytes); // a: random secret with bitLength*2 < a < N-1 let n_minus_one = &n - BigUint::from(1u32); let a = loop { let mut buf = [0u8; 256]; rand::thread_rng().fill_bytes(&mut buf); - let candidate = from_le(&buf) % &n_minus_one; + let candidate = BigUint::from_bytes_le(&buf) % &n_minus_one; if candidate > BigUint::from(512u32) { break candidate; } @@ -97,7 +93,7 @@ pub fn generate_proofs( let mut ub = Vec::with_capacity(512); ub.extend_from_slice(&a_bytes); ub.extend_from_slice(&b_le); - let u = from_le(&expand_hash(&ub)); + let u = BigUint::from_bytes_le(&expand_hash(&ub)); // v = g^x mod N let v = g.modpow(&x, &n);