replace xrouter_clientd with xrouter_procd
This commit is contained in:
parent
207ec85f8c
commit
fd796440db
3
Makefile
3
Makefile
@ -7,6 +7,9 @@ compile:
|
||||
eqc_compile: compile
|
||||
erlc -o _build/default/lib/enacl/ebin eqc_test/enacl_eqc.erl
|
||||
|
||||
eqc_mini_compile: compile
|
||||
erlc -Dmini -o _build/default/lib/enacl/ebin eqc_test/enacl_eqc.erl
|
||||
|
||||
.PHONE: console
|
||||
console: compile
|
||||
$(REBAR) shell
|
||||
|
@ -2,11 +2,19 @@
|
||||
-include_lib("eqc/include/eqc.hrl").
|
||||
-compile(export_all).
|
||||
|
||||
%% -compile({parse_transform, eqc_parallelize}).
|
||||
-ifndef(mini).
|
||||
-compile({parse_transform, eqc_parallelize}).
|
||||
-define(FAULT(Arg1, Arg2), eqc:fault(Arg1, Arg2)).
|
||||
-define(FAULT_RATE(Arg1, Arg2, Arg3), eqc:fault_rate(Arg1, Arg2, Arg3)).
|
||||
-else.
|
||||
-define(FAULT(Arg1, Arg2), noop_fault(Arg1, Arg2)).
|
||||
-define(FAULT_RATE(Arg1, Arg2, Arg3), noop_fault_rate(Arg1, Arg2, Arg3)).
|
||||
-endif.
|
||||
|
||||
z_fault(_Bad, Good) -> Good.
|
||||
|
||||
z_fault_rate(_1, _2, Gen) -> Gen.
|
||||
noop_fault(_Bad, Good) -> Good.
|
||||
|
||||
noop_fault_rate(_1, _2, Gen) -> Gen.
|
||||
|
||||
non_byte_int() ->
|
||||
oneof([
|
||||
@ -18,7 +26,7 @@ g_iolist() ->
|
||||
?SIZED(Sz, g_iolist(Sz)).
|
||||
|
||||
g_iolist(0) ->
|
||||
z_fault(
|
||||
?FAULT(
|
||||
oneof([
|
||||
elements([a,b,c]),
|
||||
real(),
|
||||
@ -26,7 +34,7 @@ g_iolist(0) ->
|
||||
]),
|
||||
return([]));
|
||||
g_iolist(N) ->
|
||||
z_fault(
|
||||
?FAULT(
|
||||
oneof([
|
||||
elements([a,b,c]),
|
||||
real(),
|
||||
@ -38,7 +46,7 @@ g_iolist(N) ->
|
||||
])).
|
||||
|
||||
g_iodata() ->
|
||||
z_fault(
|
||||
?FAULT(
|
||||
oneof([elements([a,b,c]), real()]),
|
||||
oneof([binary(), g_iolist(), eqc_gen:largebinary(64*1024)])).
|
||||
|
||||
@ -54,7 +62,7 @@ v_iodata(Structure) -> v_iolist(Structure).
|
||||
|
||||
%% Generator for binaries of a given size with different properties and fault injection:
|
||||
g_binary(Sz) ->
|
||||
z_fault(g_binary_bad(Sz), g_binary_good(Sz)).
|
||||
?FAULT(g_binary_bad(Sz), g_binary_good(Sz)).
|
||||
|
||||
g_binary_good(Sz) when Sz =< 32 -> binary(Sz);
|
||||
g_binary_good(Sz) -> eqc_gen:largebinary(Sz).
|
||||
@ -78,7 +86,7 @@ nonce_valid(N) -> v_binary(enacl:box_nonce_size(), N).
|
||||
|
||||
%% Generator of natural numbers
|
||||
g_nat() ->
|
||||
z_fault(g_nat_bad(), nat()).
|
||||
?FAULT(g_nat_bad(), nat()).
|
||||
|
||||
g_nat_bad() ->
|
||||
oneof([
|
||||
@ -110,7 +118,7 @@ keypair_bad() ->
|
||||
end).
|
||||
|
||||
keypair() ->
|
||||
z_fault(keypair_bad(), keypair_good()).
|
||||
?FAULT(keypair_bad(), keypair_good()).
|
||||
|
||||
%% CRYPTO BOX
|
||||
%% ---------------------------
|
||||
@ -162,10 +170,10 @@ failure(X) -> {failure, X}.
|
||||
|
||||
prop_box_correct() ->
|
||||
?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, nonce()),
|
||||
z_fault_rate(1, 40, keypair()),
|
||||
z_fault_rate(1, 40, keypair())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, nonce()),
|
||||
?FAULT_RATE(1, 40, keypair()),
|
||||
?FAULT_RATE(1, 40, keypair())},
|
||||
begin
|
||||
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of
|
||||
true ->
|
||||
@ -186,10 +194,10 @@ prop_box_correct() ->
|
||||
|
||||
prop_box_failure_integrity() ->
|
||||
?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, nonce()),
|
||||
z_fault_rate(1, 40, keypair()),
|
||||
z_fault_rate(1, 40, keypair())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, nonce()),
|
||||
?FAULT_RATE(1, 40, keypair()),
|
||||
?FAULT_RATE(1, 40, keypair())},
|
||||
begin
|
||||
case v_iodata(Msg)
|
||||
andalso nonce_valid(Nonce)
|
||||
@ -211,7 +219,7 @@ prop_box_failure_integrity() ->
|
||||
end).
|
||||
|
||||
prop_seal_box_failure_integrity() ->
|
||||
?FORALL({Msg, {PK1, SK1}}, {z_fault_rate(1,40,g_iodata()), z_fault_rate(1,40,keypair())},
|
||||
?FORALL({Msg, {PK1, SK1}}, {?FAULT_RATE(1,40,g_iodata()), ?FAULT_RATE(1,40,keypair())},
|
||||
begin
|
||||
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
|
||||
true ->
|
||||
@ -229,8 +237,8 @@ prop_seal_box_failure_integrity() ->
|
||||
|
||||
prop_seal_box_correct() ->
|
||||
?FORALL({Msg, {PK1, SK1}},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, keypair())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, keypair())},
|
||||
begin
|
||||
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
|
||||
true ->
|
||||
@ -247,7 +255,7 @@ prop_seal_box_correct() ->
|
||||
|
||||
%% PRECOMPUTATIONS
|
||||
beforenm_key() ->
|
||||
?LET([{PK1, SK1}, {PK2, SK2}], [z_fault_rate(1, 40, keypair()), z_fault_rate(1, 40, keypair())],
|
||||
?LET([{PK1, SK1}, {PK2, SK2}], [?FAULT_RATE(1, 40, keypair()), ?FAULT_RATE(1, 40, keypair())],
|
||||
case keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of
|
||||
true ->
|
||||
enacl:box_beforenm(PK1, SK2);
|
||||
@ -263,7 +271,7 @@ v_key(K) when is_binary(K) -> byte_size(K) == enacl:box_beforenm_bytes();
|
||||
v_key(_) -> false.
|
||||
|
||||
prop_beforenm_correct() ->
|
||||
?FORALL([{PK1, SK1}, {PK2, SK2}], [z_fault_rate(1, 40, keypair()), z_fault_rate(1, 40, keypair())],
|
||||
?FORALL([{PK1, SK1}, {PK2, SK2}], [?FAULT_RATE(1, 40, keypair()), ?FAULT_RATE(1, 40, keypair())],
|
||||
case keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of
|
||||
true ->
|
||||
equals(enacl:box_beforenm(PK1, SK2), enacl:box_beforenm(PK2, SK1));
|
||||
@ -276,9 +284,9 @@ prop_beforenm_correct() ->
|
||||
|
||||
prop_afternm_correct() ->
|
||||
?FORALL([Msg, Nonce, Key],
|
||||
[z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, nonce()),
|
||||
z_fault_rate(1, 40, beforenm_key())],
|
||||
[?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, nonce()),
|
||||
?FAULT_RATE(1, 40, beforenm_key())],
|
||||
begin
|
||||
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso v_key(Key) of
|
||||
true ->
|
||||
@ -329,7 +337,7 @@ sign_keypair_good() ->
|
||||
return(enacl:sign_keypair()).
|
||||
|
||||
sign_keypair() ->
|
||||
z_fault(sign_keypair_bad(), sign_keypair_good()).
|
||||
?FAULT(sign_keypair_bad(), sign_keypair_good()).
|
||||
|
||||
sign_keypair_public_valid(#{ public := Public })
|
||||
when is_binary(Public) ->
|
||||
@ -346,8 +354,8 @@ sign_keypair_valid(KP) ->
|
||||
|
||||
prop_sign_detached() ->
|
||||
?FORALL({Msg, KeyPair},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, sign_keypair())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, sign_keypair())},
|
||||
begin
|
||||
case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of
|
||||
true ->
|
||||
@ -362,8 +370,8 @@ prop_sign_detached() ->
|
||||
|
||||
prop_sign() ->
|
||||
?FORALL({Msg, KeyPair},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, sign_keypair())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, sign_keypair())},
|
||||
begin
|
||||
case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of
|
||||
true ->
|
||||
@ -407,10 +415,10 @@ signed_message_bad_d() ->
|
||||
{binary(), oneof([a, int(), ?SUCHTHAT(B, binary(Sz), byte_size(B) /= Sz)])}.
|
||||
|
||||
signed_message(M) ->
|
||||
z_fault(signed_message_bad(), signed_message_good(M)).
|
||||
?FAULT(signed_message_bad(), signed_message_good(M)).
|
||||
|
||||
signed_message_d(M) ->
|
||||
z_fault(signed_message_bad(), signed_message_good(M)).
|
||||
?FAULT(signed_message_bad(), signed_message_good(M)).
|
||||
|
||||
signed_message_valid({valid, _}, _) -> true;
|
||||
signed_message_valid({invalid, _}, _) -> true;
|
||||
@ -478,7 +486,7 @@ secret_key_bad() ->
|
||||
?SUCHTHAT(B, binary(), byte_size(B) /= enacl:secretbox_key_size())]).
|
||||
|
||||
secret_key() ->
|
||||
z_fault(secret_key_bad(), secret_key_good()).
|
||||
?FAULT(secret_key_bad(), secret_key_good()).
|
||||
|
||||
secret_key_valid(SK) when is_binary(SK) ->
|
||||
Sz = enacl:secretbox_key_size(),
|
||||
@ -501,9 +509,9 @@ secretbox_open(Msg, Nonce, Key) ->
|
||||
|
||||
prop_secretbox_correct() ->
|
||||
?FORALL({Msg, Nonce, Key},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, nonce()),
|
||||
z_fault_rate(1, 40, secret_key())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, nonce()),
|
||||
?FAULT_RATE(1, 40, secret_key())},
|
||||
begin
|
||||
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of
|
||||
true ->
|
||||
@ -531,8 +539,8 @@ prop_secretbox_failure_integrity() ->
|
||||
prop_stream_correct() ->
|
||||
?FORALL({Len, Nonce, Key},
|
||||
{int(),
|
||||
z_fault_rate(1, 40, nonce()),
|
||||
z_fault_rate(1, 40, secret_key())},
|
||||
?FAULT_RATE(1, 40, nonce()),
|
||||
?FAULT_RATE(1, 40, secret_key())},
|
||||
case Len >= 0 andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of
|
||||
true ->
|
||||
CipherStream = enacl:stream(Len, Nonce, Key),
|
||||
@ -547,9 +555,9 @@ xor_bytes(<<>>, <<>>) -> [].
|
||||
|
||||
%% prop_stream_xor_correct() ->
|
||||
%% ?FORALL({Msg, Nonce, Key},
|
||||
%% {z_fault_rate(1, 40, g_iodata()),
|
||||
%% z_fault_rate(1, 40, nonce()),
|
||||
%% z_fault_rate(1, 40, secret_key())},
|
||||
%% {?FAULT_RATE(1, 40, g_iodata()),
|
||||
%% ?FAULT_RATE(1, 40, nonce()),
|
||||
%% ?FAULT_RATE(1, 40, secret_key())},
|
||||
%% case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of
|
||||
%% true ->
|
||||
%% Stream = enacl:stream(iolist_size(Msg), Nonce, Key),
|
||||
@ -566,8 +574,8 @@ xor_bytes(<<>>, <<>>) -> [].
|
||||
%% CRYPTO AUTH
|
||||
prop_auth_correct() ->
|
||||
?FORALL({Msg, Key},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, secret_key())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, secret_key())},
|
||||
case v_iodata(Msg) andalso secret_key_valid(Key) of
|
||||
true ->
|
||||
Authenticator = enacl:auth(Msg, Key),
|
||||
@ -592,7 +600,7 @@ authenticator_good(_Msg, _Key) ->
|
||||
binary(enacl:auth_size()).
|
||||
|
||||
authenticator(Msg, Key) ->
|
||||
z_fault(authenticator_bad(), authenticator_good(Msg, Key)).
|
||||
?FAULT(authenticator_bad(), authenticator_good(Msg, Key)).
|
||||
|
||||
authenticator_valid({valid, _}) -> true;
|
||||
authenticator_valid({invalid, _}) -> true;
|
||||
@ -600,8 +608,8 @@ authenticator_valid(_) -> false.
|
||||
|
||||
prop_auth_verify_correct() ->
|
||||
?FORALL({Msg, Key},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, secret_key())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, secret_key())},
|
||||
?FORALL(Authenticator, authenticator(Msg, Key),
|
||||
case v_iodata(Msg) andalso secret_key_valid(Key) andalso authenticator_valid(Authenticator) of
|
||||
true ->
|
||||
@ -618,8 +626,8 @@ prop_auth_verify_correct() ->
|
||||
%% CRYPTO ONETIME AUTH
|
||||
prop_onetimeauth_correct() ->
|
||||
?FORALL({Msg, Key},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, secret_key())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, secret_key())},
|
||||
case v_iodata(Msg) andalso secret_key_valid(Key) of
|
||||
true ->
|
||||
Authenticator = enacl:onetime_auth(Msg, Key),
|
||||
@ -644,7 +652,7 @@ ot_authenticator_good(_Msg, _Key) ->
|
||||
binary(enacl:auth_size()).
|
||||
|
||||
ot_authenticator(Msg, Key) ->
|
||||
z_fault(ot_authenticator_bad(), ot_authenticator_good(Msg, Key)).
|
||||
?FAULT(ot_authenticator_bad(), ot_authenticator_good(Msg, Key)).
|
||||
|
||||
ot_authenticator_valid({valid, _}) -> true;
|
||||
ot_authenticator_valid({invalid, _}) -> true;
|
||||
@ -652,8 +660,8 @@ ot_authenticator_valid(_) -> false.
|
||||
|
||||
prop_onetime_auth_verify_correct() ->
|
||||
?FORALL({Msg, Key},
|
||||
{z_fault_rate(1, 40, g_iodata()),
|
||||
z_fault_rate(1, 40, secret_key())},
|
||||
{?FAULT_RATE(1, 40, g_iodata()),
|
||||
?FAULT_RATE(1, 40, secret_key())},
|
||||
?FORALL(Authenticator, ot_authenticator(Msg, Key),
|
||||
case v_iodata(Msg) andalso secret_key_valid(Key) andalso ot_authenticator_valid(Authenticator) of
|
||||
true ->
|
||||
@ -710,7 +718,7 @@ verify_pair_good(Sz) ->
|
||||
?SUCHTHAT({X, Y}, {binary(Sz), binary(Sz)}, X /= Y)]).
|
||||
|
||||
verify_pair(Sz) ->
|
||||
z_fault(verify_pair_bad(Sz), verify_pair_good(Sz)).
|
||||
?FAULT(verify_pair_bad(Sz), verify_pair_good(Sz)).
|
||||
|
||||
verify_pair_valid(Sz, X, Y) ->
|
||||
byte_size(X) == Sz andalso byte_size(Y) == Sz.
|
||||
|
Loading…
x
Reference in New Issue
Block a user