add eddsa test
This commit is contained in:
parent
dad5bd9d35
commit
63c1fd453a
1 changed files with 51 additions and 8 deletions
|
|
@ -1,5 +1,8 @@
|
|||
let encode = B32.encode
|
||||
let decode s = B32.decode s |> Result.get_ok
|
||||
|
||||
let round_trip s =
|
||||
let s' = s |> B32.encode |> B32.decode |> Result.get_ok in
|
||||
let s' = s |> encode |> decode in
|
||||
match s' = s with
|
||||
| false -> Fmt.failwith "b32 round trip failure: @\nin :`%S`@\nout:`%S`" s' s
|
||||
| true -> ()
|
||||
|
|
@ -10,23 +13,63 @@ let () =
|
|||
let s_l = List.init 0x0f (fun i -> String.init i Char.chr) in
|
||||
List.iter round_trip s_l; ()
|
||||
|
||||
(* TODO *)
|
||||
(* test vectors from:
|
||||
https://git.gnunet.org/gnunet/gnunet/file/src/cli/util/crypto-test-vectors.json.html *)
|
||||
|
||||
let () =
|
||||
(* hash *)
|
||||
let input = "91JPRV3F5GG4EKJNDSJQ8" in
|
||||
let expected =
|
||||
"D0R24RZ1TPASVQ2NY56CT8AJDYZE9ZGDB0GVZ05E9D4YGZQW2RC5YFPQ0Q86EPW836DY7VYQTNFFJT3ZR2K508F4JVS5JNJKYN2MMFR"
|
||||
in
|
||||
let output =
|
||||
input
|
||||
|> B32.decode
|
||||
|> Result.get_ok
|
||||
|> Hash.H64.hash
|
||||
|> Hash.H64.to_octets
|
||||
|> B32.encode
|
||||
input |> decode |> Hash.H64.hash |> Hash.H64.to_octets |> encode
|
||||
in
|
||||
assert (output = expected);
|
||||
|
||||
()
|
||||
|
||||
let () =
|
||||
(* eddsa_key_derivation *)
|
||||
let pub = "3M9KK1WSNM1RTY5P72HKFA264V4B7MVHVJ08Y90CV06DYHV8XPP0" in
|
||||
let priv = "8QC2VNF8443S5KPNKMB4XMV58BTHWAKZ7SVW5WG3KRB37567XS90" in
|
||||
let pub' =
|
||||
let open Crypto in
|
||||
priv
|
||||
|> decode
|
||||
|> EddsaPrivateKey.of_octets
|
||||
|> Result.get_ok
|
||||
|> EddsaPrivateKey.pub_of_priv
|
||||
|> EddsaPublicKey.to_octets
|
||||
|> encode
|
||||
in
|
||||
assert (pub = pub');
|
||||
|
||||
()
|
||||
|
||||
let () =
|
||||
(* eddsa_signing *)
|
||||
let priv = "5077XJR9AMH4T97ACKFBVBJD0KFENHPV66B2Y1JBSKXBJKNZJ4E0" in
|
||||
let pub = "6E2F03JJ8AEDANTTZZ4SBZDFEEZSF8A9DVGTS6VFBCVZQYQ46RRG" in
|
||||
let data = "00000300000000000000" in
|
||||
let sig_ =
|
||||
"XCNJGJ96WPDH60YVMH6C74NGQSGJE3BC1TYMGX6BHY5DMZZZKTB373QTXJ507K5EBSG9YS2EYKHCX3ATRQ6P5MY9MXC4ZB1XSZ2X23G"
|
||||
in
|
||||
let open Crypto in
|
||||
let msg = decode data in
|
||||
let eddsa_priv =
|
||||
priv |> decode |> EddsaPrivateKey.of_octets |> Result.get_ok
|
||||
in
|
||||
let sig_' =
|
||||
EddsaSignature.sign ~key:eddsa_priv msg
|
||||
|> EddsaSignature.to_octets
|
||||
|> encode
|
||||
in
|
||||
assert (sig_ = sig_');
|
||||
let eddsa_pub = pub |> decode |> EddsaPublicKey.of_octets |> Result.get_ok in
|
||||
let eddsa_sig = sig_ |> decode |> EddsaSignature.of_octets |> Result.get_ok in
|
||||
let () =
|
||||
EddsaSignature.verify ~key:eddsa_pub eddsa_sig ~msg |> Result.get_ok
|
||||
in
|
||||
|
||||
()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue