Streamline naming

More changes before 1.0 with a
more direct naming scheme.
This commit is contained in:
Jesper Louis Andersen 2020-02-06 13:57:07 +01:00
parent 014d50cf47
commit cceef4530a
5 changed files with 138 additions and 121 deletions

View File

@ -11,10 +11,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
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.
- Generichashes must support the finalized state - Generichashes must support the finalized state
- Implement missing EQC tests
- stream_chacha20...
- stream_xor...
## [Unreleased] ## [Unreleased]
### Compatibility ### Compatibility

View File

@ -20,7 +20,7 @@ test() ->
randombytes() -> randombytes() ->
randombytes(100*1000). randombytes(100*1000).
randombytes(0) -> ok; randombytes(0) -> ok;
randombytes(N) -> randombytes(N) ->
enacl:randombytes(1024), enacl:randombytes(1024),
@ -29,7 +29,7 @@ randombytes(N) ->
hash() -> hash() ->
B = binary:copy(<<0>>, 4096), B = binary:copy(<<0>>, 4096),
hash(B, 10*1000). hash(B, 10*1000).
hash(_B, 0) -> ok; hash(_B, 0) -> ok;
hash(B, N) -> hash(B, N) ->
enacl:hash(B), enacl:hash(B),
@ -37,7 +37,7 @@ hash(B, N) ->
box_keypair() -> box_keypair() ->
box_keypair(10*1000). box_keypair(10*1000).
box_keypair(0) -> ok; box_keypair(0) -> ok;
box_keypair(N) -> box_keypair(N) ->
enacl:box_keypair(), enacl:box_keypair(),
@ -47,9 +47,9 @@ box() ->
#{ public := PK1} = enacl:box_keypair(), #{ public := PK1} = enacl:box_keypair(),
#{ secret := SK2} = enacl:box_keypair(), #{ secret := SK2} = enacl:box_keypair(),
B = binary:copy(<<0>>, 1), B = binary:copy(<<0>>, 1),
Nonce = binary:copy(<<0>>, enacl:box_nonce_size()), Nonce = binary:copy(<<0>>, enacl:box_NONCEBYTES()()),
box(B, Nonce, PK1, SK2, 10*1000). box(B, Nonce, PK1, SK2, 10*1000).
box(_B, _Nonce, _PK1, _SK2, 0) -> ok; box(_B, _Nonce, _PK1, _SK2, 0) -> ok;
box(B, Nonce, PK1, SK2, N) -> box(B, Nonce, PK1, SK2, N) ->
enacl:box(B, Nonce, PK1, SK2), enacl:box(B, Nonce, PK1, SK2),
@ -62,15 +62,15 @@ box_before_after() ->
box_beforenm(PK1, SK2, 10*1000), box_beforenm(PK1, SK2, 10*1000),
R = enacl:box_beforenm(PK1, SK2), R = enacl:box_beforenm(PK1, SK2),
B = binary:copy(<<0>>, 8192), B = binary:copy(<<0>>, 8192),
Nonce = binary:copy(<<0>>, enacl:box_nonce_size()), Nonce = binary:copy(<<0>>, enacl:box_NONCEBYTES()()),
box_afternm(B, Nonce, R, 10*1000), box_afternm(B, Nonce, R, 10*1000),
ok. ok.
box_beforenm(_PK, _SK, 0) -> ok; box_beforenm(_PK, _SK, 0) -> ok;
box_beforenm(PK, SK, N) -> box_beforenm(PK, SK, N) ->
enacl:box_beforenm(PK, SK), enacl:box_beforenm(PK, SK),
box_beforenm(PK, SK, N-1). box_beforenm(PK, SK, N-1).
box_afternm(_Msg, _Nonce, _Key, 0) -> ok; box_afternm(_Msg, _Nonce, _Key, 0) -> ok;
box_afternm(Msg, Nonce, Key, N) -> box_afternm(Msg, Nonce, Key, N) ->
enacl:box_afternm(Msg, Nonce, Key), enacl:box_afternm(Msg, Nonce, Key),
@ -78,7 +78,7 @@ box_afternm(Msg, Nonce, Key, N) ->
sign_keypair() -> sign_keypair() ->
sign_keypair(10*1000). sign_keypair(10*1000).
sign_keypair(0) -> ok; sign_keypair(0) -> ok;
sign_keypair(N) -> sign_keypair(N) ->
enacl:sign_keypair(), enacl:sign_keypair(),
@ -91,7 +91,7 @@ sign() ->
Msg = binary:copy(<<0>>, 1024), Msg = binary:copy(<<0>>, 1024),
#{ secret := SK } = enacl:sign_keypair(), #{ secret := SK } = enacl:sign_keypair(),
sign(Msg, SK, 10*1000). sign(Msg, SK, 10*1000).
sign(_Msg, _SK, 0) -> ok; sign(_Msg, _SK, 0) -> ok;
sign(Msg, SK, N) -> sign(Msg, SK, N) ->
enacl:sign(Msg, SK), enacl:sign(Msg, SK),
@ -100,10 +100,10 @@ sign(Msg, SK, N) ->
secretbox() -> secretbox() ->
Msg = binary:copy(<<0>>, 8192), Msg = binary:copy(<<0>>, 8192),
Nonce = binary:copy(<<0>>, enacl:secretbox_nonce_size()), Nonce = binary:copy(<<0>>, enacl:secretbox_NONCEBYTES()()),
Key = binary:copy(<<0>>, enacl:secretbox_key_size()), Key = binary:copy(<<0>>, enacl:secretbox_KEYBYTES()),
secretbox(Msg, Nonce, Key, 10*1000). secretbox(Msg, Nonce, Key, 10*1000).
secretbox(_Msg, _Nonce, _Key, 0) -> ok; secretbox(_Msg, _Nonce, _Key, 0) -> ok;
secretbox(Msg, Nonce, Key, N) -> secretbox(Msg, Nonce, Key, N) ->
enacl:secretbox(Msg, Nonce, Key), enacl:secretbox(Msg, Nonce, Key),
@ -111,8 +111,8 @@ secretbox(Msg, Nonce, Key, N) ->
stream() -> stream() ->
stream(16384, binary:copy(<<0>>, enacl:stream_nonce_size()), binary:copy(<<0>>, enacl:stream_key_size()), 10*1000). stream(16384, binary:copy(<<0>>, enacl:stream_NONCEBYTES()), binary:copy(<<0>>, enacl:stream_KEYBYTES()), 10*1000).
stream(_L, _Nonce, _K, 0) -> ok; stream(_L, _Nonce, _K, 0) -> ok;
stream(L, Nonce, K, N) -> stream(L, Nonce, K, N) ->
enacl:stream(L, Nonce, K), enacl:stream(L, Nonce, K),
@ -120,31 +120,31 @@ stream(L, Nonce, K, N) ->
auth() -> auth() ->
Msg = binary:copy(<<0>>, 4096), Msg = binary:copy(<<0>>, 4096),
Key = binary:copy(<<0>>, enacl:auth_key_size()), Key = binary:copy(<<0>>, enacl:auth_KEYBYTES()),
auth(Msg, Key, 10*1000). auth(Msg, Key, 10*1000).
auth(_Msg, _Key, 0) -> ok; auth(_Msg, _Key, 0) -> ok;
auth(Msg, Key, N) -> auth(Msg, Key, N) ->
enacl:auth(Msg, Key), enacl:auth(Msg, Key),
auth(Msg, Key, N-1). auth(Msg, Key, N-1).
onetime_auth() -> onetime_auth() ->
Msg = binary:copy(<<0>>, 16384), Msg = binary:copy(<<0>>, 16384),
Key = binary:copy(<<0>>, enacl:onetime_auth_key_size()), Key = binary:copy(<<0>>, enacl:onetime_auth_KEYBYTES()),
onetime_auth(Msg, Key, 10*1000). onetime_auth(Msg, Key, 10*1000).
onetime_auth(_Msg, _Key, 0) -> ok; onetime_auth(_Msg, _Key, 0) -> ok;
onetime_auth(Msg, Key, N) -> onetime_auth(Msg, Key, N) ->
enacl:onetime_auth(Msg, Key), enacl:onetime_auth(Msg, Key),
onetime_auth(Msg, Key, N-1). onetime_auth(Msg, Key, N-1).
scalarmult() -> scalarmult() ->
Secret = binary:copy(<<0>>, 32), Secret = binary:copy(<<0>>, 32),
BasePoint = binary:copy(<<1>>, 32), BasePoint = binary:copy(<<1>>, 32),
scalarmult(Secret, BasePoint, 10*1000). scalarmult(Secret, BasePoint, 10*1000).
scalarmult(_S, _B, 0) -> ok; scalarmult(_S, _B, 0) -> ok;
scalarmult(S, B, N) -> scalarmult(S, B, N) ->
enacl:curve25519_scalarmult(S, B), enacl:curve25519_scalarmult(S, B),
scalarmult(S, B, N-1). scalarmult(S, B, N-1).

