Commit b6aee836 authored by Jesper Louis Andersen's avatar Jesper Louis Andersen
Browse files

Inject faults into iodata() values.

This further verifies the test cases and also the enacl API. By injecting
wrong data, we verify that given incorrect data will make the system fail
and error(badarg) all over the place.
parent b1ed21e7
...@@ -141,7 +141,7 @@ failure(_) -> false. ...@@ -141,7 +141,7 @@ failure(_) -> false.
prop_box_correct() -> prop_box_correct() ->
?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}}, ?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, nonce()), fault_rate(1, 40, nonce()),
fault_rate(1, 40, keypair()), fault_rate(1, 40, keypair()),
fault_rate(1, 40, keypair())}, fault_rate(1, 40, keypair())},
...@@ -161,7 +161,7 @@ prop_box_correct() -> ...@@ -161,7 +161,7 @@ prop_box_correct() ->
prop_box_failure_integrity() -> prop_box_failure_integrity() ->
?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}}, ?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, nonce()), fault_rate(1, 40, nonce()),
fault_rate(1, 40, keypair()), fault_rate(1, 40, keypair()),
fault_rate(1, 40, keypair())}, fault_rate(1, 40, keypair())},
...@@ -175,7 +175,7 @@ prop_box_failure_integrity() -> ...@@ -175,7 +175,7 @@ prop_box_failure_integrity() ->
Err = enacl:box_open([<<"x">>, CipherText], Nonce, PK1, SK2), Err = enacl:box_open([<<"x">>, CipherText], Nonce, PK1, SK2),
equals(Err, {error, failed_verification}); equals(Err, {error, failed_verification});
false -> false ->
case box(iolist_to_binary(Msg), Nonce, PK2, SK1) of case box(Msg, Nonce, PK2, SK1) of
badarg -> true; badarg -> true;
Res -> Res ->
failure(box_open(Res, Nonce, PK1, SK2)) failure(box_open(Res, Nonce, PK1, SK2))
...@@ -229,7 +229,9 @@ sign_keypair_valid(KP) -> ...@@ -229,7 +229,9 @@ sign_keypair_valid(KP) ->
sign_keypair_public_valid(KP) andalso sign_keypair_secret_valid(KP). sign_keypair_public_valid(KP) andalso sign_keypair_secret_valid(KP).
prop_sign() -> prop_sign() ->
?FORALL({Msg, KeyPair}, {g_iodata(), fault_rate(1, 40, sign_keypair())}, ?FORALL({Msg, KeyPair},
{fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, sign_keypair())},
begin begin
case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of
true -> true ->
...@@ -334,7 +336,7 @@ secretbox_open(Msg, Nonce, Key) -> ...@@ -334,7 +336,7 @@ secretbox_open(Msg, Nonce, Key) ->
prop_secretbox_correct() -> prop_secretbox_correct() ->
?FORALL({Msg, Nonce, Key}, ?FORALL({Msg, Nonce, Key},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, nonce()), fault_rate(1, 40, nonce()),
fault_rate(1, 40, secret_key())}, fault_rate(1, 40, secret_key())},
begin begin
...@@ -380,7 +382,7 @@ xor_bytes(<<>>, <<>>) -> []. ...@@ -380,7 +382,7 @@ xor_bytes(<<>>, <<>>) -> [].
prop_stream_xor_correct() -> prop_stream_xor_correct() ->
?FORALL({Msg, Nonce, Key}, ?FORALL({Msg, Nonce, Key},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, nonce()), fault_rate(1, 40, nonce()),
fault_rate(1, 40, secret_key())}, fault_rate(1, 40, secret_key())},
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of
...@@ -399,7 +401,7 @@ prop_stream_xor_correct() -> ...@@ -399,7 +401,7 @@ prop_stream_xor_correct() ->
%% CRYPTO AUTH %% CRYPTO AUTH
prop_auth_correct() -> prop_auth_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, secret_key())}, fault_rate(1, 40, secret_key())},
case v_iodata(Msg) andalso secret_key_valid(Key) of case v_iodata(Msg) andalso secret_key_valid(Key) of
true -> true ->
...@@ -414,7 +416,7 @@ authenticator_bad() -> ...@@ -414,7 +416,7 @@ authenticator_bad() ->
authenticator_good(Msg, Key) when is_binary(Key) -> authenticator_good(Msg, Key) when is_binary(Key) ->
Sz = enacl:secretbox_key_size(), Sz = enacl:secretbox_key_size(),
case byte_size(Key) == Sz of case v_iodata(Msg) andalso byte_size(Key) == Sz of
true -> true ->
frequency([{1, ?LAZY({invalid, binary(enacl:auth_size())})}, frequency([{1, ?LAZY({invalid, binary(enacl:auth_size())})},
{3, return({valid, enacl:auth(Msg, Key)})}]); {3, return({valid, enacl:auth(Msg, Key)})}]);
...@@ -433,7 +435,7 @@ authenticator_valid(_) -> false. ...@@ -433,7 +435,7 @@ authenticator_valid(_) -> false.
prop_auth_verify_correct() -> prop_auth_verify_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, secret_key())}, fault_rate(1, 40, secret_key())},
?FORALL(Authenticator, authenticator(Msg, Key), ?FORALL(Authenticator, authenticator(Msg, Key),
case v_iodata(Msg) andalso secret_key_valid(Key) andalso authenticator_valid(Authenticator) of case v_iodata(Msg) andalso secret_key_valid(Key) andalso authenticator_valid(Authenticator) of
...@@ -451,7 +453,7 @@ prop_auth_verify_correct() -> ...@@ -451,7 +453,7 @@ prop_auth_verify_correct() ->
%% CRYPTO ONETIME AUTH %% CRYPTO ONETIME AUTH
prop_onetimeauth_correct() -> prop_onetimeauth_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, secret_key())}, fault_rate(1, 40, secret_key())},
case v_iodata(Msg) andalso secret_key_valid(Key) of case v_iodata(Msg) andalso secret_key_valid(Key) of
true -> true ->
...@@ -466,7 +468,7 @@ ot_authenticator_bad() -> ...@@ -466,7 +468,7 @@ ot_authenticator_bad() ->
ot_authenticator_good(Msg, Key) when is_binary(Key) -> ot_authenticator_good(Msg, Key) when is_binary(Key) ->
Sz = enacl:secretbox_key_size(), Sz = enacl:secretbox_key_size(),
case byte_size(Key) == Sz of case v_iodata(Msg) andalso byte_size(Key) == Sz of
true -> true ->
frequency([{1, ?LAZY({invalid, binary(enacl:onetime_auth_size())})}, frequency([{1, ?LAZY({invalid, binary(enacl:onetime_auth_size())})},
{3, return({valid, enacl:onetime_auth(Msg, Key)})}]); {3, return({valid, enacl:onetime_auth(Msg, Key)})}]);
...@@ -485,7 +487,7 @@ ot_authenticator_valid(_) -> false. ...@@ -485,7 +487,7 @@ ot_authenticator_valid(_) -> false.
prop_onetime_auth_verify_correct() -> prop_onetime_auth_verify_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{g_iodata(), {fault_rate(1, 40, g_iodata()),
fault_rate(1, 40, secret_key())}, fault_rate(1, 40, secret_key())},
?FORALL(Authenticator, ot_authenticator(Msg, Key), ?FORALL(Authenticator, ot_authenticator(Msg, Key),
case v_iodata(Msg) andalso secret_key_valid(Key) andalso ot_authenticator_valid(Authenticator) of case v_iodata(Msg) andalso secret_key_valid(Key) andalso ot_authenticator_valid(Authenticator) of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment