From 4f57d8010a90fe1221c351f695d15d29a9cdc37f Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 3 Oct 2012 16:59:46 +0200 Subject: calculate verifiers and multiplier just like in py srp Some other parts are still missing. Main issue was using hashes of hex representation rather that hashes of byte arrays --- lib/srp/client.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/srp/client.rb') diff --git a/lib/srp/client.rb b/lib/srp/client.rb index 484d12b..37f37d7 100644 --- a/lib/srp/client.rb +++ b/lib/srp/client.rb @@ -7,10 +7,10 @@ module SRP attr_reader :salt, :verifier - def initialize(username, password) + def initialize(username, password, salt = nil) @username = username @password = password - @salt = "5d3055e0acd3ddcfc15".hex # bigrand(10).hex + @salt = salt.hex || bigrand(4).hex @multiplier = multiplier # let's cache it calculate_verifier end @@ -27,15 +27,15 @@ module SRP protected def calculate_verifier - x = calculate_x(@username, @password, @salt) - @verifier = modpow(GENERATOR, x, PRIME_N) + x = calculate_x + @verifier = modpow(GENERATOR, x, BIG_PRIME_N) @verifier end - def calculate_x(username, password, salt) - shex = '%x' % [salt] - spad = "" # if shex.length.odd? then '0' else '' end - sha256_str(spad + shex + sha256_str([username, password].join(':'))).hex + def calculate_x + shex = '%x' % [@salt] + inner = sha256_str([@username, @password].join(':')) + sha256_str([shex].pack('H*') + [inner].pack('H*')).hex end def calculate_client_s(x, a, bb, u) -- cgit v1.2.3