summaryrefslogtreecommitdiff
path: root/lib/srp/authentication.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/srp/authentication.rb')
-rw-r--r--lib/srp/authentication.rb50
1 files changed, 39 insertions, 11 deletions
diff --git a/lib/srp/authentication.rb b/lib/srp/authentication.rb
index f4b2e70..96f68fe 100644
--- a/lib/srp/authentication.rb
+++ b/lib/srp/authentication.rb
@@ -5,21 +5,49 @@ module SRP
include Util
+ class Session
+ include Util
+ attr_accessor :aa, :bb
+
+ def initialize(aa, verifier)
+ @aa = aa
+ @b = bigrand(32).hex
+ # B = g^b + k v (mod N)
+ @bb = (modpow(GENERATOR, @b, PRIME_N) + multiplier * verifier) % PRIME_N
+ @verifier = verifier
+ end
+
+ def u
+ calculate_u(aa, bb, PRIME_N)
+ end
+
+ def secret
+ @s ||= calculate_secret
+ end
+
+ def m1
+ calculate_m(aa, bb, secret)
+ end
+
+ def m2
+ calculate_m(aa, m1, secret)
+ end
+
+ protected
+
+ def calculate_secret
+ base = (modpow(@verifier, u, PRIME_N) * aa) % PRIME_N
+ modpow(base, @b, PRIME_N)
+ end
+ end
def initialize_auth(aa)
- @aa = aa
- @b = bigrand(32).hex
- # B = g^b + k v (mod N)
- @bb = (modpow(GENERATOR, @b, PRIME_N) + multiplier * verifier) % PRIME_N
- return @bb
+ return Session.new(aa, verifier)
end
- def authenticate(m)
- u = calculate_u(@aa, @bb, PRIME_N)
- base = (modpow(verifier, u, PRIME_N) * @aa) % PRIME_N
- server_s = modpow(base, @b, PRIME_N)
- if(m == calculate_m(@aa, @bb, server_s))
- return calculate_m(@aa, m, server_s)
+ def authenticate(m, session)
+ if(m == session.m1)
+ return session.m2
end
end