Class: Ronin::Support::Crypto::Key::EC

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

Overview

Represents an EC key.

Examples

List supported curves

Crypto::Key::EC.supported_curves
# => ["secp224r1", "secp256k1", "secp384r1", "secp521r1", "prime256v1"]

Generate a random key

ec = Crypto::Key::EC.random("secp224r1")

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Methods

included, #save

Constructor Details

#initialize(*args) ⇒ EC

Note:

Will print a warning message when running on JRuby about jruby-openssl's EC key bugs:

Initializes the EC key.

Parameters:

  • args (Array)

    Additional arguments.

Since:

  • 1.0.0



85
86
87
88
89
90
91
92
93
# File 'lib/ronin/support/crypto/key/ec.rb', line 85

def initialize(*args)
  if RUBY_ENGINE == 'jruby'
    warn "WARNING: jruby-openssl has multiple bugs wrt parsing EC keys"
    warn " * https://github.com/jruby/jruby-openssl/issues/256"
    warn " * https://github.com/jruby/jruby-openssl/issues/257"
  end

  super(*args)
end

Class Method Details

.generate(curve = 'prime256v1') ⇒ EC

Generates a new random EC key.

Parameters:

Returns:

  • (EC)

    The newly generated key.

Since:

  • 1.0.0



69
70
71
# File 'lib/ronin/support/crypto/key/ec.rb', line 69

def self.generate(curve='prime256v1')
  super(curve)
end

.supported_curvesArray<String>

The supported elliptical curves.

Returns:

Since:

  • 1.0.0



56
57
58
# File 'lib/ronin/support/crypto/key/ec.rb', line 56

def self.supported_curves
  builtin_curves.map { |(name,desc)| name }
end

Instance Method Details

#curveString

The Elliptical Curve name.

Returns:

Since:

  • 1.1.0



102
103
104
# File 'lib/ronin/support/crypto/key/ec.rb', line 102

def curve
  group.curve_name
end

#sizeInteger?

The size of the EC key in bits.

Returns:

Since:

  • 1.1.0



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

def size
  if (match = to_text.match(/\((\d+) bit\)/))
    match[1].to_i
  end
end