class CryptoGost::Create
DigitalSignature
@author WildDima
Attributes
create_hash[R]
group[R]
public_key[R]
signature_adapter[R]
Public Class Methods
new(message, group, signature_adapter: Signature, create_hash: Stribog::CreateHash)
click to toggle source
# 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
Public Instance Methods
call(private_key)
click to toggle source
# 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
Private Instance Methods
hash_message(message, size: 256)
click to toggle source
# File lib/crypto_gost/create.rb, line 31 def hash_message(message, size: 256) new_hash(message, size: size) end
hash_mod_ecn()
click to toggle source
# File lib/crypto_gost/create.rb, line 44 def hash_mod_ecn hashed = hash_message(@message, size: 256).dec hashed.zero? ? 1 : hashed end
new_hash(message, size: 256)
click to toggle source
# File lib/crypto_gost/create.rb, line 53 def new_hash(message, size: 256) create_hash.new(message).(size) end
new_signature(keys)
click to toggle source
# File lib/crypto_gost/create.rb, line 49 def new_signature(keys) signature_adapter.new(r: keys[:r], s: keys[:s]) end
r_func(rand_val)
click to toggle source
# File lib/crypto_gost/create.rb, line 35 def r_func(rand_val) (group.generator * rand_val).x % group.order end
s_func(rand_val, private_key)
click to toggle source
# File lib/crypto_gost/create.rb, line 39 def s_func(rand_val, private_key) (r_func(rand_val) * private_key + rand_val * hash_mod_ecn) % group.order end