From 5a313cb363e2f74ed0c602482c609fcc6dcc718a Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Tue, 12 Mar 2019 15:07:43 +0100 Subject: crypto: Rename SSL special functions to crypto_init_dyn_iv/3 and crypto_update_dyn_iv/3 --- lib/crypto/src/crypto.erl | 63 ++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl index 4bceeb7510..5cf34f8069 100644 --- a/lib/crypto/src/crypto.erl +++ b/lib/crypto/src/crypto.erl @@ -56,9 +56,11 @@ ]). %% New interface --export([crypto_init/4, crypto_init/3, crypto_init/2, - crypto_update/2, crypto_update/3, - crypto_one_shot/5 +-export([crypto_init/4, crypto_init/3, + crypto_update/2, + crypto_one_shot/5, + crypto_init_dyn_iv/3, + crypto_update_dyn_iv/3 ]). @@ -721,24 +723,39 @@ next_iv(Type, Data, _Ivec) -> %%% Create and initialize a new state for encryption or decryption %%% +-spec crypto_init(Cipher, Key, EncryptFlag) -> State | ng_crypto_error() + when Cipher :: block_cipher_without_iv() + | stream_cipher_no_iv(), + Key :: iodata(), + EncryptFlag :: boolean(), + State :: crypto_state() . +crypto_init(Cipher, Key, EncryptFlag) -> + %% The IV is supposed to be supplied by calling crypto_update/3 + ng_crypto_init_nif(alias(Cipher), iolist_to_binary(Key), <<>>, EncryptFlag). + + -spec crypto_init(Cipher, Key, IV, EncryptFlag) -> State | ng_crypto_error() - when Cipher :: stream_cipher() - | block_cipher_with_iv() - | block_cipher_without_iv(), + when Cipher :: stream_cipher_iv() + | block_cipher_with_iv(), Key :: iodata(), - IV :: iodata() | undefined, + IV :: iodata(), EncryptFlag :: boolean(), State :: crypto_state() . -crypto_init(Cipher, Key, undefined, EncryptFlag) -> - %% The IV is supposed to be supplied by calling crypto_update/3 - ng_crypto_init_nif(alias(Cipher), - iolist_to_binary(Key), undefined, - EncryptFlag); - crypto_init(Cipher, Key, IV, EncryptFlag) -> - ng_crypto_init_nif(alias(Cipher), - iolist_to_binary(Key), iolist_to_binary(IV), - EncryptFlag). + ng_crypto_init_nif(alias(Cipher), iolist_to_binary(Key), iolist_to_binary(IV), EncryptFlag). + + + +%%%---------------------------------------------------------------- +-spec crypto_init_dyn_iv(Cipher, Key, EncryptFlag) -> State | ng_crypto_error() + when Cipher :: stream_cipher_iv() + | block_cipher_with_iv(), + Key :: iodata(), + EncryptFlag :: boolean(), + State :: crypto_state() . +crypto_init_dyn_iv(Cipher, Key, EncryptFlag) -> + %% The IV is supposed to be supplied by calling crypto_update/3 + ng_crypto_init_nif(alias(Cipher), iolist_to_binary(Key), undefined, EncryptFlag). %%%---------------------------------------------------------------- %%% @@ -760,12 +777,13 @@ crypto_update(State, Data0) -> end. --spec crypto_update(State, Data, IV) -> Result | ng_crypto_error() - when State :: crypto_state(), - Data :: iodata(), - IV :: iodata(), - Result :: binary() . -crypto_update(State, Data0, IV) -> +%%%---------------------------------------------------------------- +-spec crypto_update_dyn_iv(State, Data, IV) -> Result | ng_crypto_error() + when State :: crypto_state(), + Data :: iodata(), + IV :: iodata(), + Result :: binary() . +crypto_update_dyn_iv(State, Data0, IV) -> %% When State is from State = crypto_init(Cipher, Key, undefined, EncryptFlag) case iolist_to_binary(Data0) of <<>> -> @@ -774,7 +792,6 @@ crypto_update(State, Data0, IV) -> ng_crypto_update_nif(State, Data, iolist_to_binary(IV)) end. - %%%---------------------------------------------------------------- %%% %%% Encrypt/decrypt one set bytes. -- cgit v1.2.3