Implement crypto boxing/unboxing for public key cryptographic systems.

This commit is contained in:
Jesper Louis Andersen
2014-11-21 13:40:47 +01:00
parent c074a4b186
commit ff5196b99f
3 changed files with 76 additions and 6 deletions
+23
View File
@@ -5,6 +5,10 @@
%% CRYPTO BOX
%% ---------------------------
nonce() ->
Sz = enacl:box_nonce_size(),
binary(Sz).
prop_box_keypair() ->
?FORALL(_X, return(dummy),
ok_box(enacl:box_keypair())).
@@ -12,6 +16,25 @@ prop_box_keypair() ->
ok_box({ok, _PK, _SK}) -> true;
ok_box(_) -> false.
prop_box_correct() ->
?FORALL({Msg, Nonce}, {binary(), nonce()},
begin
{ok, PK1, SK1} = enacl:box_keypair(),
{ok, PK2, SK2} = enacl:box_keypair(),
CipherText = enacl:box(Msg, Nonce, PK2, SK1),
{ok, DecodedMsg} = enacl:box_open(CipherText, Nonce, PK1, SK2),
equals(Msg, DecodedMsg)
end).
prop_box_failure_integrity() ->
?FORALL({Msg, Nonce}, {binary(), nonce()},
begin
{ok, PK1, SK1} = enacl:box_keypair(),
{ok, PK2, SK2} = enacl:box_keypair(),
CipherText = enacl:box(Msg, Nonce, PK2, SK1),
Err = enacl:box_open([<<"x">>, CipherText], Nonce, PK1, SK2),
equals(Err, {error, failed_verification})
end).
%% HASHING
%% ---------------------------