Class: Ronin::Support::Crypto::Key::DH

Inherits:
OpenSSL::PKey::DH
  • Object
show all
Includes:
Methods
Defined in:
lib/ronin/support/crypto/key/dh.rb

Overview

Represents an Diffie-Hellman (DH) key.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Methods

included

Class Method Details

.generate(key_size = 1024, generator: nil) ⇒ DH

Note:

jruby's openssl does not define OpenSSL::PKey::DH.generate. See https://github.com/jruby/jruby-openssl/issues/254

Generates a new DH key.

Parameters:

  • key_size (Integer) (defaults to: 1024)

    The size of the key in bits.

  • generator (Integer, nil) (defaults to: nil)

    A small number > 1, typically 2 or 5.

Returns:

  • (DH)

    The newly generated key.

Since:

  • 1.0.0



55
56
57
58
59
# 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

Instance Method Details

#gOpenSSL::BN

The g variable for the DH key.

Returns:

  • (OpenSSL::BN)

See Also:

Since:

  • 1.0.0



94
95
96
# File 'lib/ronin/support/crypto/key/dh.rb', line 94

def g
  super()
end

#pOpenSSL::BN

The p variable for the DH key.

Returns:

  • (OpenSSL::BN)

See Also:

Since:

  • 1.0.0



68
69
70
# File 'lib/ronin/support/crypto/key/dh.rb', line 68

def p
  super()
end

#qOpenSSL::BN?

Note:

jruby's openssl does not implement OpenSSL::PKey::DH#q. See https://github.com/jruby/jruby-openssl/issues/253

The q variable for the DH key.

Returns:

  • (OpenSSL::BN, nil)

See Also:

Since:

  • 1.0.0



83
84
85
# File 'lib/ronin/support/crypto/key/dh.rb', line 83

def q
  super() unless RUBY_ENGINE == 'jruby'
end

#save(path) ⇒ Object

Saves the DH key to the given file.

Parameters:

  • path (String)

    The path to the output file.

Since:

  • 1.0.0



114
115
116
# File 'lib/ronin/support/crypto/key/dh.rb', line 114

def save(path)
  super(path)
end

#sizeInteger

The size of the DH key in bits.

Returns:

  • (Integer)

    The key size in bits.

Since:

  • 1.0.0



104
105
106
# File 'lib/ronin/support/crypto/key/dh.rb', line 104

def size
  p.num_bits
end