aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2019-02-28 19:59:30 +0100
committerHans Nilsson <[email protected]>2019-03-19 12:45:54 +0100
commitfcc89ded7f5cb5f81533883c30e7daa89195970d (patch)
tree9c8338ae42ef54f4c3be7095b6317201e0d99647 /lib/crypto
parent47b496da10cfedeea8a0341ce13c76de3c132a57 (diff)
downloadotp-fcc89ded7f5cb5f81533883c30e7daa89195970d.tar.gz
otp-fcc89ded7f5cb5f81533883c30e7daa89195970d.tar.bz2
otp-fcc89ded7f5cb5f81533883c30e7daa89195970d.zip
crypto: Remove condition of block size
Unnecessary, because the underlying crypto libraries handles this case. Also: - Relax the condition of binary Key and IV -Fix bug for empty data on historic cryptolibs because tests fails for empty data on at least aes_cfb8 on OpenSSL 0.9.8h. It does not fail on OpenSSL 0.9.8zh.
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/c_src/api_ng.c2
-rw-r--r--lib/crypto/src/crypto.erl21
2 files changed, 13 insertions, 10 deletions
diff --git a/lib/crypto/c_src/api_ng.c b/lib/crypto/c_src/api_ng.c
index c4114d1626..f24aded748 100644
--- a/lib/crypto/c_src/api_ng.c
+++ b/lib/crypto/c_src/api_ng.c
@@ -165,8 +165,6 @@ ERL_NIF_TERM ng_crypto_update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[
ASSERT(in_data_bin.size =< INT_MAX);
block_size = EVP_CIPHER_CTX_block_size(ctx->ctx);
- if (in_data_bin.size % (size_t)block_size != 0)
- return ERROR_Str(env, "Data not a multiple of block size");
if (argc==3) {
if (!enif_inspect_iolist_as_binary(env, argv[2], &ivec_bin))
diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl
index 97a4a7a3f0..8d6d24210a 100644
--- a/lib/crypto/src/crypto.erl
+++ b/lib/crypto/src/crypto.erl
@@ -2252,15 +2252,15 @@ check_otp_test_engine(LibDir) ->
| block_cipher_with_iv()
| block_cipher_without_iv() ,
Key :: iodata(),
- IV :: binary(),
+ IV :: iodata(),
EncryptFlag :: boolean() | undefined,
State :: crypto_state() .
-crypto_init(Cipher, Key, IV, EncryptFlag) when is_atom(Cipher),
- is_binary(Key),
- is_binary(IV),
- is_atom(EncryptFlag) ->
- case ng_crypto_init_nif(alias(Cipher), Key, IV, EncryptFlag) of
+crypto_init(Cipher, Key, IV, EncryptFlag) ->
+ case ng_crypto_init_nif(alias(Cipher),
+ iolist_to_binary(Key),
+ iolist_to_binary(IV),
+ EncryptFlag) of
{error,Error} ->
{error,Error};
undefined -> % For compatibility function crypto_stream_init/3
@@ -2284,8 +2284,13 @@ crypto_init(Cipher, Key, IV, EncryptFlag) when is_atom(Cipher),
when State :: crypto_state(),
Data :: iodata(),
Result :: binary() | {crypto_state(),binary()}.
-crypto_update(State, Data) ->
- mk_ret(ng_crypto_update_nif(State, Data)).
+crypto_update(State, Data0) ->
+ case iolist_to_binary(Data0) of
+ <<>> ->
+ <<>>; % Known to fail on OpenSSL 0.9.8h
+ Data ->
+ mk_ret(ng_crypto_update_nif(State, Data))
+ end.
%%%----------------------------------------------------------------
%%%