From 7181600cb4a53c661ee50f07384840aef8829f58 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Mon, 5 Mar 2018 09:53:08 +0100 Subject: [PATCH] Simple QuickCheck properties for ChaCha20Poly1305 --- eqc_test/enacl_eqc.erl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/eqc_test/enacl_eqc.erl b/eqc_test/enacl_eqc.erl index 3bc2987..c7b4bf2 100644 --- a/eqc_test/enacl_eqc.erl +++ b/eqc_test/enacl_eqc.erl @@ -219,7 +219,7 @@ prop_box_failure_integrity() -> end end end). - + prop_seal_box_failure_integrity() -> ?FORALL({Msg, {PK1, SK1}}, {?FAULT_RATE(1,40,g_iodata()), ?FAULT_RATE(1,40,keypair())}, begin @@ -783,6 +783,26 @@ badargs(Thunk) -> error:badarg -> true end. +%% AEAD ChaCha20Poly1305 +prop_aead_chacha20poly1305() -> + ?FORALL({Key, Msg, AD, Nonce}, + {binary(32), binary(), ?LET(ADBytes, choose(0,16), binary(ADBytes)), largeint()}, + begin + EncryptMsg = enacl:aead_chacha20poly1305_encrypt(Key, Nonce, AD, Msg), + equals(enacl:aead_chacha20poly1305_decrypt(Key, Nonce, AD, EncryptMsg), Msg) + end). + +prop_aead_chacha20poly1305_fail() -> + ?FORALL({Key, Msg, AD, Nonce}, + {binary(32), binary(), ?LET(ADBytes, choose(0,16), binary(ADBytes)), largeint()}, + begin + EncryptMsg = enacl:aead_chacha20poly1305_encrypt(Key, Nonce, AD, Msg), + case enacl:aead_chacha20poly1305_decrypt(Key, Nonce, AD, <<0:8, EncryptMsg/binary>>) of + {error, _} -> true; + _ -> false + end + end). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Joel Test Blobs