summaryrefslogtreecommitdiff
path: root/lib/srp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/srp')
-rw-r--r--lib/srp/client.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/srp/client.rb b/lib/srp/client.rb
index 22ed9f7..de17fb3 100644
--- a/lib/srp/client.rb
+++ b/lib/srp/client.rb
@@ -10,31 +10,33 @@ module SRP
def initialize(username, password, salt = nil)
@username = username
@password = password
- @salt = (salt || bigrand(4)).hex
+ @salt = salt || bigrand(4).hex
@multiplier = multiplier # let's cache it
calculate_verifier
end
- def authenticate(server, username, password)
- x = calculate_x(username, password)
+ def authenticate(server)
a = bigrand(32).hex
aa = modpow(GENERATOR, a) # A = g^a (mod N)
- bb = server.handshake(username, aa)
+ bb = server.handshake(@username, aa)
u = calculate_u(aa, bb)
- client_s = calculate_client_s(x, a, bb, u)
+ client_s = calculate_client_s(private_key, a, bb, u)
server.validate(calculate_m(aa, bb, client_s))
end
protected
+
def calculate_verifier
- x = calculate_x
- @verifier = modpow(GENERATOR, x)
- @verifier
+ @verifier ||= modpow(GENERATOR, private_key)
+ end
+
+ def private_key
+ @private_key ||= calculate_private_key
end
- def calculate_x(username = @username, password = @password)
+ def calculate_private_key
shex = '%x' % [@salt]
- inner = sha256_str([username, password].join(':'))
+ inner = sha256_str([@username, @password].join(':'))
sha256_hex(shex, inner).hex
end