fixes #8.
This commit is contained in:
parent
87d1c12f5b
commit
3d700b6157
@ -1,5 +1,6 @@
|
||||
require "../../spec_helper"
|
||||
require "../../../src/sodium/sign/secret_key"
|
||||
require "../../../src/sodium/crypto_box/secret_key"
|
||||
|
||||
detached_test_vectors = [
|
||||
{
|
||||
@ -71,6 +72,12 @@ describe Sodium::Sign::SecretKey do
|
||||
end
|
||||
end
|
||||
|
||||
it "to_curve25519" do
|
||||
message = "foo"
|
||||
sskey = Sodium::Sign::SecretKey.new
|
||||
cskey = sskey.to_curve25519
|
||||
end
|
||||
|
||||
it "RbNaCl detached test vectors" do
|
||||
detached_test_vectors.each do |vec|
|
||||
seckey, plaintext, signature = sign_from_vec vec
|
||||
|
@ -55,6 +55,22 @@ class Sodium::CryptoBox
|
||||
end
|
||||
end
|
||||
|
||||
# Use existing secret and public keys.
|
||||
#
|
||||
# Takes ownership of an existing key in a SecureBuffer.
|
||||
# Recomputes the public key from a secret key if missing.
|
||||
def initialize(@sbuf : SecureBuffer, pkey : Bytes? = nil)
|
||||
raise ArgumentError.new("Secret key must be #{KEY_SIZE} bytes, got #{@sbuf.bytesize}") if @sbuf.bytesize != KEY_SIZE
|
||||
if pk = pkey
|
||||
@public_key = PublicKey.new pk
|
||||
else
|
||||
@public_key = PublicKey.new
|
||||
if LibSodium.crypto_scalarmult_base(@public_key.to_slice, self.to_slice) != 0
|
||||
raise Sodium::Error.new("crypto_scalarmult_base")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Use existing secret and public keys.
|
||||
#
|
||||
# Copies secret key to a SecureBuffer.
|
||||
|
@ -83,5 +83,12 @@ module Sodium
|
||||
end
|
||||
sig
|
||||
end
|
||||
|
||||
def to_curve25519 : CryptoBox::SecretKey
|
||||
key = SecureBuffer.new CryptoBox::SecretKey::KEY_SIZE
|
||||
LibSodium.crypto_sign_ed25519_sk_to_curve25519 key.to_slice, @sbuf.to_slice
|
||||
key.readonly
|
||||
CryptoBox::SecretKey.new key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user