Streamline sealed boxes
This commit is contained in:
parent
c791f602e9
commit
71832cce4c
@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
- generichash
|
- generichash
|
||||||
- hash
|
- hash
|
||||||
- kx
|
- kx
|
||||||
- public
|
|
||||||
- pwhash
|
- pwhash
|
||||||
- randombytes
|
- randombytes
|
||||||
- secret
|
- secret
|
||||||
|
@ -255,7 +255,9 @@ ERL_NIF_TERM enacl_crypto_box_seal(ErlNifEnv *env, int argc,
|
|||||||
|
|
||||||
crypto_box_seal(ciphertext.data, msg.data, msg.size, key.data);
|
crypto_box_seal(ciphertext.data, msg.data, msg.size, key.data);
|
||||||
|
|
||||||
return enif_make_binary(env, &ciphertext);
|
ERL_NIF_TERM ret_ok = enif_make_atom(env, ATOM_OK);
|
||||||
|
ERL_NIF_TERM ret_bin = enif_make_binary(env, &ciphertext);
|
||||||
|
return enif_make_tuple2(env, ret_ok, ret_bin);
|
||||||
}
|
}
|
||||||
|
|
||||||
ERL_NIF_TERM enacl_crypto_box_seal_open(ErlNifEnv *env, int argc,
|
ERL_NIF_TERM enacl_crypto_box_seal_open(ErlNifEnv *env, int argc,
|
||||||
@ -283,5 +285,8 @@ ERL_NIF_TERM enacl_crypto_box_seal_open(ErlNifEnv *env, int argc,
|
|||||||
return enacl_error_tuple(env, "failed_verification");
|
return enacl_error_tuple(env, "failed_verification");
|
||||||
}
|
}
|
||||||
|
|
||||||
return enif_make_binary(env, &msg);
|
ERL_NIF_TERM ret_ok = enif_make_atom(env, ATOM_OK);
|
||||||
|
ERL_NIF_TERM ret_bin = enif_make_binary(env, &msg);
|
||||||
|
|
||||||
|
return enif_make_tuple2(env, ret_ok, ret_bin);
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ prop_seal_box_failure_integrity() ->
|
|||||||
begin
|
begin
|
||||||
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
|
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
|
||||||
true ->
|
true ->
|
||||||
CT = enacl:box_seal(Msg, PK1),
|
{ok, CT} = enacl:box_seal(Msg, PK1),
|
||||||
Err = enacl:box_seal_open([<<"x">>, CT], PK1, SK1),
|
Err = enacl:box_seal_open([<<"x">>, CT], PK1, SK1),
|
||||||
equals(Err, {error, failed_verification});
|
equals(Err, {error, failed_verification});
|
||||||
false ->
|
false ->
|
||||||
@ -450,7 +450,7 @@ prop_seal_box_correct() ->
|
|||||||
begin
|
begin
|
||||||
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
|
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
|
||||||
true ->
|
true ->
|
||||||
SealedCipherText = enacl:box_seal(Msg, PK1),
|
{ok, SealedCipherText} = enacl:box_seal(Msg, PK1),
|
||||||
{ok, DecodedMsg} = enacl:box_seal_open(SealedCipherText, PK1, SK1),
|
{ok, DecodedMsg} = enacl:box_seal_open(SealedCipherText, PK1, SK1),
|
||||||
equals(iolist_to_binary(Msg), DecodedMsg);
|
equals(iolist_to_binary(Msg), DecodedMsg);
|
||||||
false ->
|
false ->
|
||||||
|
@ -685,7 +685,7 @@ box_secret_key_bytes() ->
|
|||||||
%% keypair and then uses `box'. Ephemeral public key will sent to other party. Returns the
|
%% keypair and then uses `box'. Ephemeral public key will sent to other party. Returns the
|
||||||
%% enciphered message `SealedCipherText' which includes ephemeral public key at head.
|
%% enciphered message `SealedCipherText' which includes ephemeral public key at head.
|
||||||
%% @end
|
%% @end
|
||||||
-spec box_seal(Msg, PK) -> SealedCipherText
|
-spec box_seal(Msg, PK) -> {ok, SealedCipherText} | {error, term()}
|
||||||
when
|
when
|
||||||
Msg :: iodata(),
|
Msg :: iodata(),
|
||||||
PK :: binary(),
|
PK :: binary(),
|
||||||
@ -706,10 +706,7 @@ box_seal(Msg, PK) ->
|
|||||||
SK :: binary(),
|
SK :: binary(),
|
||||||
Msg :: binary().
|
Msg :: binary().
|
||||||
box_seal_open(SealedCipherText, PK, SK) ->
|
box_seal_open(SealedCipherText, PK, SK) ->
|
||||||
case enacl_nif:crypto_box_seal_open(SealedCipherText, PK, SK) of
|
enacl_nif:crypto_box_seal_open(SealedCipherText, PK, SK).
|
||||||
{error, Err} -> {error, Err};
|
|
||||||
Bin when is_binary(Bin) -> {ok, Bin}
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% @doc secretbox/3 encrypts a message with a key
|
%% @doc secretbox/3 encrypts a message with a key
|
||||||
%%
|
%%
|
||||||
|
Loading…
x
Reference in New Issue
Block a user