Sha256: 835b3f5193873fb4b200759ac9939a28f544e87df38f3697c1226a4bb8555dff

Contents?: true

Size: 988 Bytes

Versions: 11

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module Noise
  module Functions
    module DH
      class ED25519
        DHLEN = 32
        def generate_keypair
          private_key = 1 + SecureRandom.random_number(RbNaCl::GroupElement::STANDARD_GROUP_ORDER - 1)
          scalar_as_string = ECDSA::Format::IntegerOctetString.encode(private_key, 32)
          public_key = RbNaCl::GroupElements::Curve25519.base.mult(scalar_as_string)
          [ECDSA::Format::IntegerOctetString.encode(private_key, 32), public_key.to_bytes]
        end

        def dh(private_key, public_key)
          RbNaCl::GroupElement.new(public_key).mult(private_key).to_bytes
        end

        def dhlen
          DHLEN
        end

        def self.from_private(private_key)
          public_key = RbNaCl::GroupElements::Curve25519.base.mult(private_key)
          [private_key, public_key.to_bytes]
        end

        def self.from_public(public_key)
          [nil, public_key]
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
noise-ruby-0.7.1 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.7.0 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.6.3 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.6.2 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.6.1 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.6.0 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.5.3 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.5.2 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.5.1 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.5.0 lib/noise/functions/dh/ed25519.rb
noise-ruby-0.3.0 lib/noise/functions/dh/ed25519.rb