Class: CryptoToolchain::SRP::SimpleClient
- Includes:
- Framework
- Defined in:
- lib/crypto_toolchain/srp/simple_client.rb
Constant Summary
Constants included from Framework
Instance Attribute Summary collapse
-
#u ⇒ Object
readonly
Returns the value of attribute u.
Attributes included from Framework
#email, #g, #k, #key, #n, #password, #privkey, #pubkey, #salt, #socket
Attributes inherited from Client
#authenticated, #server_pubkey
Instance Method Summary collapse
- #calculate_secret ⇒ Object
- #hello_received(_salt, _server_pubkey, _u) ⇒ Object
-
#initialize(**kargs) ⇒ SimpleClient
constructor
A new instance of SimpleClient.
Methods included from Framework
#error_received, #event_loop, #go!, #shutdown_received, #write_message
Methods inherited from Client
#authentication_success_received, #send_hello, #send_verify
Constructor Details
#initialize(**kargs) ⇒ SimpleClient
Returns a new instance of SimpleClient.
8 9 10 11 12 |
# File 'lib/crypto_toolchain/srp/simple_client.rb', line 8 def initialize(**kargs) provided_pubkey = kargs.delete(:pubkey) super(**kargs) @pubkey = provided_pubkey || g.modpow(privkey, n) end |
Instance Attribute Details
#u ⇒ Object (readonly)
Returns the value of attribute u.
6 7 8 |
# File 'lib/crypto_toolchain/srp/simple_client.rb', line 6 def u @u end |
Instance Method Details
#calculate_secret ⇒ Object
24 25 26 27 28 29 |
# File 'lib/crypto_toolchain/srp/simple_client.rb', line 24 def calculate_secret xH = Digest::SHA256.hexdigest("#{salt}#{password}") x = xH.to_i(16) # S = B**(a + ux) % n server_pubkey.modpow(privkey + (u * x), n) end |
#hello_received(_salt, _server_pubkey, _u) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/crypto_toolchain/srp/simple_client.rb', line 14 def hello_received(_salt, _server_pubkey, _u) @salt = _salt.to_i @server_pubkey = _server_pubkey.to_i @u = _u.to_i secret = calculate_secret puts "SimpleClient generated secret #{secret}" if DEBUG @key = Digest::SHA256.hexdigest(secret.to_s) send_verify end |