Improve and verify sign_*_detached functions.
Provide non-dirty-scheduler variants for small strings, accurately bump reductions for these strings. While here, provide EQC test cases for the two functions.
This commit is contained in:
+15
-3
@@ -395,7 +395,13 @@ sign_open(SM, PK) ->
|
||||
M :: iodata(),
|
||||
SK :: binary(),
|
||||
DS :: binary().
|
||||
sign_detached(M, SK) -> enacl_nif:crypto_sign_detached(M, SK).
|
||||
sign_detached(M, SK) ->
|
||||
case iolist_size(M) of
|
||||
K when K =< ?SIGN_SIZE ->
|
||||
bump(enacl_nif:crypto_sign_detached_b(M, SK), ?SIGN_REDUCTIONS, ?SIGN_SIZE, K);
|
||||
_ ->
|
||||
enacl_nif:crypto_sign_detached(M, SK)
|
||||
end.
|
||||
|
||||
%% @doc sign_verify_detached/3 verifies the given signature against the given
|
||||
%% message for the given public key.
|
||||
@@ -408,8 +414,14 @@ sign_detached(M, SK) -> enacl_nif:crypto_sign_detached(M, SK).
|
||||
M :: iodata(),
|
||||
PK :: binary().
|
||||
sign_verify_detached(SIG, M, PK) ->
|
||||
case enacl_nif:crypto_sign_verify_detached(SIG, M, PK) of
|
||||
true -> {ok, M};
|
||||
SignRes = case iolist_size(M) of
|
||||
K when K =< ?SIGN_SIZE ->
|
||||
bump(enacl_nif:crypto_sign_verify_detached_b(SIG, M, PK), ?SIGN_REDUCTIONS, ?SIGN_SIZE, K);
|
||||
_ ->
|
||||
enacl_nif:crypto_sign_detached(SIG, M, PK)
|
||||
end,
|
||||
case SignRes of
|
||||
true -> {ok, M};
|
||||
false -> {error, failed_verification}
|
||||
end.
|
||||
|
||||
|
||||
+6
-1
@@ -34,7 +34,9 @@
|
||||
crypto_sign_open_b/2,
|
||||
|
||||
crypto_sign_detached/2,
|
||||
crypto_sign_detached_b/2,
|
||||
crypto_sign_verify_detached/3,
|
||||
crypto_sign_verify_detached_b/3,
|
||||
|
||||
crypto_box_seal/2,
|
||||
crypto_box_seal_open/3,
|
||||
@@ -153,7 +155,10 @@ crypto_sign_open(_SignedMessage, _PK) -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_sign_open_b(_SignedMessage, _PK) -> erlang:nif_error(nif_not_loaded).
|
||||
|
||||
crypto_sign_detached(_M, _SK) -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_sign_verify_detached(_SIG, _M, _PK) -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_sign_detached_b(_M, _SK) -> erlang:nif_error(nif_not_loaded).
|
||||
|
||||
crypto_sign_verify_detached(_Sig, _M, _PK) -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_sign_verify_detached_b(_Sig, _M, _PK) -> erlang:nif_error(nif_not_loaded).
|
||||
|
||||
crypto_box_seal(_Msg, _PK) -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_box_seal_open(_CipherText, _PK, _SK) -> erlang:nif_error(nif_not_loaded).
|
||||
|
||||
Reference in New Issue
Block a user