Add Sodium::Sign::SecretKey detached test vectors.

master
Didactic Drunk 2019-08-06 02:20:47 -07:00
parent 4be74741d5
commit 8ca9dc6ff9
2 changed files with 34 additions and 1 deletions

View File

@ -19,7 +19,7 @@ Crystal bindings for the [libsodium API](https://libsodium.gitbook.io/doc/)
- [x] ☑ [Crypto Box Easy](https://libsodium.gitbook.io/doc/public-key_cryptography/authenticated_encryption) - [x] ☑ [Crypto Box Easy](https://libsodium.gitbook.io/doc/public-key_cryptography/authenticated_encryption)
- [x] [Sealed Box](https://libsodium.gitbook.io/doc/public-key_cryptography/sealed_boxes) - [x] [Sealed Box](https://libsodium.gitbook.io/doc/public-key_cryptography/sealed_boxes)
- [ ] [Combined Signatures](https://libsodium.gitbook.io/doc/public-key_cryptography/public-key_signatures) - [ ] [Combined Signatures](https://libsodium.gitbook.io/doc/public-key_cryptography/public-key_signatures)
- [x] [Detached Signatures](https://libsodium.gitbook.io/doc/public-key_cryptography/public-key_signatures) - [x] [Detached Signatures](https://libsodium.gitbook.io/doc/public-key_cryptography/public-key_signatures)
- [Secret-Key Cryptography](https://libsodium.gitbook.io/doc/secret-key_cryptography) - [Secret-Key Cryptography](https://libsodium.gitbook.io/doc/secret-key_cryptography)
- Secret Box - Secret Box
- [x] ☑ [Combined mode](https://libsodium.gitbook.io/doc/secret-key_cryptography/authenticated_encryption) - [x] ☑ [Combined mode](https://libsodium.gitbook.io/doc/secret-key_cryptography/authenticated_encryption)

View File

@ -1,6 +1,31 @@
require "../../spec_helper" require "../../spec_helper"
require "../../../src/sodium/sign/secret_key" require "../../../src/sodium/sign/secret_key"
detached_test_vectors = [
{
seed: "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd",
secret_key: "b18e1d0045995ec3d010c387ccfeb984d783af8fbb0f40fa7db126d889f6dadd" \
"77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb",
public_key: "77f48b59caeda77751ed138b0ec667ff50f8768c25d48309a8f386a2bad187fb",
plaintext: "916c7d1d268fc0e77c1bef238432573c39be577bbea0998936add2b50a653171" \
"ce18a542b0b7f96c1691a3be6031522894a8634183eda38798a0c5d5d79fbd01" \
"dd04a8646d71873b77b221998a81922d8105f892316369d5224c9983372d2313" \
"c6b1f4556ea26ba49d46e8b561e0fc76633ac9766e68e21fba7edca93c4c7460" \
"376d7f3ac22ff372c18f613f2ae2e856af40",
signature: "6bd710a368c1249923fc7a1610747403040f0cc30815a00f9ff548a896bbda0b" \
"4eb2ca19ebcf917f0f34200a9edbad3901b64ab09cc5ef7b9bcc3c40c0ff7509",
},
]
private def sign_from_vec(vec)
seckey = Sodium::Sign::SecretKey.new seed: vec[:seed].hexbytes
seckey.to_slice.should eq vec[:secret_key].hexbytes
seckey.public_key.to_slice.should eq vec[:public_key].hexbytes
plaintext = vec[:plaintext].hexbytes
signature = vec[:signature].hexbytes
{seckey, plaintext, signature}
end
private def new_sign_key_to_slice private def new_sign_key_to_slice
Sodium::Sign::SecretKey.new.to_slice Sodium::Sign::SecretKey.new.to_slice
end end
@ -45,4 +70,12 @@ describe Sodium::Sign::SecretKey do
skey.public_key.verify_detached "bar", sig skey.public_key.verify_detached "bar", sig
end end
end end
it "RbNaCl detached test vectors" do
detached_test_vectors.each do |vec|
seckey, plaintext, signature = sign_from_vec vec
sig = seckey.sign_detached plaintext
sig.should eq signature
end
end
end end