@@ -7,7 +7,10 @@ use subtle::ConstantTimeEq;
77use crate :: {
88 Group ,
99 errors:: AuthError ,
10- utils:: { compute_hash, compute_k, compute_m1, compute_m1_rfc5054, compute_m2, compute_u} ,
10+ utils:: {
11+ compute_hash, compute_k, compute_m1_legacy, compute_m1_rfc5054, compute_m2, compute_u,
12+ monty_form,
13+ } ,
1114} ;
1215
1316/// SRP server implementation.
@@ -105,8 +108,8 @@ impl<G: Group, D: Digest> Server<G, D> {
105108 /// Compute the server's public ephemeral: `k*v + g^b % N`.
106109 #[ must_use]
107110 pub fn compute_b_pub ( & self , b : & BoxedUint , k : & BoxedUint , v : & BoxedUint ) -> BoxedUint {
108- let k = self . monty_form ( k) ;
109- let v = self . monty_form ( v) ;
111+ let k = monty_form ( k, self . g . params ( ) ) ;
112+ let v = monty_form ( v, self . g . params ( ) ) ;
110113 ( k * v + self . g . pow ( b) ) . retrieve ( )
111114 }
112115
@@ -119,8 +122,8 @@ impl<G: Group, D: Digest> Server<G, D> {
119122 u : & BoxedUint ,
120123 b : & BoxedUint ,
121124 ) -> BoxedUint {
122- let a_pub = self . monty_form ( a_pub) ;
123- let v = self . monty_form ( v) ;
125+ let a_pub = monty_form ( a_pub, self . g . params ( ) ) ;
126+ let v = monty_form ( v, self . g . params ( ) ) ;
124127
125128 // (A * v^u)
126129 ( a_pub * v. pow ( u) ) . pow ( b) . retrieve ( )
@@ -223,7 +226,7 @@ impl<G: Group, D: Digest> Server<G, D> {
223226
224227 let key = self . compute_premaster_secret ( & a_pub, & v, & u, & b) ;
225228
226- let m1 = compute_m1 :: < D > (
229+ let m1 = compute_m1_legacy :: < D > (
227230 a_pub_bytes,
228231 & b_pub_bytes,
229232 & key. to_be_bytes_trimmed_vartime ( ) ,
@@ -238,12 +241,6 @@ impl<G: Group, D: Digest> Server<G, D> {
238241 } )
239242 }
240243
241- /// Convert an integer into the Montgomery domain, returning a [`BoxedMontyForm`] modulo `N`.
242- fn monty_form ( & self , x : & BoxedUint ) -> BoxedMontyForm {
243- let precision = self . n ( ) . bits_precision ( ) ;
244- BoxedMontyForm :: new ( x. resize ( precision) , self . g . params ( ) )
245- }
246-
247244 /// Get the modulus `N`.
248245 fn n ( & self ) -> & Odd < BoxedUint > {
249246 self . g . params ( ) . modulus ( )
0 commit comments