Generate Sodium::Sign::SecretKey#seed.

master
Didactic Drunk 2020-07-18 22:49:13 -07:00
parent f0213b88c8
commit da188875c4
2 changed files with 7 additions and 6 deletions

View File

@ -49,7 +49,7 @@ describe Sodium::Sign::SecretKey do
it "seed keys" do
seed = Bytes.new Sodium::Sign::SecretKey::SEED_SIZE
key1 = Sodium::Sign::SecretKey.new seed: seed
key2 = Sodium::Sign::SecretKey.new seed: seed
key2 = Sodium::Sign::SecretKey.new seed: Sodium::Sign::SecretKey.new(key1.to_slice).seed
key1.to_slice.should eq key2.to_slice
key1.public_key.to_slice.should eq key2.public_key.to_slice
key1.seed.should eq seed

View File

@ -23,8 +23,6 @@ module Sodium
# Returns key
delegate_to_slice to: @sbuf
@seed : SecureBuffer?
# Generates a new random secret/public key pair.
def initialize
@sbuf = SecureBuffer.new KEY_SIZE
@ -70,9 +68,12 @@ module Sodium
end
end
def seed
# BUG: Generate seed if not set.
@seed.not_nil!.to_slice
getter seed : SecureBuffer? do
SecureBuffer.new(SEED_SIZE).tap do |s|
if LibSodium.crypto_sign_ed25519_sk_to_seed(s.to_slice, self.to_slice) != 0
raise Sodium::Error.new("crypto_sign_ed25519_sk_to_seed")
end
end.readonly
end
# Signs message and returns a detached signature.