Class: Cakewalk::SASL::DiffieHellman Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cakewalk/sasl/diffie_hellman.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p, g, q) ⇒ DiffieHellman

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DiffieHellman.

Since:

  • 2.0.0



6
7
8
9
10
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 6

def initialize(p, g, q)
  @p = p
  @g = g
  @q = q
end

Instance Attribute Details

#eObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



4
5
6
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 4

def e
  @e
end

#gObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



4
5
6
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 4

def g
  @g
end

#pObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



4
5
6
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 4

def p
  @p
end

#qObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



4
5
6
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 4

def q
  @q
end

#xObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



4
5
6
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 4

def x
  @x
end

Instance Method Details

#generate(tries = 16) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)

Since:

  • 2.0.0



12
13
14
15
16
17
18
19
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 12

def generate(tries = 16)
  tries.times do
    @x = rand(@q)
    @e = mod_exp(@g, @x, @p)
    return @e if valid?
  end
  raise ArgumentError, "can't generate valid e"
end

#secret(f) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

compute the shared secret, given the public key

Since:

  • 2.0.0



22
23
24
# File 'lib/cakewalk/sasl/diffie_hellman.rb', line 22

def secret(f)
  mod_exp(f, @x, @p)
end