Class: ECC::PrivateKey
- Inherits:
-
Object
- Object
- ECC::PrivateKey
- Defined in:
- lib/elliptic-lite/signature.rb
Instance Method Summary collapse
-
#initialize(secret, group: SECP256K1) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
- #public_key ⇒ Object (also: #pubkey)
- #sign(z) ⇒ Object
Constructor Details
#initialize(secret, group: SECP256K1) ⇒ PrivateKey
Returns a new instance of PrivateKey.
42 43 44 45 |
# File 'lib/elliptic-lite/signature.rb', line 42 def initialize( secret, group: SECP256K1 ) @secret = secret @group = group end |
Instance Method Details
#public_key ⇒ Object Also known as: pubkey
47 48 49 |
# File 'lib/elliptic-lite/signature.rb', line 47 def public_key @pubkey ||= PublicKey.new( @secret * @group.g, group: @group ) end |
#sign(z) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/elliptic-lite/signature.rb', line 52 def sign( z ) k = 1 + SecureRandom.random_number( @group.n - 1) # k = 1234567890 r = (k*@group.g).x k_inv = k.pow( @group.n-2, @group.n ) s = (z+r*@secret) * k_inv % @group.n s = @group.n - s if s > @group.n/2 Signature.new( r, s ) end |