Commit f64e62d1 authored by Jesper Louis Andersen's avatar Jesper Louis Andersen
Browse files

Provide correctness test cases for the verification codes.

parent dc78d268
......@@ -216,3 +216,53 @@ prop_crypto_hash_neq() ->
enacl:hash(X) /= enacl:hash(Y)
)).
%% STRING COMPARISON
%% -------------------------
verify_pair_bad(Sz) ->
?LET(X, elements([fst, snd]),
case X of
fst ->
{?SUCHTHAT(B, binary(), byte_size(B) /= Sz), binary(Sz)};
snd ->
{binary(Sz), ?SUCHTHAT(B, binary(), byte_size(B) /= Sz)}
end).
verify_pair_good(Sz) ->
oneof([
?LET(Bin, binary(Sz), {Bin, Bin}),
?SUCHTHAT({X, Y}, {binary(Sz), binary(Sz)}, X /= Y)]).
verify_pair(Sz) ->
fault(verify_pair_bad(Sz), verify_pair_good(Sz)).
verify_pair_valid(Sz, X, Y) ->
byte_size(X) == Sz andalso byte_size(Y) == Sz.
prop_verify_16() ->
?FORALL({X, Y}, verify_pair(16),
case verify_pair_valid(16, X, Y) of
true ->
equals(X == Y, enacl:verify_16(X, Y));
false ->
try
enacl:verify_16(X, Y),
false
catch
error:badarg -> true
end
end).
prop_verify_32() ->
?FORALL({X, Y}, verify_pair(32),
case verify_pair_valid(32, X, Y) of
true ->
equals(X == Y, enacl:verify_32(X, Y));
false ->
try
enacl:verify_32(X, Y),
false
catch
error:badarg -> true
end
end).
\ No newline at end of file
......@@ -19,12 +19,20 @@
]).
-export([
hash/1
hash/1,
verify_16/2,
verify_32/2
]).
hash(Bin) ->
enacl_nif:crypto_hash(Bin).
%% Low level helper functions
%% -----------------
hash(Bin) -> enacl_nif:crypto_hash(Bin).
verify_16(X, Y) -> enacl_nif:crypto_verify_16(X, Y).
verify_32(X, Y) -> enacl_nif:crypto_verify_32(X, Y).
%% Public Key Crypto
%% ---------------------
box_keypair() ->
enacl_nif:crypto_box_keypair().
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment