Implement cryptography for secret boxes.
This commit is contained in:
+27
-3
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user