lib/noise/functions/dh/ed448.rb in noise-ruby-0.8.4 vs lib/noise/functions/dh/ed448.rb in noise-ruby-0.9.4
- old
+ new
@@ -1,21 +1,35 @@
# frozen_string_literal: true
+begin
+ require 'ed448'
+ Ed448.init
+rescue LoadError
+end
+
module Noise
module Functions
module DH
class ED448
- DHLEN = 56
+ DHLEN = Ed448::X448::X448_PRIVATE_BYTES
+
def generate_keypair
- throw NotImplementedError
+ private_key = SecureRandom.random_bytes(DHLEN)
+ public_key = Ed448::X448.derive_public_key(private_key)
+ Noise::Key.new(private_key, public_key)
end
- def dh(_key_pair, _public_key)
- throw NotImplementedError
+ def dh(private_key, public_key)
+ Ed448::X448.dh(public_key, private_key)
end
def dhlen
DHLEN
+ end
+
+ def self.from_private(private_key)
+ public_key = Ed448::X448.derive_public_key(private_key)
+ Noise::Key.new(private_key, public_key)
end
end
end
end
end