View File

@ -83,8 +83,8 @@ v_binary(_, _) -> false.
%% Typical generators based on the binaries %% Typical generators based on the binaries
nonce() -> g_binary(enacl:box_nonce_size()). nonce() -> g_binary(enacl:box_NONCEBYTES()).
nonce_valid(N) -> v_binary(enacl:box_nonce_size(), N). nonce_valid(N) -> v_binary(enacl:box_NONCEBYTES(), N).
%% Generator of natural numbers %% Generator of natural numbers
g_nat() -> g_nat() ->
@ -111,10 +111,10 @@ keypair_bad() ->
#{ public := PK, secret := SK} = enacl:box_keypair(), #{ public := PK, secret := SK} = enacl:box_keypair(),
case X of case X of
pk -> pk ->
PKBytes = enacl:box_public_key_bytes(), PKBytes = enacl:box_PUBLICKEYBYTES(),
{oneof([return(a), nat(), ?SUCHTHAT(B, binary(), byte_size(B) /= PKBytes)]), SK}; {oneof([return(a), nat(), ?SUCHTHAT(B, binary(), byte_size(B) /= PKBytes)]), SK};
sk -> sk ->
SKBytes = enacl:box_secret_key_bytes(), SKBytes = enacl:box_SECRETKEYBYTES(),
{PK, oneof([return(a), nat(), ?SUCHTHAT(B, binary(), byte_size(B) /= SKBytes)])} {PK, oneof([return(a), nat(), ?SUCHTHAT(B, binary(), byte_size(B) /= SKBytes)])}
end end
end). end).
@ -159,8 +159,8 @@ g_generichash_size() ->
%% * box_afternm/3 %% * box_afternm/3
%% * box_open_afternm/3 %% * box_open_afternm/3
keypair_valid(PK, SK) when is_binary(PK), is_binary(SK) -> keypair_valid(PK, SK) when is_binary(PK), is_binary(SK) ->
PKBytes = enacl:box_public_key_bytes(), PKBytes = enacl:box_PUBLICKEYBYTES(),
SKBytes = enacl:box_secret_key_bytes(), SKBytes = enacl:box_SECRETKEYBYTES(),
byte_size(PK) == PKBytes andalso byte_size(SK) == SKBytes; byte_size(PK) == PKBytes andalso byte_size(SK) == SKBytes;
keypair_valid(_PK, _SK) -> false. keypair_valid(_PK, _SK) -> false.
@ -264,11 +264,11 @@ beforenm_key() ->
oneof([ oneof([
elements([a,b,c]), elements([a,b,c]),
real(), real(),
?SUCHTHAT(X, binary(), byte_size(X) /= enacl:box_beforenm_bytes()) ?SUCHTHAT(X, binary(), byte_size(X) /= enacl:box_BEFORENMBYTES())
]) ])
end). end).
v_key(K) when is_binary(K) -> byte_size(K) == enacl:box_beforenm_bytes(); v_key(K) when is_binary(K) -> byte_size(K) == enacl:box_BEFORENMBYTES();
v_key(_) -> false. v_key(_) -> false.
prop_beforenm_correct() -> prop_beforenm_correct() ->
@ -324,11 +324,11 @@ sign_keypair_bad() ->
KP = enacl:sign_keypair(), KP = enacl:sign_keypair(),
case X of case X of
pk -> pk ->
Sz = enacl:sign_keypair_public_size(), Sz = enacl:sign_PUBLICBYTES(),
?LET(Wrong, oneof([a, int(), ?SUCHTHAT(B, binary(), byte_size(B) /= Sz)]), ?LET(Wrong, oneof([a, int(), ?SUCHTHAT(B, binary(), byte_size(B) /= Sz)]),
KP#{ public := Wrong }); KP#{ public := Wrong });
sk -> sk ->
Sz = enacl:sign_keypair_secret_size(), Sz = enacl:sign_SECRETBYTES(),
?LET(Wrong, oneof([a, int(), ?SUCHTHAT(B, binary(), byte_size(B) /= Sz)]), ?LET(Wrong, oneof([a, int(), ?SUCHTHAT(B, binary(), byte_size(B) /= Sz)]),
KP#{ secret := Wrong }) KP#{ secret := Wrong })
end end
@ -342,12 +342,12 @@ sign_keypair() ->
sign_keypair_public_valid(#{ public := Public }) sign_keypair_public_valid(#{ public := Public })
when is_binary(Public) -> when is_binary(Public) ->
byte_size(Public) == enacl:sign_keypair_public_size(); byte_size(Public) == enacl:sign_PUBLICBYTES();
sign_keypair_public_valid(_) -> false. sign_keypair_public_valid(_) -> false.
sign_keypair_secret_valid(#{ secret := Secret }) sign_keypair_secret_valid(#{ secret := Secret })
when is_binary(Secret) -> when is_binary(Secret) ->
byte_size(Secret) == enacl:sign_keypair_secret_size(); byte_size(Secret) == enacl:sign_SECRETBYTES();
sign_keypair_secret_valid(_) -> false. sign_keypair_secret_valid(_) -> false.
sign_keypair_valid(KP) -> sign_keypair_valid(KP) ->
@ -408,11 +408,11 @@ signed_message_good_d(M) ->
end)}]). end)}]).
signed_message_bad() -> signed_message_bad() ->
Sz = enacl:sign_keypair_public_size(), Sz = enacl:sign_PUBLICBYTES(),
{binary(), oneof([a, int(), ?SUCHTHAT(B, binary(Sz), byte_size(B) /= Sz)])}. {binary(), oneof([a, int(), ?SUCHTHAT(B, binary(Sz), byte_size(B) /= Sz)])}.
signed_message_bad_d() -> signed_message_bad_d() ->
Sz = enacl:sign_keypair_public_size(), Sz = enacl:sign_PUBLICBYTES(),
{binary(), oneof([a, int(), ?SUCHTHAT(B, binary(Sz), byte_size(B) /= Sz)])}. {binary(), oneof([a, int(), ?SUCHTHAT(B, binary(Sz), byte_size(B) /= Sz)])}.
signed_message(M) -> signed_message(M) ->
@ -496,19 +496,19 @@ prop_seal_box_correct() ->
%% * secretbox/3 %% * secretbox/3
%% * secretbo_open/3 %% * secretbo_open/3
secret_key_good() -> secret_key_good() ->
Sz = enacl:secretbox_key_size(), Sz = enacl:secretbox_KEYBYTES(),
binary(Sz). binary(Sz).
secret_key_bad() -> secret_key_bad() ->
oneof([return(a), oneof([return(a),
nat(), nat(),
?SUCHTHAT(B, binary(), byte_size(B) /= enacl:secretbox_key_size())]). ?SUCHTHAT(B, binary(), byte_size(B) /= enacl:secretbox_KEYBYTES())]).
secret_key() -> secret_key() ->
?FAULT(secret_key_bad(), secret_key_good()). ?FAULT(secret_key_bad(), secret_key_good()).
secret_key_valid(SK) when is_binary(SK) -> secret_key_valid(SK) when is_binary(SK) ->
Sz = enacl:secretbox_key_size(), Sz = enacl:secretbox_KEYBYTES(),
byte_size(SK) == Sz; byte_size(SK) == Sz;
secret_key_valid(_SK) -> false. secret_key_valid(_SK) -> false.
@ -618,6 +618,27 @@ xor_bytes(<<A, As/binary>>, <<B, Bs/binary>>) ->
[A bxor B | xor_bytes(As, Bs)]; [A bxor B | xor_bytes(As, Bs)];
xor_bytes(<<>>, <<>>) -> []. xor_bytes(<<>>, <<>>) -> [].
positive() ->
?LET(N, nat(), N+1).
chacha20_nonce() ->
Sz = enacl:stream_chacha20_NONCEBYTES(),
binary(Sz).
chacha20_key() ->
Sz = enacl:stream_chacha20_KEYBYTES(),
binary(Sz).
prop_stream_chacha20_correct() ->
?FORALL(Len, positive(),
?FORALL({Msg, Nonce, Key}, {binary(Len), chacha20_nonce(), chacha20_key()},
begin
CT = enacl:stream_chacha20_xor(Msg, Nonce, Key),
Stream = enacl:stream_chacha20(Len, Nonce, Key),
CT2 = list_to_binary(xor_bytes(Stream, Msg)),
equals(CT, CT2)
end)).
%% CRYPTO AUTH %% CRYPTO AUTH
%% ------------------------------------------------------------ %% ------------------------------------------------------------
%% * auth/2 %% * auth/2
@ -635,19 +656,19 @@ prop_auth_correct() ->
end). end).
authenticator_bad() -> authenticator_bad() ->
oneof([a, int(), ?SUCHTHAT(X, binary(), byte_size(X) /= enacl:auth_size())]). oneof([a, int(), ?SUCHTHAT(X, binary(), byte_size(X) /= enacl:auth_BYTES())]).
authenticator_good(Msg, Key) when is_binary(Key) -> authenticator_good(Msg, Key) when is_binary(Key) ->
Sz = enacl:secretbox_key_size(), Sz = enacl:secretbox_KEYBYTES(),
case v_iodata(Msg) andalso 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_BYTES())})},
{3, return({valid, enacl:auth(Msg, Key)})}]); {3, return({valid, enacl:auth(Msg, Key)})}]);
false -> false ->
binary(enacl:auth_size()) binary(enacl:auth_BYTES())
end; end;
authenticator_good(_Msg, _Key) -> authenticator_good(_Msg, _Key) ->
binary(enacl:auth_size()). binary(enacl:auth_BYTES()).
authenticator(Msg, Key) -> authenticator(Msg, Key) ->
?FAULT(authenticator_bad(), authenticator_good(Msg, Key)). ?FAULT(authenticator_bad(), authenticator_good(Msg, Key)).
@ -690,19 +711,19 @@ prop_onetimeauth_correct() ->
end). end).
ot_authenticator_bad() -> ot_authenticator_bad() ->
oneof([a, int(), ?SUCHTHAT(X, binary(), byte_size(X) /= enacl:onetime_auth_size())]). oneof([a, int(), ?SUCHTHAT(X, binary(), byte_size(X) /= enacl:onetime_auth_BYTES())]).
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_KEYBYTES(),
case v_iodata(Msg) andalso 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_BYTES())})},
{3, return({valid, enacl:onetime_auth(Msg, Key)})}]); {3, return({valid, enacl:onetime_auth(Msg, Key)})}]);
false -> false ->
binary(enacl:onetime_auth_size()) binary(enacl:onetime_auth_BYTES())
end; end;
ot_authenticator_good(_Msg, _Key) -> ot_authenticator_good(_Msg, _Key) ->
binary(enacl:auth_size()). binary(enacl:auth_BYTES()).
ot_authenticator(Msg, Key) -> ot_authenticator(Msg, Key) ->
?FAULT(ot_authenticator_bad(), ot_authenticator_good(Msg, Key)). ?FAULT(ot_authenticator_bad(), ot_authenticator_good(Msg, Key)).

