Sha256: 713d8104afc3ab810e7faa0ebecb2c434d1d4aa484aacbc6d7bea16314f9d8fb

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 KB

Contents

gem 'x25519' # raise if the gem x25519 is not installed

require 'x25519'
require 'net/ssh/transport/constants'
require 'net/ssh/transport/kex/abstract5656'

module Net
  module SSH
    module Transport
      module Kex
        # A key-exchange service implementing the "curve25519-sha256@libssh.org"
        # key-exchange algorithm. (defined in https://tools.ietf.org/html/draft-ietf-curdle-ssh-curves-06)
        class Curve25519Sha256 < Abstract5656
          def digester
            OpenSSL::Digest::SHA256
          end

          private

          def generate_key #:nodoc:
            ::X25519::Scalar.generate
          end

          ## string   Q_C, client's ephemeral public key octet string
          def ecdh_public_key_bytes
            ecdh.public_key.to_bytes
          end

          # compute shared secret from server's public key and client's private key
          def compute_shared_secret(server_ecdh_pubkey)
            pk = ::X25519::MontgomeryU.new(server_ecdh_pubkey)
            OpenSSL::BN.new(ecdh.diffie_hellman(pk).to_bytes, 2)
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 16 versions & 2 rubygems

Version Path
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/kex/curve25519_sha256.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/kex/curve25519_sha256.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/kex/curve25519_sha256.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.2.0.rc1/lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.2.0.rc2 lib/net/ssh/transport/kex/curve25519_sha256.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.2.0.rc1/lib/net/ssh/transport/kex/curve25519_sha256.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.2.0.rc1 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.2.0.beta1 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.1.0 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.1.0.rc1 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.0.2 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.0.1 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.0.0 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.0.0.rc1 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.0.0.beta2 lib/net/ssh/transport/kex/curve25519_sha256.rb
net-ssh-6.0.0.beta1 lib/net/ssh/transport/kex/curve25519_sha256.rb