Class: CryptoGost::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_gost/create.rb

Overview

DigitalSignature

Author:

  • WildDima

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, group, signature_adapter: Signature, create_hash: Stribog::CreateHash) ⇒ Create

Returns a new instance of Create.



11
12
13
14
15
16
17
# File 'lib/crypto_gost/create.rb', line 11

def initialize(message, group, signature_adapter: Signature,
                               create_hash: Stribog::CreateHash)
  @signature_adapter = signature_adapter
  @create_hash = create_hash
  @message = message
  @group = group
end

Instance Attribute Details

#create_hashObject (readonly)

Returns the value of attribute create_hash.



9
10
11
# File 'lib/crypto_gost/create.rb', line 9

def create_hash
  @create_hash
end

#groupObject (readonly)

Returns the value of attribute group.



9
10
11
# File 'lib/crypto_gost/create.rb', line 9

def group
  @group
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



9
10
11
# File 'lib/crypto_gost/create.rb', line 9

def public_key
  @public_key
end

#signature_adapterObject (readonly)

Returns the value of attribute signature_adapter.



9
10
11
# File 'lib/crypto_gost/create.rb', line 9

def signature_adapter
  @signature_adapter
end

Instance Method Details

#call(private_key) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/crypto_gost/create.rb', line 19

def call(private_key)
  @private_key = private_key
  loop do
    rand_val = SecureRandom.random_number(1..group.order)
    r = r_func(rand_val)
    s = s_func(rand_val, private_key)
    break new_signature(r: r, s: s) if !r.zero? || !s.zero?
  end
end