View File

@ -25,14 +25,14 @@
box_beforenm/2, box_beforenm/2,
box_afternm/3, box_afternm/3,
box_open_afternm/3, box_open_afternm/3,
box_nonce_size/0, box_NONCEBYTES/0,
box_public_key_bytes/0, box_PUBLICKEYBYTES/0,
box_secret_key_bytes/0, box_SECRETKEYBYTES/0,
box_beforenm_bytes/0, box_BEFORENMBYTES/0,
sign_keypair_public_size/0, sign_PUBLICBYTES/0,
sign_keypair_secret_size/0, sign_SECRETBYTES/0,
sign_keypair_seed_size/0, sign_SEEDBYTES/0,
sign_keypair/0, sign_keypair/0,
sign_seed_keypair/1, sign_seed_keypair/1,
sign/2, sign/2,
@ -52,14 +52,14 @@
%% Secret key crypto %% Secret key crypto
-export([ -export([
%% EQC %% EQC
secretbox_key_size/0, secretbox_KEYBYTES/0,
secretbox_nonce_size/0, secretbox_NONCEBYTES/0,
secretbox/3, secretbox/3,
secretbox_open/3, secretbox_open/3,
%% No Tests! %% No Tests!
stream_chacha20_key_size/0, stream_chacha20_KEYBYTES/0,
stream_chacha20_nonce_size/0, stream_chacha20_NONCEBYTES/0,
stream_chacha20/3, stream_chacha20/3,
stream_chacha20_xor/3, stream_chacha20_xor/3,
@ -79,22 +79,22 @@
aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX/0, aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX/0,
%% EQC %% EQC
stream_key_size/0, stream_KEYBYTES/0,
stream_nonce_size/0, stream_NONCEBYTES/0,
stream/3, stream/3,
%% No Tests! %% No Tests!
stream_xor/3, stream_xor/3,
%% EQC %% EQC
auth_key_size/0, auth_KEYBYTES/0,
auth_size/0, auth_BYTES/0,
auth/2, auth/2,
auth_verify/3, auth_verify/3,
%% EQC %% EQC
onetime_auth_key_size/0, onetime_auth_KEYBYTES/0,
onetime_auth_size/0, onetime_auth_BYTES/0,
onetime_auth/2, onetime_auth/2,
onetime_auth_verify/3 onetime_auth_verify/3
]). ]).
@ -189,9 +189,9 @@
-define(SECRETBOX_OPEN_REDUCTIONS, 17 * 2). -define(SECRETBOX_OPEN_REDUCTIONS, 17 * 2).
-define(STREAM_SIZE, 16 * 1024). -define(STREAM_SIZE, 16 * 1024).
-define(STREAM_REDUCTIONS, 17 * 2). -define(STREAM_REDUCTIONS, 17 * 2).
-define(AUTH_SIZE, 4 * 1024). -define(auth_BYTES, 4 * 1024).
-define(AUTH_REDUCTIONS, 17 * 2). -define(AUTH_REDUCTIONS, 17 * 2).
-define(ONETIME_AUTH_SIZE, 16 * 1024). -define(ONETIME_auth_BYTES, 16 * 1024).
-define(ONETIME_AUTH_REDUCTIONS, 16 * 2). -define(ONETIME_AUTH_REDUCTIONS, 16 * 2).
-define(ED25519_PUBLIC_TO_CURVE_REDS, 20 * 2). -define(ED25519_PUBLIC_TO_CURVE_REDS, 20 * 2).
-define(ED25519_SECRET_TO_CURVE_REDS, 20 * 2). -define(ED25519_SECRET_TO_CURVE_REDS, 20 * 2).
@ -522,35 +522,35 @@ box_open_afternm(CipherText, Nonce, Key) ->
enacl_nif:crypto_box_open_afternm([?P_BOXZEROBYTES, CipherText], Nonce, Key) enacl_nif:crypto_box_open_afternm([?P_BOXZEROBYTES, CipherText], Nonce, Key)
end. end.
%% @doc box_nonce_size/0 return the byte-size of the nonce %% @doc box_NONCEBYTES()/0 return the byte-size of the nonce
%% %%
%% Used to obtain the size of the nonce. %% Used to obtain the size of the nonce.
%% @end. %% @end.
-spec box_nonce_size() -> pos_integer(). -spec box_NONCEBYTES() -> pos_integer().
box_nonce_size() -> box_NONCEBYTES() ->
enacl_nif:crypto_box_NONCEBYTES(). enacl_nif:crypto_box_NONCEBYTES().
%% @private %% @private
-spec box_public_key_bytes() -> pos_integer(). -spec box_PUBLICKEYBYTES() -> pos_integer().
box_public_key_bytes() -> box_PUBLICKEYBYTES() ->
enacl_nif:crypto_box_PUBLICKEYBYTES(). enacl_nif:crypto_box_PUBLICKEYBYTES().
%% @private %% @private
box_beforenm_bytes() -> box_BEFORENMBYTES() ->
enacl_nif:crypto_box_BEFORENMBYTES(). enacl_nif:crypto_box_BEFORENMBYTES().
%% Signatures %% Signatures
%% @private %% @private
sign_keypair_public_size() -> sign_PUBLICBYTES() ->
enacl_nif:crypto_sign_PUBLICKEYBYTES(). enacl_nif:crypto_sign_PUBLICKEYBYTES().
%% @private %% @private
sign_keypair_secret_size() -> sign_SECRETBYTES() ->
enacl_nif:crypto_sign_SECRETKEYBYTES(). enacl_nif:crypto_sign_SECRETKEYBYTES().
%% @private %% @private
sign_keypair_seed_size() -> sign_SEEDBYTES() ->
enacl_nif:crypto_sign_SEEDBYTES(). enacl_nif:crypto_sign_SEEDBYTES().
%% @doc sign_keypair/0 returns a signature keypair for signing %% @doc sign_keypair/0 returns a signature keypair for signing
@ -666,8 +666,8 @@ sign_final_verify(SignState, SIG, PK) ->
enacl_nif:crypto_sign_final_verify(SignState, SIG, PK). enacl_nif:crypto_sign_final_verify(SignState, SIG, PK).
%% @private %% @private
-spec box_secret_key_bytes() -> pos_integer(). -spec box_SECRETKEYBYTES() -> pos_integer().
box_secret_key_bytes() -> box_SECRETKEYBYTES() ->
enacl_nif:crypto_box_SECRETKEYBYTES(). enacl_nif:crypto_box_SECRETKEYBYTES().
%% @doc seal_box/2 encrypts an anonymous message to another party. %% @doc seal_box/2 encrypts an anonymous message to another party.
@ -741,30 +741,30 @@ secretbox_open(CipherText, Nonce, Key) ->
enacl_nif:crypto_secretbox_open([?S_BOXZEROBYTES, CipherText], Nonce, Key) enacl_nif:crypto_secretbox_open([?S_BOXZEROBYTES, CipherText], Nonce, Key)
end. end.
%% @doc secretbox_nonce_size/0 returns the size of the secretbox nonce %% @doc secretbox_NONCEBYTES()/0 returns the size of the secretbox nonce
%% %%
%% When encrypting with a secretbox, the nonce must have this size %% When encrypting with a secretbox, the nonce must have this size
%% @end %% @end
secretbox_nonce_size() -> secretbox_NONCEBYTES() ->
enacl_nif:crypto_secretbox_NONCEBYTES(). enacl_nif:crypto_secretbox_NONCEBYTES().
%% @doc secretbox_key_size/0 returns the size of the secretbox key %% @doc secretbox_KEYBYTES/0 returns the size of the secretbox key
%% %%
%% When encrypting with a secretbox, the key must have this size %% When encrypting with a secretbox, the key must have this size
%% @end %% @end
secretbox_key_size() -> secretbox_KEYBYTES() ->
enacl_nif:crypto_secretbox_KEYBYTES(). enacl_nif:crypto_secretbox_KEYBYTES().
%% @doc stream_chacha20_nonce_size/0 returns the byte size of the nonce for streams %% @doc stream_chacha20_NONCEBYTES/0 returns the byte size of the nonce for streams
%% @end %% @end
-spec stream_chacha20_nonce_size() -> ?CRYPTO_STREAM_CHACHA20_NONCEBYTES. -spec stream_chacha20_NONCEBYTES() -> ?CRYPTO_STREAM_CHACHA20_NONCEBYTES.
stream_chacha20_nonce_size() -> stream_chacha20_NONCEBYTES() ->
?CRYPTO_STREAM_CHACHA20_NONCEBYTES. ?CRYPTO_STREAM_CHACHA20_NONCEBYTES.
%% @doc stream_key_size/0 returns the byte size of the key for streams %% @doc stream_chacha20_KEYBYTES/0 returns the byte size of the key for streams
%% @end %% @end
-spec stream_chacha20_key_size() -> ?CRYPTO_STREAM_CHACHA20_KEYBYTES. -spec stream_chacha20_KEYBYTES() -> ?CRYPTO_STREAM_CHACHA20_KEYBYTES.
stream_chacha20_key_size() -> stream_chacha20_KEYBYTES() ->
?CRYPTO_STREAM_CHACHA20_KEYBYTES. ?CRYPTO_STREAM_CHACHA20_KEYBYTES.
%% @doc stream_chacha20/3 produces a cryptographic stream suitable for secret-key encryption %% @doc stream_chacha20/3 produces a cryptographic stream suitable for secret-key encryption
@ -812,16 +812,16 @@ stream_chacha20_xor(Msg, Nonce, Key) ->
enacl_nif:crypto_stream_chacha20_xor(Msg, Nonce, Key) enacl_nif:crypto_stream_chacha20_xor(Msg, Nonce, Key)
end. end.
%% @doc stream_nonce_size/0 returns the byte size of the nonce for streams %% @doc stream_NONCEBYTES/0 returns the byte size of the nonce for streams
%% @end %% @end
-spec stream_nonce_size() -> ?CRYPTO_STREAM_NONCEBYTES. -spec stream_NONCEBYTES() -> ?CRYPTO_STREAM_NONCEBYTES.
stream_nonce_size() -> stream_NONCEBYTES() ->
?CRYPTO_STREAM_NONCEBYTES. ?CRYPTO_STREAM_NONCEBYTES.
%% @doc stream_key_size/0 returns the byte size of the key for streams %% @doc stream_KEYBYTES/0 returns the byte size of the key for streams
%% @end %% @end
-spec stream_key_size() -> ?CRYPTO_STREAM_KEYBYTES. -spec stream_KEYBYTES() -> ?CRYPTO_STREAM_KEYBYTES.
stream_key_size() -> stream_KEYBYTES() ->
?CRYPTO_STREAM_KEYBYTES. ?CRYPTO_STREAM_KEYBYTES.
%% @doc stream/3 produces a cryptographic stream suitable for secret-key encryption %% @doc stream/3 produces a cryptographic stream suitable for secret-key encryption
@ -869,16 +869,16 @@ stream_xor(Msg, Nonce, Key) ->
enacl_nif:crypto_stream_xor(Msg, Nonce, Key) enacl_nif:crypto_stream_xor(Msg, Nonce, Key)
end. end.
%% @doc auth_key_size/0 returns the byte-size of the authentication key %% @doc auth_KEYBYTES/0 returns the byte-size of the authentication key
%% @end %% @end
-spec auth_key_size() -> pos_integer(). -spec auth_KEYBYTES() -> pos_integer().
auth_key_size() -> auth_KEYBYTES() ->
enacl_nif:crypto_auth_KEYBYTES(). enacl_nif:crypto_auth_KEYBYTES().
%% @doc auth_size/0 returns the byte-size of the authenticator %% @doc auth_BYTES/0 returns the byte-size of the authenticator
%% @end %% @end
-spec auth_size() -> pos_integer(). -spec auth_BYTES() -> pos_integer().
auth_size() -> auth_BYTES() ->
enacl_nif:crypto_auth_BYTES(). enacl_nif:crypto_auth_BYTES().
%% @doc auth/2 produces an authenticator (MAC) for a message %% @doc auth/2 produces an authenticator (MAC) for a message
@ -893,8 +893,8 @@ auth_size() ->
Authenticator :: binary(). Authenticator :: binary().
auth(Msg, Key) -> auth(Msg, Key) ->
case iolist_size(Msg) of case iolist_size(Msg) of
K when K =< ?AUTH_SIZE -> K when K =< ?auth_BYTES ->
bump(enacl_nif:crypto_auth_b(Msg, Key), ?AUTH_REDUCTIONS, ?AUTH_SIZE, K); bump(enacl_nif:crypto_auth_b(Msg, Key), ?AUTH_REDUCTIONS, ?auth_BYTES, K);
_ -> _ ->
enacl_nif:crypto_auth(Msg, Key) enacl_nif:crypto_auth(Msg, Key)
end. end.
@ -911,10 +911,10 @@ auth(Msg, Key) ->
Key :: binary(). Key :: binary().
auth_verify(A, M, K) -> auth_verify(A, M, K) ->
case iolist_size(M) of case iolist_size(M) of
K when K =< ?AUTH_SIZE -> K when K =< ?auth_BYTES ->
bump(enacl_nif:crypto_auth_verify_b(A, M, K), bump(enacl_nif:crypto_auth_verify_b(A, M, K),
?AUTH_REDUCTIONS, ?AUTH_REDUCTIONS,
?AUTH_SIZE, ?auth_BYTES,
K); K);
_ -> _ ->
enacl_nif:crypto_auth_verify(A, M, K) enacl_nif:crypto_auth_verify(A, M, K)
@ -961,10 +961,10 @@ shorthash(Msg, Key) ->
Authenticator :: binary(). Authenticator :: binary().
onetime_auth(Msg, Key) -> onetime_auth(Msg, Key) ->
case iolist_size(Msg) of case iolist_size(Msg) of
K when K =< ?ONETIME_AUTH_SIZE -> K when K =< ?ONETIME_auth_BYTES ->
bump(enacl_nif:crypto_onetimeauth_b(Msg, Key), bump(enacl_nif:crypto_onetimeauth_b(Msg, Key),
?ONETIME_AUTH_REDUCTIONS, ?ONETIME_AUTH_REDUCTIONS,
?ONETIME_AUTH_SIZE, ?ONETIME_auth_BYTES,
K); K);
_ -> _ ->
enacl_nif:crypto_onetimeauth(Msg, Key) enacl_nif:crypto_onetimeauth(Msg, Key)
@ -983,25 +983,25 @@ onetime_auth(Msg, Key) ->
Key :: binary(). Key :: binary().
onetime_auth_verify(A, M, K) -> onetime_auth_verify(A, M, K) ->
case iolist_size(M) of case iolist_size(M) of
K when K =< ?ONETIME_AUTH_SIZE -> K when K =< ?ONETIME_auth_BYTES ->
bump(enacl_nif:crypto_onetimeauth_verify_b(A, M, K), bump(enacl_nif:crypto_onetimeauth_verify_b(A, M, K),
?ONETIME_AUTH_REDUCTIONS, ?ONETIME_AUTH_REDUCTIONS,
?ONETIME_AUTH_SIZE, ?ONETIME_auth_BYTES,
K); K);
_ -> _ ->
enacl_nif:crypto_onetimeauth_verify(A, M, K) enacl_nif:crypto_onetimeauth_verify(A, M, K)
end. end.
%% @doc onetime_auth_size/0 returns the number of bytes of the one-time authenticator %% @doc onetime_auth_BYTES/0 returns the number of bytes of the one-time authenticator
%% @end %% @end
-spec onetime_auth_size() -> pos_integer(). -spec onetime_auth_BYTES() -> pos_integer().
onetime_auth_size() -> onetime_auth_BYTES() ->
enacl_nif:crypto_onetimeauth_BYTES(). enacl_nif:crypto_onetimeauth_BYTES().
%% @doc onetime_auth_key_size/0 returns the byte-size of the onetime authentication key %% @doc onetime_auth_KEYBYTES/0 returns the byte-size of the onetime authentication key
%% @end %% @end
-spec onetime_auth_key_size() -> pos_integer(). -spec onetime_auth_KEYBYTES() -> pos_integer().
onetime_auth_key_size() -> onetime_auth_KEYBYTES() ->
enacl_nif:crypto_onetimeauth_KEYBYTES(). enacl_nif:crypto_onetimeauth_KEYBYTES().
%% Curve 25519 Crypto %% Curve 25519 Crypto

View File

@ -133,7 +133,7 @@ sign(_Config) ->
{ok, Signature} = enacl:sign_final_create(Create, SK), {ok, Signature} = enacl:sign_final_create(Create, SK),
StateVerify = enacl:sign_init(), StateVerify = enacl:sign_init(),
Verify = sign_chunked(StateVerify, Msg, 10000), Verify = sign_chunked(StateVerify, Msg, 10000),
ok = enacl:sign_final_verify(Verify, Signature, PK), true = enacl:sign_final_verify(Verify, Signature, PK),
ok. ok.
sign_chunked(S, _M, 0) -> S; sign_chunked(S, _M, 0) -> S;