Encapsulates a Diffie-Hellman key exchange. This class is used internally by both the consumer and server objects.
Read more about Diffie-Hellman on wikipedia: en.wikipedia.org/wiki/Diffie-Hellman
A new DiffieHellman object, using the modulus and generator from the OpenID specification
# File lib/openid/dh.rb, line 22 def DiffieHellman.from_defaults DiffieHellman.new(@@default_mod, @@default_gen) end
# File lib/openid/dh.rb, line 26 def initialize(modulus=nil, generator=nil, priv=nil) @modulus = modulus.nil? ? @@default_mod : modulus @generator = generator.nil? ? @@default_gen : generator set_private(priv.nil? ? OpenID::CryptUtil.rand(@modulus-2) + 1 : priv) end
# File lib/openid/dh.rb, line 43 def using_default_values? @generator == @@default_gen && @modulus == @@default_mod end
# File lib/openid/dh.rb, line 36 def xor_secret(algorithm, composite, secret) dh_shared = get_shared_secret(composite) packed_dh_shared = OpenID::CryptUtil.num_to_binary(dh_shared) hashed_dh_shared = algorithm.call(packed_dh_shared) return DiffieHellman.strxor(secret, hashed_dh_shared) end