Implement cryptography for secret boxes.

This commit is contained in:
Jesper Louis Andersen
2014-11-21 17:42:32 +01:00
parent ff5196b99f
commit c08f83a755
4 changed files with 187 additions and 9 deletions
+27 -3
View File
@@ -2,13 +2,14 @@
-include_lib("eqc/include/eqc.hrl").
-compile(export_all).
%% CRYPTO BOX
%% ---------------------------
nonce() ->
Sz = enacl:box_nonce_size(),
binary(Sz).
%% CRYPTO BOX
%% ---------------------------
prop_box_keypair() ->
?FORALL(_X, return(dummy),
ok_box(enacl:box_keypair())).
@@ -36,6 +37,29 @@ prop_box_failure_integrity() ->
equals(Err, {error, failed_verification})
end).
%% CRYPTO SECRET BOX
%% -------------------------------
secret_key() ->
Sz = enacl:secretbox_key_size(),
binary(Sz).
prop_secretbox_correct() ->
?FORALL({Msg, Nonce, Key}, {binary(), nonce(), secret_key()},
begin
CipherText = enacl:secretbox(Msg, Nonce, Key),
{ok, DecodedMsg} = enacl:secretbox_open(CipherText, Nonce, Key),
equals(Msg, DecodedMsg)
end).
prop_secretbox_failure_integrity() ->
?FORALL({Msg, Nonce, Key}, {binary(), nonce(), secret_key()},
begin
CipherText = enacl:secretbox(Msg, Nonce, Key),
Err = enacl:secretbox_open([<<"x">>, CipherText], Nonce, Key),
equals(Err, {error, failed_verification})
end).
%% HASHING
%% ---------------------------
diff_pair(Sz) ->