aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src/crypto.c
diff options
context:
space:
mode:
authorKelly McLaughlin <[email protected]>2015-01-30 15:25:03 -0700
committerKelly McLaughlin <[email protected]>2015-02-04 11:52:59 -0700
commita1fa5b86e2241a6409d3278ebc39dbc6a07fcae4 (patch)
treebd141e2b98ebf12b64465e276b9ee37459ec1a2d /lib/crypto/c_src/crypto.c
parent6f19eae6d1df8d6892a3f665d3cf38d3cc5359fc (diff)
downloadotp-a1fa5b86e2241a6409d3278ebc39dbc6a07fcae4.tar.gz
otp-a1fa5b86e2241a6409d3278ebc39dbc6a07fcae4.tar.bz2
otp-a1fa5b86e2241a6409d3278ebc39dbc6a07fcae4.zip
Accept all valid key sizes in aes_cfb functions
Despite the confusion caused by the name, aes_cfb_8_crypt and aes_cfb_128_crypt can use key lengths of 128, 192, or 256. The integer in the function name refers to the block size for CFB mode. Change the aes_cfb_8_crypt and aes_cfb_128_crypt functions to accept and use keys of length 128, 192, or 256. Also augment the existing testing for these functions using the NIST test vectors for the additional key lengths to ensure the changes function properly.
Diffstat (limited to 'lib/crypto/c_src/crypto.c')
-rw-r--r--lib/crypto/c_src/crypto.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index e7215eeb64..26e2486dc2 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -1644,14 +1644,15 @@ static ERL_NIF_TERM aes_cfb_8_crypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM
int new_ivlen = 0;
ERL_NIF_TERM ret;
- if (!enif_inspect_iolist_as_binary(env, argv[0], &key) || key.size != 16
+ if (!enif_inspect_iolist_as_binary(env, argv[0], &key)
+ || !(key.size == 16 || key.size == 24 || key.size == 32)
|| !enif_inspect_binary(env, argv[1], &ivec) || ivec.size != 16
|| !enif_inspect_iolist_as_binary(env, argv[2], &text)) {
return enif_make_badarg(env);
}
memcpy(ivec_clone, ivec.data, 16);
- AES_set_encrypt_key(key.data, 128, &aes_key);
+ AES_set_encrypt_key(key.data, key.size * 8, &aes_key);
AES_cfb8_encrypt((unsigned char *) text.data,
enif_make_new_binary(env, text.size, &ret),
text.size, &aes_key, ivec_clone, &new_ivlen,
@@ -1670,14 +1671,15 @@ static ERL_NIF_TERM aes_cfb_128_crypt(ErlNifEnv* env, int argc, const ERL_NIF_TE
CHECK_OSE_CRYPTO();
- if (!enif_inspect_iolist_as_binary(env, argv[0], &key) || key.size != 16
+ if (!enif_inspect_iolist_as_binary(env, argv[0], &key)
+ || !(key.size == 16 || key.size == 24 || key.size == 32)
|| !enif_inspect_binary(env, argv[1], &ivec) || ivec.size != 16
|| !enif_inspect_iolist_as_binary(env, argv[2], &text)) {
return enif_make_badarg(env);
}
memcpy(ivec_clone, ivec.data, 16);
- AES_set_encrypt_key(key.data, 128, &aes_key);
+ AES_set_encrypt_key(key.data, key.size * 8, &aes_key);
AES_cfb128_encrypt((unsigned char *) text.data,
enif_make_new_binary(env, text.size, &ret),
text.size, &aes_key, ivec_clone, &new_ivlen,