Streamline naming
More changes before 1.0 with a more direct naming scheme.
This commit is contained in:
parent
014d50cf47
commit
cceef4530a
@ -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.
|
||||
- Generichashes must support the finalized state
|
||||
|
||||
- Implement missing EQC tests
|
||||
- stream_chacha20...
|
||||
- stream_xor...
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Compatibility
|
||||
|
@ -20,7 +20,7 @@ test() ->
|
||||
|
||||
randombytes() ->
|
||||
randombytes(100*1000).
|
||||
|
||||
|
||||
randombytes(0) -> ok;
|
||||
randombytes(N) ->
|
||||
enacl:randombytes(1024),
|
||||
@ -29,7 +29,7 @@ randombytes(N) ->
|
||||
hash() ->
|
||||
B = binary:copy(<<0>>, 4096),
|
||||
hash(B, 10*1000).
|
||||
|
||||
|
||||
hash(_B, 0) -> ok;
|
||||
hash(B, N) ->
|
||||
enacl:hash(B),
|
||||
@ -37,7 +37,7 @@ hash(B, N) ->
|
||||
|
||||
box_keypair() ->
|
||||
box_keypair(10*1000).
|
||||
|
||||
|
||||
box_keypair(0) -> ok;
|
||||
box_keypair(N) ->
|
||||
enacl:box_keypair(),
|
||||
@ -47,9 +47,9 @@ box() ->
|
||||
#{ public := PK1} = enacl:box_keypair(),
|
||||
#{ secret := SK2} = enacl:box_keypair(),
|
||||
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, 0) -> ok;
|
||||
box(B, Nonce, PK1, SK2, N) ->
|
||||
enacl:box(B, Nonce, PK1, SK2),
|
||||
@ -62,15 +62,15 @@ box_before_after() ->
|
||||
box_beforenm(PK1, SK2, 10*1000),
|
||||
R = enacl:box_beforenm(PK1, SK2),
|
||||
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),
|
||||
ok.
|
||||
|
||||
|
||||
box_beforenm(_PK, _SK, 0) -> ok;
|
||||
box_beforenm(PK, SK, N) ->
|
||||
enacl:box_beforenm(PK, SK),
|
||||
box_beforenm(PK, SK, N-1).
|
||||
|
||||
|
||||
box_afternm(_Msg, _Nonce, _Key, 0) -> ok;
|
||||
box_afternm(Msg, Nonce, Key, N) ->
|
||||
enacl:box_afternm(Msg, Nonce, Key),
|
||||
@ -78,7 +78,7 @@ box_afternm(Msg, Nonce, Key, N) ->
|
||||
|
||||
sign_keypair() ->
|
||||
sign_keypair(10*1000).
|
||||
|
||||
|
||||
sign_keypair(0) -> ok;
|
||||
sign_keypair(N) ->
|
||||
enacl:sign_keypair(),
|
||||
@ -91,7 +91,7 @@ sign() ->
|
||||
Msg = binary:copy(<<0>>, 1024),
|
||||
#{ secret := SK } = enacl:sign_keypair(),
|
||||
sign(Msg, SK, 10*1000).
|
||||
|
||||
|
||||
sign(_Msg, _SK, 0) -> ok;
|
||||
sign(Msg, SK, N) ->
|
||||
enacl:sign(Msg, SK),
|
||||
@ -100,10 +100,10 @@ sign(Msg, SK, N) ->
|
||||
|
||||
secretbox() ->
|
||||
Msg = binary:copy(<<0>>, 8192),
|
||||
Nonce = binary:copy(<<0>>, enacl:secretbox_nonce_size()),
|
||||
Key = binary:copy(<<0>>, enacl:secretbox_key_size()),
|
||||
Nonce = binary:copy(<<0>>, enacl:secretbox_NONCEBYTES()()),
|
||||
Key = binary:copy(<<0>>, enacl:secretbox_KEYBYTES()),
|
||||
secretbox(Msg, Nonce, Key, 10*1000).
|
||||
|
||||
|
||||
secretbox(_Msg, _Nonce, _Key, 0) -> ok;
|
||||
secretbox(Msg, Nonce, Key, N) ->
|
||||
enacl:secretbox(Msg, Nonce, Key),
|
||||
@ -111,8 +111,8 @@ secretbox(Msg, Nonce, Key, N) ->
|
||||
|
||||
|
||||
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, N) ->
|
||||
enacl:stream(L, Nonce, K),
|
||||
@ -120,31 +120,31 @@ stream(L, Nonce, K, N) ->
|
||||
|
||||
auth() ->
|
||||
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, 0) -> ok;
|
||||
auth(Msg, Key, N) ->
|
||||
enacl:auth(Msg, Key),
|
||||
auth(Msg, Key, N-1).
|
||||
|
||||
|
||||
onetime_auth() ->
|
||||
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, 0) -> ok;
|
||||
onetime_auth(Msg, Key, N) ->
|
||||
enacl:onetime_auth(Msg, Key),
|
||||
onetime_auth(Msg, Key, N-1).
|
||||
|
||||
|
||||
scalarmult() ->
|
||||
Secret = binary:copy(<<0>>, 32),
|
||||
BasePoint = binary:copy(<<1>>, 32),
|
||||
scalarmult(Secret, BasePoint, 10*1000).
|
||||
|
||||
|
||||
scalarmult(_S, _B, 0) -> ok;
|
||||
scalarmult(S, B, N) ->
|
||||
enacl:curve25519_scalarmult(S, B),
|
||||
scalarmult(S, B, N-1).
|
||||
|
||||
|
||||
|
@ -83,8 +83,8 @@ v_binary(_, _) -> false.
|
||||
|
||||
|
||||
%% Typical generators based on the binaries
|
||||
nonce() -> g_binary(enacl:box_nonce_size()).
|
||||
nonce_valid(N) -> v_binary(enacl:box_nonce_size(), N).
|
||||
nonce() -> g_binary(enacl:box_NONCEBYTES()).
|
||||
nonce_valid(N) -> v_binary(enacl:box_NONCEBYTES(), N).
|
||||
|
||||
%% Generator of natural numbers
|
||||
g_nat() ->
|
||||
@ -111,10 +111,10 @@ keypair_bad() ->
|
||||
#{ public := PK, secret := SK} = enacl:box_keypair(),
|
||||
case X of
|
||||
pk ->
|
||||
PKBytes = enacl:box_public_key_bytes(),
|
||||
PKBytes = enacl:box_PUBLICKEYBYTES(),
|
||||
{oneof([return(a), nat(), ?SUCHTHAT(B, binary(), byte_size(B) /= PKBytes)]), SK};
|
||||
sk ->
|
||||
SKBytes = enacl:box_secret_key_bytes(),
|
||||
SKBytes = enacl:box_SECRETKEYBYTES(),
|
||||
{PK, oneof([return(a), nat(), ?SUCHTHAT(B, binary(), byte_size(B) /= SKBytes)])}
|
||||
end
|
||||
end).
|
||||
@ -159,8 +159,8 @@ g_generichash_size() ->
|
||||
%% * box_afternm/3
|
||||
%% * box_open_afternm/3
|
||||
keypair_valid(PK, SK) when is_binary(PK), is_binary(SK) ->
|
||||
PKBytes = enacl:box_public_key_bytes(),
|
||||
SKBytes = enacl:box_secret_key_bytes(),
|
||||
PKBytes = enacl:box_PUBLICKEYBYTES(),
|
||||
SKBytes = enacl:box_SECRETKEYBYTES(),
|
||||
byte_size(PK) == PKBytes andalso byte_size(SK) == SKBytes;
|
||||
keypair_valid(_PK, _SK) -> false.
|
||||
|
||||
@ -264,11 +264,11 @@ beforenm_key() ->
|
||||
oneof([
|
||||
elements([a,b,c]),
|
||||
real(),
|
||||
?SUCHTHAT(X, binary(), byte_size(X) /= enacl:box_beforenm_bytes())
|
||||
?SUCHTHAT(X, binary(), byte_size(X) /= enacl:box_BEFORENMBYTES())
|
||||
])
|
||||
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.
|
||||
|
||||
prop_beforenm_correct() ->
|
||||
@ -324,11 +324,11 @@ sign_keypair_bad() ->
|
||||
KP = enacl:sign_keypair(),
|
||||
case X of
|
||||
pk ->
|
||||
Sz = enacl:sign_keypair_public_size(),
|
||||
Sz = enacl:sign_PUBLICBYTES(),
|
||||
?LET(Wrong, oneof([a, int(), ?SUCHTHAT(B, binary(), byte_size(B) /= Sz)]),
|
||||
KP#{ public := Wrong });
|
||||
sk ->
|
||||
Sz = enacl:sign_keypair_secret_size(),
|
||||
Sz = enacl:sign_SECRETBYTES(),
|
||||
?LET(Wrong, oneof([a, int(), ?SUCHTHAT(B, binary(), byte_size(B) /= Sz)]),
|
||||
KP#{ secret := Wrong })
|
||||
end
|
||||
@ -342,12 +342,12 @@ sign_keypair() ->
|
||||
|
||||
sign_keypair_public_valid(#{ public := 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_secret_valid(#{ secret := 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_valid(KP) ->
|
||||
@ -408,11 +408,11 @@ signed_message_good_d(M) ->
|
||||
end)}]).
|
||||
|
||||
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)])}.
|
||||
|
||||
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)])}.
|
||||
|
||||
signed_message(M) ->
|
||||
@ -496,19 +496,19 @@ prop_seal_box_correct() ->
|
||||
%% * secretbox/3
|
||||
%% * secretbo_open/3
|
||||
secret_key_good() ->
|
||||
Sz = enacl:secretbox_key_size(),
|
||||
Sz = enacl:secretbox_KEYBYTES(),
|
||||
binary(Sz).
|
||||
|
||||
secret_key_bad() ->
|
||||
oneof([return(a),
|
||||
nat(),
|
||||
?SUCHTHAT(B, binary(), byte_size(B) /= enacl:secretbox_key_size())]).
|
||||
?SUCHTHAT(B, binary(), byte_size(B) /= enacl:secretbox_KEYBYTES())]).
|
||||
|
||||
secret_key() ->
|
||||
?FAULT(secret_key_bad(), secret_key_good()).
|
||||
|
||||
secret_key_valid(SK) when is_binary(SK) ->
|
||||
Sz = enacl:secretbox_key_size(),
|
||||
Sz = enacl:secretbox_KEYBYTES(),
|
||||
byte_size(SK) == Sz;
|
||||
secret_key_valid(_SK) -> false.
|
||||
|
||||
@ -618,6 +618,27 @@ xor_bytes(<<A, As/binary>>, <<B, Bs/binary>>) ->
|
||||
[A bxor B | xor_bytes(As, Bs)];
|
||||
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
|
||||
%% ------------------------------------------------------------
|
||||
%% * auth/2
|
||||
@ -635,19 +656,19 @@ prop_auth_correct() ->
|
||||
end).
|
||||
|
||||
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) ->
|
||||
Sz = enacl:secretbox_key_size(),
|
||||
Sz = enacl:secretbox_KEYBYTES(),
|
||||
case v_iodata(Msg) andalso byte_size(Key) == Sz of
|
||||
true ->
|
||||
frequency([{1, ?LAZY({invalid, binary(enacl:auth_size())})},
|
||||
frequency([{1, ?LAZY({invalid, binary(enacl:auth_BYTES())})},
|
||||
{3, return({valid, enacl:auth(Msg, Key)})}]);
|
||||
false ->
|
||||
binary(enacl:auth_size())
|
||||
binary(enacl:auth_BYTES())
|
||||
end;
|
||||
authenticator_good(_Msg, _Key) ->
|
||||
binary(enacl:auth_size()).
|
||||
binary(enacl:auth_BYTES()).
|
||||
|
||||
authenticator(Msg, Key) ->
|
||||
?FAULT(authenticator_bad(), authenticator_good(Msg, Key)).
|
||||
@ -690,19 +711,19 @@ prop_onetimeauth_correct() ->
|
||||
end).
|
||||
|
||||
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) ->
|
||||
Sz = enacl:secretbox_key_size(),
|
||||
Sz = enacl:secretbox_KEYBYTES(),
|
||||
case v_iodata(Msg) andalso byte_size(Key) == Sz of
|
||||
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)})}]);
|
||||
false ->
|
||||
binary(enacl:onetime_auth_size())
|
||||
binary(enacl:onetime_auth_BYTES())
|
||||
end;
|
||||
ot_authenticator_good(_Msg, _Key) ->
|
||||
binary(enacl:auth_size()).
|
||||
binary(enacl:auth_BYTES()).
|
||||
|
||||
ot_authenticator(Msg, Key) ->
|
||||
?FAULT(ot_authenticator_bad(), ot_authenticator_good(Msg, Key)).
|
||||
|
132
src/enacl.erl
132
src/enacl.erl
@ -25,14 +25,14 @@
|
||||
box_beforenm/2,
|
||||
box_afternm/3,
|
||||
box_open_afternm/3,
|
||||
box_nonce_size/0,
|
||||
box_public_key_bytes/0,
|
||||
box_secret_key_bytes/0,
|
||||
box_beforenm_bytes/0,
|
||||
box_NONCEBYTES/0,
|
||||
box_PUBLICKEYBYTES/0,
|
||||
box_SECRETKEYBYTES/0,
|
||||
box_BEFORENMBYTES/0,
|
||||
|
||||
sign_keypair_public_size/0,
|
||||
sign_keypair_secret_size/0,
|
||||
sign_keypair_seed_size/0,
|
||||
sign_PUBLICBYTES/0,
|
||||
sign_SECRETBYTES/0,
|
||||
sign_SEEDBYTES/0,
|
||||
sign_keypair/0,
|
||||
sign_seed_keypair/1,
|
||||
sign/2,
|
||||
@ -52,14 +52,14 @@
|
||||
%% Secret key crypto
|
||||
-export([
|
||||
%% EQC
|
||||
secretbox_key_size/0,
|
||||
secretbox_nonce_size/0,
|
||||
secretbox_KEYBYTES/0,
|
||||
secretbox_NONCEBYTES/0,
|
||||
secretbox/3,
|
||||
secretbox_open/3,
|
||||
|
||||
%% No Tests!
|
||||
stream_chacha20_key_size/0,
|
||||
stream_chacha20_nonce_size/0,
|
||||
stream_chacha20_KEYBYTES/0,
|
||||
stream_chacha20_NONCEBYTES/0,
|
||||
stream_chacha20/3,
|
||||
stream_chacha20_xor/3,
|
||||
|
||||
@ -79,22 +79,22 @@
|
||||
aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX/0,
|
||||
|
||||
%% EQC
|
||||
stream_key_size/0,
|
||||
stream_nonce_size/0,
|
||||
stream_KEYBYTES/0,
|
||||
stream_NONCEBYTES/0,
|
||||
stream/3,
|
||||
|
||||
%% No Tests!
|
||||
stream_xor/3,
|
||||
|
||||
%% EQC
|
||||
auth_key_size/0,
|
||||
auth_size/0,
|
||||
auth_KEYBYTES/0,
|
||||
auth_BYTES/0,
|
||||
auth/2,
|
||||
auth_verify/3,
|
||||
|
||||
%% EQC
|
||||
onetime_auth_key_size/0,
|
||||
onetime_auth_size/0,
|
||||
onetime_auth_KEYBYTES/0,
|
||||
onetime_auth_BYTES/0,
|
||||
onetime_auth/2,
|
||||
onetime_auth_verify/3
|
||||
]).
|
||||
@ -189,9 +189,9 @@
|
||||
-define(SECRETBOX_OPEN_REDUCTIONS, 17 * 2).
|
||||
-define(STREAM_SIZE, 16 * 1024).
|
||||
-define(STREAM_REDUCTIONS, 17 * 2).
|
||||
-define(AUTH_SIZE, 4 * 1024).
|
||||
-define(auth_BYTES, 4 * 1024).
|
||||
-define(AUTH_REDUCTIONS, 17 * 2).
|
||||
-define(ONETIME_AUTH_SIZE, 16 * 1024).
|
||||
-define(ONETIME_auth_BYTES, 16 * 1024).
|
||||
-define(ONETIME_AUTH_REDUCTIONS, 16 * 2).
|
||||
-define(ED25519_PUBLIC_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)
|
||||
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.
|
||||
%% @end.
|
||||
-spec box_nonce_size() -> pos_integer().
|
||||
box_nonce_size() ->
|
||||
-spec box_NONCEBYTES() -> pos_integer().
|
||||
box_NONCEBYTES() ->
|
||||
enacl_nif:crypto_box_NONCEBYTES().
|
||||
|
||||
%% @private
|
||||
-spec box_public_key_bytes() -> pos_integer().
|
||||
box_public_key_bytes() ->
|
||||
-spec box_PUBLICKEYBYTES() -> pos_integer().
|
||||
box_PUBLICKEYBYTES() ->
|
||||
enacl_nif:crypto_box_PUBLICKEYBYTES().
|
||||
|
||||
%% @private
|
||||
box_beforenm_bytes() ->
|
||||
box_BEFORENMBYTES() ->
|
||||
enacl_nif:crypto_box_BEFORENMBYTES().
|
||||
|
||||
%% Signatures
|
||||
|
||||
%% @private
|
||||
sign_keypair_public_size() ->
|
||||
sign_PUBLICBYTES() ->
|
||||
enacl_nif:crypto_sign_PUBLICKEYBYTES().
|
||||
|
||||
%% @private
|
||||
sign_keypair_secret_size() ->
|
||||
sign_SECRETBYTES() ->
|
||||
enacl_nif:crypto_sign_SECRETKEYBYTES().
|
||||
|
||||
%% @private
|
||||
sign_keypair_seed_size() ->
|
||||
sign_SEEDBYTES() ->
|
||||
enacl_nif:crypto_sign_SEEDBYTES().
|
||||
|
||||
%% @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).
|
||||
|
||||
%% @private
|
||||
-spec box_secret_key_bytes() -> pos_integer().
|
||||
box_secret_key_bytes() ->
|
||||
-spec box_SECRETKEYBYTES() -> pos_integer().
|
||||
box_SECRETKEYBYTES() ->
|
||||
enacl_nif:crypto_box_SECRETKEYBYTES().
|
||||
|
||||
%% @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)
|
||||
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
|
||||
%% @end
|
||||
secretbox_nonce_size() ->
|
||||
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
|
||||
%% @end
|
||||
secretbox_key_size() ->
|
||||
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
|
||||
-spec stream_chacha20_nonce_size() -> ?CRYPTO_STREAM_CHACHA20_NONCEBYTES.
|
||||
stream_chacha20_nonce_size() ->
|
||||
-spec stream_chacha20_NONCEBYTES() -> ?CRYPTO_STREAM_CHACHA20_NONCEBYTES.
|
||||
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
|
||||
-spec stream_chacha20_key_size() -> ?CRYPTO_STREAM_CHACHA20_KEYBYTES.
|
||||
stream_chacha20_key_size() ->
|
||||
-spec stream_chacha20_KEYBYTES() -> ?CRYPTO_STREAM_CHACHA20_KEYBYTES.
|
||||
stream_chacha20_KEYBYTES() ->
|
||||
?CRYPTO_STREAM_CHACHA20_KEYBYTES.
|
||||
|
||||
%% @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)
|
||||
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
|
||||
-spec stream_nonce_size() -> ?CRYPTO_STREAM_NONCEBYTES.
|
||||
stream_nonce_size() ->
|
||||
-spec stream_NONCEBYTES() -> ?CRYPTO_STREAM_NONCEBYTES.
|
||||
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
|
||||
-spec stream_key_size() -> ?CRYPTO_STREAM_KEYBYTES.
|
||||
stream_key_size() ->
|
||||
-spec stream_KEYBYTES() -> ?CRYPTO_STREAM_KEYBYTES.
|
||||
stream_KEYBYTES() ->
|
||||
?CRYPTO_STREAM_KEYBYTES.
|
||||
|
||||
%% @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)
|
||||
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
|
||||
-spec auth_key_size() -> pos_integer().
|
||||
auth_key_size() ->
|
||||
-spec auth_KEYBYTES() -> pos_integer().
|
||||
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
|
||||
-spec auth_size() -> pos_integer().
|
||||
auth_size() ->
|
||||
-spec auth_BYTES() -> pos_integer().
|
||||
auth_BYTES() ->
|
||||
enacl_nif:crypto_auth_BYTES().
|
||||
|
||||
%% @doc auth/2 produces an authenticator (MAC) for a message
|
||||
@ -893,8 +893,8 @@ auth_size() ->
|
||||
Authenticator :: binary().
|
||||
auth(Msg, Key) ->
|
||||
case iolist_size(Msg) of
|
||||
K when K =< ?AUTH_SIZE ->
|
||||
bump(enacl_nif:crypto_auth_b(Msg, Key), ?AUTH_REDUCTIONS, ?AUTH_SIZE, K);
|
||||
K when K =< ?auth_BYTES ->
|
||||
bump(enacl_nif:crypto_auth_b(Msg, Key), ?AUTH_REDUCTIONS, ?auth_BYTES, K);
|
||||
_ ->
|
||||
enacl_nif:crypto_auth(Msg, Key)
|
||||
end.
|
||||
@ -911,10 +911,10 @@ auth(Msg, Key) ->
|
||||
Key :: binary().
|
||||
auth_verify(A, M, K) ->
|
||||
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),
|
||||
?AUTH_REDUCTIONS,
|
||||
?AUTH_SIZE,
|
||||
?auth_BYTES,
|
||||
K);
|
||||
_ ->
|
||||
enacl_nif:crypto_auth_verify(A, M, K)
|
||||
@ -961,10 +961,10 @@ shorthash(Msg, Key) ->
|
||||
Authenticator :: binary().
|
||||
onetime_auth(Msg, Key) ->
|
||||
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),
|
||||
?ONETIME_AUTH_REDUCTIONS,
|
||||
?ONETIME_AUTH_SIZE,
|
||||
?ONETIME_auth_BYTES,
|
||||
K);
|
||||
_ ->
|
||||
enacl_nif:crypto_onetimeauth(Msg, Key)
|
||||
@ -983,25 +983,25 @@ onetime_auth(Msg, Key) ->
|
||||
Key :: binary().
|
||||
onetime_auth_verify(A, M, K) ->
|
||||
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),
|
||||
?ONETIME_AUTH_REDUCTIONS,
|
||||
?ONETIME_AUTH_SIZE,
|
||||
?ONETIME_auth_BYTES,
|
||||
K);
|
||||
_ ->
|
||||
enacl_nif:crypto_onetimeauth_verify(A, M, K)
|
||||
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
|
||||
-spec onetime_auth_size() -> pos_integer().
|
||||
onetime_auth_size() ->
|
||||
-spec onetime_auth_BYTES() -> pos_integer().
|
||||
onetime_auth_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
|
||||
-spec onetime_auth_key_size() -> pos_integer().
|
||||
onetime_auth_key_size() ->
|
||||
-spec onetime_auth_KEYBYTES() -> pos_integer().
|
||||
onetime_auth_KEYBYTES() ->
|
||||
enacl_nif:crypto_onetimeauth_KEYBYTES().
|
||||
|
||||
%% Curve 25519 Crypto
|
||||
|
@ -133,7 +133,7 @@ sign(_Config) ->
|
||||
{ok, Signature} = enacl:sign_final_create(Create, SK),
|
||||
StateVerify = enacl:sign_init(),
|
||||
Verify = sign_chunked(StateVerify, Msg, 10000),
|
||||
ok = enacl:sign_final_verify(Verify, Signature, PK),
|
||||
true = enacl:sign_final_verify(Verify, Signature, PK),
|
||||
ok.
|
||||
|
||||
sign_chunked(S, _M, 0) -> S;
|
||||
|
Loading…
x
Reference in New Issue
Block a user