summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-10-03 16:59:46 +0200
committerAzul <azul@riseup.net>2012-10-03 16:59:46 +0200
commit4f57d8010a90fe1221c351f695d15d29a9cdc37f (patch)
treefd85a1db7a2d851a8227e566a406a62a2713e472 /lib
parent9683634eb18843151d318b483a5fb237508f4755 (diff)
calculate verifiers and multiplier just like in py srpfeature-py_srp_compat
Some other parts are still missing. Main issue was using hashes of hex representation rather that hashes of byte arrays
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby-srp.rb1
-rw-r--r--lib/srp/client.rb16
-rw-r--r--lib/srp/util.rb15
3 files changed, 15 insertions, 17 deletions
diff --git a/lib/ruby-srp.rb b/lib/ruby-srp.rb
index 7cbe06f..d5d6cf3 100644
--- a/lib/ruby-srp.rb
+++ b/lib/ruby-srp.rb
@@ -10,6 +10,7 @@ $:.unshift File.dirname(__FILE__)
module SRP
autoload :Client, 'srp/client'
autoload :Authentication, 'srp/authentication'
+ autoload :Util, 'srp/util'
class WrongPassword < StandardError
end
end
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)
diff --git a/lib/srp/util.rb b/lib/srp/util.rb
index bf4c248..66bd9e7 100644
--- a/lib/srp/util.rb
+++ b/lib/srp/util.rb
@@ -10,7 +10,7 @@ module SRP
115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3
EOS
- BIG_PRIME_N = <<-EOS # 1024 bits modulus (N)
+ BIG_PRIME_N = <<-EOS.split.join.hex # 1024 bits modulus (N)
eeaf0ab9adb38dd69c33f80afa8fc5e86072618775ff3c0b9ea2314c9c25657
6d674df7496ea81d3383b4813d692c6e0e0d5d8e250b98be48e495c1d6089da
d15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e5
@@ -43,21 +43,18 @@ d15dc7d7b46154d6b6ce8ef4ad69b15d4982559b297bcf1885c529f566660e5
end
def multiplier
- return "c46d46600d87fef149bd79b81119842f3c20241fda67d06ef412d8f6d9479c58".hex % PRIME_N
@k ||= calculate_multiplier
end
protected
def calculate_multiplier
- n = PRIME_N
+ n = BIG_PRIME_N
g = GENERATOR
- nhex = '%x' % [n]
- nlen = nhex.length + (nhex.length.odd? ? 1 : 0 )
- ghex = '%x' % [g]
- hashin = '0' * (nlen - nhex.length) + nhex \
- + '0' * (nlen - ghex.length) + ghex
- sha256_hex(hashin).hex % n
+ nhex = '%x' % n
+ ghex = '0%x' % g
+ hashin = [nhex].pack('H*') + [ghex].pack('H*')
+ sha256_str(hashin).hex
end
def calculate_m(aa, bb, s)