Class: Ccrypto::Ruby::ECCEngine

Inherits:
Object
  • Object
show all
Includes:
TR::CondUtils, TeLogger::TeLogHelper
Defined in:
lib/ccrypto/ruby/engines/ecc_engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ ECCEngine

Returns a new instance of ECCEngine.

Raises:

  • (KeypairEngineException)


181
182
183
184
185
# File 'lib/ccrypto/ruby/engines/ecc_engine.rb', line 181

def initialize(*args, &block)
  @config = args.first 
  raise KeypairEngineException, "1st parameter must be a #{Ccrypto::KeypairConfig.class} object" if not @config.is_a?(Ccrypto::KeypairConfig)
  teLogger.debug "Config #{@config}"
end

Class Method Details

.supported_curvesObject



174
175
176
177
178
179
# File 'lib/ccrypto/ruby/engines/ecc_engine.rb', line 174

def self.supported_curves
  if @curves.nil?
    @curves = OpenSSL::PKey::EC.builtin_curves.map { |c| Ccrypto::ECCConfig.new(c[0]) }
  end
  @curves
end

.verify(pubKey, val, sign) ⇒ Object



205
206
207
208
209
210
211
212
213
214
# File 'lib/ccrypto/ruby/engines/ecc_engine.rb', line 205

def self.verify(pubKey, val, sign)
  uPubKey = pubKey.native_pubKey
  if pubKey.native_pubKey.is_a?(OpenSSL::PKey::EC::Point)
    uPubKey = OpenSSL::PKey::EC.new(uPubKey.group)
    uPubKey.public_key = pubKey.native_pubKey
  end

  res = uPubKey.dsa_verify_asn1(val, sign)
  res
end

Instance Method Details

#generate_keypair(&block) ⇒ Object



187
188
189
190
191
192
# File 'lib/ccrypto/ruby/engines/ecc_engine.rb', line 187

def generate_keypair(&block)
  teLogger.debug "Generating keypair of curve #{@config.curve}"
  kp = OpenSSL::PKey::EC.generate(@config.curve.to_s) 
  #teLogger.debug "Generated keypair #{kp.inspect}"
  ECCKeyBundle.new(kp)
end

#sign(val) ⇒ Object

Raises:

  • (KeypairEngineException)


194
195
196
197
198
199
200
201
202
203
# File 'lib/ccrypto/ruby/engines/ecc_engine.rb', line 194

def sign(val)
  raise KeypairEngineException, "Keypair is required" if @config.keypair.nil?
  raise KeypairEngineException, "ECC keypair is required" if not @config.keypair.is_a?(ECCKeyBundle)
  kp = @config.keypair
  
  res = kp.nativeKeypair.dsa_sign_asn1(val)
  teLogger.debug "Data of length #{val.length} signed "

  res
end