Update enacl dep and fix some minor details (#1)
Co-authored-by: Ulf Wiger <ulf@wiger.net> Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -54,12 +54,8 @@ set_nonce(CState = #noise_cs{}, Nonce) ->
|
||||
encrypt_with_ad(CState = #noise_cs{ k = empty }, _AD, PlainText) ->
|
||||
{ok, CState, PlainText};
|
||||
encrypt_with_ad(CState = #noise_cs{ k = K, n = N, cipher = Cipher }, AD, PlainText) ->
|
||||
case enoise_crypto:encrypt(Cipher, K, N, AD, PlainText) of
|
||||
Encrypted when is_binary(Encrypted) ->
|
||||
{ok, CState#noise_cs{ n = N+1 }, Encrypted};
|
||||
Err = {error, _} ->
|
||||
Err
|
||||
end.
|
||||
Encrypted = enoise_crypto:encrypt(Cipher, K, N, AD, PlainText),
|
||||
{ok, CState#noise_cs{ n = N+1 }, Encrypted}.
|
||||
|
||||
-spec decrypt_with_ad(CState :: state(), AD :: binary(), CipherText :: binary()) ->
|
||||
{ok, state(), binary()} | {error, term()}.
|
||||
|
||||
@@ -65,8 +65,7 @@ rekey(Cipher, K) ->
|
||||
|
||||
-spec encrypt(Cipher :: enoise_cipher_state:noise_cipher(),
|
||||
Key :: binary(), Nonce :: non_neg_integer(),
|
||||
Ad :: binary(), PlainText :: binary()) ->
|
||||
binary() | {error, term()}.
|
||||
Ad :: binary(), PlainText :: binary()) -> binary().
|
||||
encrypt('ChaChaPoly', K, N, Ad, PlainText) ->
|
||||
Nonce = <<0:32, N:64/little-unsigned-integer>>,
|
||||
enacl:aead_chacha20poly1305_ietf_encrypt(PlainText, Ad, Nonce, K);
|
||||
|
||||
Reference in New Issue
Block a user