Implement crypto boxing/unboxing for public key cryptographic systems.
This commit is contained in:
@@ -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
|
||||
%% ---------------------------
|
||||
|
||||
Reference in New Issue
Block a user