Class: Noise::Functions::DH::Secp256k1
- Inherits:
-
Object
- Object
- Noise::Functions::DH::Secp256k1
- Defined in:
- lib/noise/functions/dh/secp256k1.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_private(private_key) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/noise/functions/dh/secp256k1.rb', line 33 def self.from_private(private_key) group = ECDSA::Group::Secp256k1 scalar = ECDSA::Format::IntegerOctetString.decode(private_key) point = group.generator.multiply_by_scalar(scalar) Noise::Key.new(private_key, ECDSA::Format::PointOctetString.encode(point, compression: true)) end |
Instance Method Details
#dh(private_key, public_key) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/noise/functions/dh/secp256k1.rb', line 22 def dh(private_key, public_key) key = ::Secp256k1::PublicKey.new(pubkey: public_key, raw: true) key.ecdh(private_key) rescue ::Secp256k1::AssertError => _ raise Noise::Exceptions::InvalidPublicKeyError, public_key end |
#dhlen ⇒ Object
29 30 31 |
# File 'lib/noise/functions/dh/secp256k1.rb', line 29 def dhlen 33 end |
#generate_keypair ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/noise/functions/dh/secp256k1.rb', line 12 def generate_keypair group = ECDSA::Group::Secp256k1 private_key = 1 + SecureRandom.random_number(group.order - 1) public_key = group.generator.multiply_by_scalar(private_key) Noise::Key.new( ECDSA::Format::IntegerOctetString.encode(private_key, 32), ECDSA::Format::PointOctetString.encode(public_key, compression: true) ) end |