class Ronin::Support::Crypto::Key::DH

Represents an Diffie-Hellman (DH) key.

@see rubydoc.info/stdlib/openssl/OpenSSL/PKey/DH.html

@since 1.0.0

@api public

Public Class Methods

generate(key_size=1024, generator: nil) click to toggle source

Generates a new DH key.

@param [Integer] key_size

The size of the key in bits.

@param [Integer, nil] generator

A small number > 1, typically 2 or 5.

@return [DH]

The newly generated key.

@note

jruby's openssl does not define `OpenSSL::PKey::DH.generate`.
See https://github.com/jruby/jruby-openssl/issues/254
Calls superclass method
# File lib/ronin/support/crypto/key/dh.rb, line 55
def self.generate(key_size=1024, generator: nil)
  new_key = allocate
  new_key.send(:initialize_copy,super(key_size,*generator))
  new_key
end

Public Instance Methods

g() click to toggle source

The ‘g` variable for the DH key.

@return [OpenSSL::BN]

@see rubydoc.info/stdlib/openssl/OpenSSL/BN

Calls superclass method
# File lib/ronin/support/crypto/key/dh.rb, line 94
def g
  super()
end
p() click to toggle source

The ‘p` variable for the DH key.

@return [OpenSSL::BN]

@see rubydoc.info/stdlib/openssl/OpenSSL/BN

Calls superclass method
# File lib/ronin/support/crypto/key/dh.rb, line 68
def p
  super()
end
q() click to toggle source

The ‘q` variable for the DH key.

@return [OpenSSL::BN, nil]

@see rubydoc.info/stdlib/openssl/OpenSSL/BN

@note

jruby's openssl does not implement `OpenSSL::PKey::DH#q`.
See https://github.com/jruby/jruby-openssl/issues/253
Calls superclass method
# File lib/ronin/support/crypto/key/dh.rb, line 83
def q
  super() unless RUBY_ENGINE == 'jruby'
end
save(path) click to toggle source

Saves the DH key to the given file.

@param [String] path

The path to the output file.
# File lib/ronin/support/crypto/key/dh.rb, line 114
def save(path)
  super(path)
end
size() click to toggle source

The size of the DH key in bits.

@return [Integer]

The key size in bits.
# File lib/ronin/support/crypto/key/dh.rb, line 104
def size
  p.num_bits
end