QuickCheck for randombytes
There are some new randombytes functions. Implement these as EQC properties.
This commit is contained in:
parent
c7720e6ab8
commit
d06fff489d
@ -9,9 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
|
|
||||||
- Go through all calls and make them return streamlined exceptions if applicable.
|
- Go through all calls and make them return streamlined exceptions if applicable.
|
||||||
Pretty large change, but OTOH, this ought to happen before a 1.0 release as well.
|
Pretty large change, but OTOH, this ought to happen before a 1.0 release as well.
|
||||||
- hash
|
|
||||||
- kx
|
- kx
|
||||||
- randombytes
|
|
||||||
- secret
|
- secret
|
||||||
- sign
|
- sign
|
||||||
- enacl_nif
|
- enacl_nif
|
||||||
@ -79,6 +77,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
- Split Sign Public Key routines from the rest. Modernize the handling of contexts.
|
- Split Sign Public Key routines from the rest. Modernize the handling of contexts.
|
||||||
- The multi-part generic hash routines now follow the structure of the crypto
|
- The multi-part generic hash routines now follow the structure of the crypto
|
||||||
modules multi-part constructions in API and style.
|
modules multi-part constructions in API and style.
|
||||||
|
- The AEAD constructions have been streamlined so they follow the rules of libsodium
|
||||||
|
closer than before. In particular, some dead code has been removed as a result.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix a resource leak in generichash/sign init/update/final.
|
- Fix a resource leak in generichash/sign init/update/final.
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <erl_nif.h>
|
#include <erl_nif.h>
|
||||||
|
|
||||||
|
#include "enacl.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
ERL_NIF_TERM enacl_crypto_shorthash_BYTES(ErlNifEnv *env, int argc,
|
ERL_NIF_TERM enacl_crypto_shorthash_BYTES(ErlNifEnv *env, int argc,
|
||||||
@ -28,7 +29,7 @@ ERL_NIF_TERM enacl_crypto_shorthash(ErlNifEnv *env, int argc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!enif_alloc_binary(crypto_shorthash_BYTES, &a)) {
|
if (!enif_alloc_binary(crypto_shorthash_BYTES, &a)) {
|
||||||
return enacl_error_tuple(env, "alloc_failed");
|
return enacl_internal_error(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto_shorthash(a.data, m.data, m.size, k.data);
|
crypto_shorthash(a.data, m.data, m.size, k.data);
|
||||||
@ -54,9 +55,8 @@ ERL_NIF_TERM enacl_crypto_hash(ErlNifEnv *env, int argc,
|
|||||||
|
|
||||||
bad_arg:
|
bad_arg:
|
||||||
return enif_make_badarg(env);
|
return enif_make_badarg(env);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
ret = enacl_error_tuple(env, "alloc_failed");
|
ret = enacl_internal_error(env);
|
||||||
done:
|
done:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -783,6 +783,25 @@ prop_crypto_hash_neq() ->
|
|||||||
enacl:hash(X) /= enacl:hash(Y)
|
enacl:hash(X) /= enacl:hash(Y)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
prop_crypto_shorthash_eq() ->
|
||||||
|
?FORALL(X, g_iodata(),
|
||||||
|
case v_iodata(X) of
|
||||||
|
true -> equals(enacl:hash(X), enacl:hash(X));
|
||||||
|
false ->
|
||||||
|
try
|
||||||
|
enacl:hash(X),
|
||||||
|
false
|
||||||
|
catch
|
||||||
|
error:badarg -> true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
).
|
||||||
|
|
||||||
|
prop_crypto_shorthash_neq() ->
|
||||||
|
?FORALL({X, Y}, diff_pair(),
|
||||||
|
enacl:hash(X) /= enacl:hash(Y)
|
||||||
|
).
|
||||||
|
|
||||||
%% STRING COMPARISON
|
%% STRING COMPARISON
|
||||||
%% -------------------------
|
%% -------------------------
|
||||||
%% * verify_16/2,
|
%% * verify_16/2,
|
||||||
@ -842,7 +861,8 @@ prop_randombytes() ->
|
|||||||
?FORALL(X, g_nat(),
|
?FORALL(X, g_nat(),
|
||||||
case is_nat(X) of
|
case is_nat(X) of
|
||||||
true ->
|
true ->
|
||||||
is_binary(enacl:randombytes(X));
|
R = enacl:randombytes(X),
|
||||||
|
is_binary(R) andalso (byte_size(R) == X);
|
||||||
false ->
|
false ->
|
||||||
try
|
try
|
||||||
enacl:randombytes(X),
|
enacl:randombytes(X),
|
||||||
@ -853,6 +873,13 @@ prop_randombytes() ->
|
|||||||
end
|
end
|
||||||
end).
|
end).
|
||||||
|
|
||||||
|
prop_randombytes_uint32() ->
|
||||||
|
?FORALL(_, return(x),
|
||||||
|
begin
|
||||||
|
V = enacl:randombytes_uint32(),
|
||||||
|
is_integer(V)
|
||||||
|
end).
|
||||||
|
|
||||||
%% SCRAMBLING
|
%% SCRAMBLING
|
||||||
prop_scramble_block() ->
|
prop_scramble_block() ->
|
||||||
?FORALL({Block, Key}, {binary(16), eqc_gen:largebinary(32)},
|
?FORALL({Block, Key}, {binary(16), eqc_gen:largebinary(32)},
|
||||||
|
@ -953,6 +953,10 @@ shorthash_size() ->
|
|||||||
%%
|
%%
|
||||||
%% Given a `Msg' and a `Key' produce a MAC/Authenticator for that message. The key can be reused for several such Msg/Authenticator pairs.
|
%% Given a `Msg' and a `Key' produce a MAC/Authenticator for that message. The key can be reused for several such Msg/Authenticator pairs.
|
||||||
%% An eavesdropper will not learn anything extra about the message structure.
|
%% An eavesdropper will not learn anything extra about the message structure.
|
||||||
|
%%
|
||||||
|
%% The intended use is to generate a random key and use it as a hash table or bloom filter function.
|
||||||
|
%% This avoids an enemy their ability to predict where a collision would occur in the data structure,
|
||||||
|
%% since they don't know the key.
|
||||||
%% @end
|
%% @end
|
||||||
-spec shorthash(Msg, Key) -> Authenticator
|
-spec shorthash(Msg, Key) -> Authenticator
|
||||||
when
|
when
|
||||||
|
@ -44,7 +44,8 @@ groups() ->
|
|||||||
aead_chacha20poly1305_ietf,
|
aead_chacha20poly1305_ietf,
|
||||||
pwhash,
|
pwhash,
|
||||||
sign,
|
sign,
|
||||||
kx]},
|
kx,
|
||||||
|
randombytes]},
|
||||||
|
|
||||||
[Neg, Pos].
|
[Neg, Pos].
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user