aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-01-19 19:03:36 +0100
committerSverker Eriksson <[email protected]>2016-01-19 19:03:36 +0100
commita741a2f03d7a73222c3cfbecbd6c0c32ac598e7c (patch)
treefd13176838864a11c51b6cd0137e0643c6b2aaea
parentdaa9ca6ff54697b18d407ae91a91b587662dfc99 (diff)
parent64248a85e221a905aa37fbb8dd0ab1d4f4551be0 (diff)
downloadotp-a741a2f03d7a73222c3cfbecbd6c0c32ac598e7c.tar.gz
otp-a741a2f03d7a73222c3cfbecbd6c0c32ac598e7c.tar.bz2
otp-a741a2f03d7a73222c3cfbecbd6c0c32ac598e7c.zip
Merge branch 'sverk/crypto-aec-ecb-multiblock' into maint
OTP-13249 * sverk/crypto-aec-ecb-multiblock: crypto: Fix bug for multiple blocks for AES-ECB
-rw-r--r--lib/crypto/c_src/crypto.c5
-rw-r--r--lib/crypto/test/crypto_SUITE.erl18
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 9de8dc74c2..3c73c318ed 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -2042,6 +2042,7 @@ static ERL_NIF_TERM aes_ecb_crypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM a
ErlNifBinary key_bin, data_bin;
AES_KEY aes_key;
int i;
+ int j;
unsigned char* ret_ptr;
ERL_NIF_TERM ret;
@@ -2064,7 +2065,9 @@ static ERL_NIF_TERM aes_ecb_crypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM a
}
ret_ptr = enif_make_new_binary(env, data_bin.size, &ret);
- AES_ecb_encrypt(data_bin.data, ret_ptr, &aes_key, i);
+ for (j = 0; j < data_bin.size; j += 16) {
+ AES_ecb_encrypt(data_bin.data+j, ret_ptr+j, &aes_key, i);
+ }
CONSUME_REDS(env,data_bin);
return ret;
}
diff --git a/lib/crypto/test/crypto_SUITE.erl b/lib/crypto/test/crypto_SUITE.erl
index e84f5e1075..802c8a4df4 100644
--- a/lib/crypto/test/crypto_SUITE.erl
+++ b/lib/crypto/test/crypto_SUITE.erl
@@ -1301,7 +1301,23 @@ aes_ecb() ->
<<"0000000000000000">>},
{aes_ecb,
<<"FEDCBA9876543210">>,
- <<"FFFFFFFFFFFFFFFF">>}
+ <<"FFFFFFFFFFFFFFFF">>},
+ %% AES ECB test vectors from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
+ %% F.1.1 ECB-AES128.Encrypt, F.1.2 ECB-AES128.Decrypt
+ {aes_ecb,
+ hexstr2bin("2b7e151628aed2a6abf7158809cf4f3c"),
+ hexstr2bin("6bc1bee22e409f96e93d7e117393172a"
+ "ae2d8a571e03ac9c9eb76fac45af8e51"
+ "30c81c46a35ce411e5fbc1191a0a52ef"
+ "f69f2445df4f9b17ad2b417be66c3710")},
+ %% F.1.5 ECB-AES256.Encrypt, F.1.6 ECB-AES256.Decrypt
+ {aes_ecb,
+ hexstr2bin("603deb1015ca71be2b73aef0857d7781"
+ "1f352c073b6108d72d9810a30914dff4"),
+ hexstr2bin("6bc1bee22e409f96e93d7e117393172a"
+ "ae2d8a571e03ac9c9eb76fac45af8e51"
+ "30c81c46a35ce411e5fbc1191a0a52ef"
+ "f69f2445df4f9b17ad2b417be66c3710")}
].
aes_ige256() ->