master
Didactic Drunk 2020-07-10 17:06:53 -07:00
parent 87d1c12f5b
commit 3d700b6157
4 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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.

View File

@ -379,7 +379,7 @@ module Sodium
fun crypto_sign_ed25519_seed_keypair(pk : UInt8*, sk : UInt8*, seed : UInt8*) : LibC::Int
fun crypto_sign_ed25519_seedbytes : LibC::SizeT
fun crypto_sign_ed25519_sk_to_curve25519(curve25519_sk : UInt8*, ed25519_sk : UInt8*) : LibC::Int
# fun crypto_sign_ed25519_sk_to_pk(pk : UInt8*, sk : UInt8*) : LibC::Int
# fun crypto_sign_ed25519_sk_to_pk(pk : UInt8*, sk : UInt8*) : LibC::Int
fun crypto_sign_ed25519_sk_to_seed(seed : UInt8*, sk : UInt8*) : LibC::Int
fun crypto_sign_ed25519_verify_detached(sig : UInt8*, m : UInt8*, mlen : LibC::ULongLong, pk : UInt8*) : LibC::Int
fun crypto_sign_ed25519ph_final_create(state : CryptoSignEd25519phState*, sig : UInt8*, siglen_p : LibC::ULongLong*, sk : UInt8*) : LibC::Int

View File

@ -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