class CryptoToolchain::SRP::Client

Attributes

authenticated[R]
authenticated?[R]
server_pubkey[R]

Public Class Methods

new(**kargs) click to toggle source
Calls superclass method CryptoToolchain::SRP::Framework::new
# File lib/crypto_toolchain/srp/client.rb, line 9
def initialize(**kargs)
  provided_pubkey = kargs.delete(:pubkey)
  super(**kargs)
  @pubkey = provided_pubkey || g.modpow(privkey, n)
end

Public Instance Methods

authentication_success_received() click to toggle source
# File lib/crypto_toolchain/srp/client.rb, line 33
def authentication_success_received
  @authenticated = true
  write_message("shutdown")
  raise ShutdownSignal
end
calculate_secret() click to toggle source
# File lib/crypto_toolchain/srp/client.rb, line 39
def calculate_secret
  return 0 if [0, n, n**2, n**3].include?(pubkey)

  xH = Digest::SHA256.hexdigest("#{salt}#{password}")
  x = xH.to_i(16)
  uH = Digest::SHA256.hexdigest("#{pubkey}#{server_pubkey}")
  u = uH.to_i(16)
  # S = (B - k * g**x)**(a + u * x) % N
  (server_pubkey - k * g.modpow(x, n)).modpow(privkey + u * x, n)
end
hello_received(_salt, _server_pubkey) click to toggle source
# File lib/crypto_toolchain/srp/client.rb, line 24
def hello_received(_salt, _server_pubkey)
  @salt = _salt.to_i
  @server_pubkey = _server_pubkey.to_i
  secret = calculate_secret
  puts "Client generated secret #{secret}" if DEBUG
  @key = Digest::SHA256.hexdigest(secret.to_s)
  send_verify
end
send_hello() click to toggle source
# File lib/crypto_toolchain/srp/client.rb, line 15
def send_hello
  write_message("hello", email, pubkey)
end
send_verify() click to toggle source
# File lib/crypto_toolchain/srp/client.rb, line 19
def send_verify
  hmac = OpenSSL::HMAC.hexdigest("SHA256", key.to_s, salt.to_s)
  write_message("verify", hmac)
end