Sha256: e3cbc5d855a54df6dbe600a4ee6ee728c24a0aa48793045d0fad6dccb0870dcf
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/util') module SRP class Client include Util attr_reader :salt, :verifier def initialize(username, password) @username = username @password = password @salt = "5d3055e0acd3ddcfc15".hex # bigrand(10).hex @multiplier = multiplier # let's cache it calculate_verifier end def authenticate(server, username, password) x = calculate_x(username, password, salt) a = bigrand(32).hex aa = modpow(GENERATOR, a, PRIME_N) # A = g^a (mod N) bb = server.handshake(username, aa) u = calculate_u(aa, bb, PRIME_N) client_s = calculate_client_s(x, a, bb, u) server.validate(calculate_m(aa, bb, client_s)) end protected def calculate_verifier x = calculate_x(@username, @password, @salt) @verifier = modpow(GENERATOR, x, 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 end def calculate_client_s(x, a, bb, u) base = bb base += PRIME_N * @multiplier base -= modpow(GENERATOR, x, PRIME_N) * @multiplier base = base % PRIME_N modpow(base, x * u + a, PRIME_N) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-srp-0.0.2 | lib/srp/client.rb |