From c73f7c1b4c1270d4d0ca47650a12893a6d13e796 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 4 Oct 2012 10:32:39 +0200 Subject: simplifying modpow to default to BIG_PRIME_N --- lib/srp/authentication.rb | 6 +++--- lib/srp/client.rb | 8 ++++---- lib/srp/util.rb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/srp/authentication.rb b/lib/srp/authentication.rb index 0fd275c..3428fd4 100644 --- a/lib/srp/authentication.rb +++ b/lib/srp/authentication.rb @@ -13,7 +13,7 @@ module SRP @aa = aa @b = bigrand(32).hex # B = g^b + k v (mod N) - @bb = (modpow(GENERATOR, @b, BIG_PRIME_N) + multiplier * verifier) % BIG_PRIME_N + @bb = (modpow(GENERATOR, @b) + multiplier * verifier) % BIG_PRIME_N end def u @@ -23,8 +23,8 @@ module SRP # do not cache this - it's secret and someone might store the # session in a CookieStore def secret(verifier) - base = (modpow(verifier, u, BIG_PRIME_N) * aa) % BIG_PRIME_N - modpow(base, @b, BIG_PRIME_N) + base = (modpow(verifier, u) * aa) % BIG_PRIME_N + modpow(base, @b) end def m1(verifier) diff --git a/lib/srp/client.rb b/lib/srp/client.rb index 65052f5..22ed9f7 100644 --- a/lib/srp/client.rb +++ b/lib/srp/client.rb @@ -18,7 +18,7 @@ module SRP def authenticate(server, username, password) x = calculate_x(username, password) a = bigrand(32).hex - aa = modpow(GENERATOR, a, BIG_PRIME_N) # A = g^a (mod N) + aa = modpow(GENERATOR, a) # A = g^a (mod N) bb = server.handshake(username, aa) u = calculate_u(aa, bb) client_s = calculate_client_s(x, a, bb, u) @@ -28,7 +28,7 @@ module SRP protected def calculate_verifier x = calculate_x - @verifier = modpow(GENERATOR, x, BIG_PRIME_N) + @verifier = modpow(GENERATOR, x) @verifier end @@ -41,9 +41,9 @@ module SRP def calculate_client_s(x, a, bb, u) base = bb base += BIG_PRIME_N * @multiplier - base -= modpow(GENERATOR, x, BIG_PRIME_N) * @multiplier + base -= modpow(GENERATOR, x) * @multiplier base = base % BIG_PRIME_N - modpow(base, x * u + a, BIG_PRIME_N) + modpow(base, x * u + a) end end end diff --git a/lib/srp/util.rb b/lib/srp/util.rb index fcbab31..087ce5d 100644 --- a/lib/srp/util.rb +++ b/lib/srp/util.rb @@ -20,7 +20,7 @@ d15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e5 GENERATOR = 2 # g # a^n (mod m) - def modpow(a, n, m) + def modpow(a, n, m = BIG_PRIME_N) r = 1 while true r = r * a % m if n[0] == 1 -- cgit v1.2.3