aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2019-01-04 02:26:24 -0800
committerDoug Hogan <[email protected]>2019-01-08 01:11:59 -0800
commit7e8f28265c746f2a8993e34159cc0f4c3363832b (patch)
tree74cffafd61af3467d7208961710aa0220f9f8023 /lib/crypto/c_src
parent10b24fc72ffe49dac252176adfc35f76918626b1 (diff)
downloadotp-7e8f28265c746f2a8993e34159cc0f4c3363832b.tar.gz
otp-7e8f28265c746f2a8993e34159cc0f4c3363832b.tar.bz2
otp-7e8f28265c746f2a8993e34159cc0f4c3363832b.zip
Revamp rc4_encrypt_with_state()
Diffstat (limited to 'lib/crypto/c_src')
-rw-r--r--lib/crypto/c_src/rc4.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/crypto/c_src/rc4.c b/lib/crypto/c_src/rc4.c
index d5b32d88bd..63f8000839 100644
--- a/lib/crypto/c_src/rc4.c
+++ b/lib/crypto/c_src/rc4.c
@@ -57,20 +57,34 @@ ERL_NIF_TERM rc4_encrypt_with_state(ErlNifEnv* env, int argc, const ERL_NIF_TERM
ErlNifBinary state, data;
RC4_KEY* rc4_key;
ERL_NIF_TERM new_state, new_data;
+ unsigned char *outp;
CHECK_NO_FIPS_MODE();
- if (!enif_inspect_iolist_as_binary(env,argv[0], &state)
- || state.size != sizeof(RC4_KEY)
- || !enif_inspect_iolist_as_binary(env,argv[1], &data)) {
- return enif_make_badarg(env);
- }
- rc4_key = (RC4_KEY*)enif_make_new_binary(env, sizeof(RC4_KEY), &new_state);
+ if (argc != 2)
+ goto bad_arg;
+ if (!enif_inspect_iolist_as_binary(env, argv[0], &state))
+ goto bad_arg;
+ if (state.size != sizeof(RC4_KEY))
+ goto bad_arg;
+ if (!enif_inspect_iolist_as_binary(env, argv[1], &data))
+ goto bad_arg;
+
+ if ((rc4_key = (RC4_KEY*)enif_make_new_binary(env, sizeof(RC4_KEY), &new_state)) == NULL)
+ goto err;
+ if ((outp = enif_make_new_binary(env, data.size, &new_data)) == NULL)
+ goto err;
+
memcpy(rc4_key, state.data, sizeof(RC4_KEY));
- RC4(rc4_key, data.size, data.data,
- enif_make_new_binary(env, data.size, &new_data));
- CONSUME_REDS(env,data);
- return enif_make_tuple2(env,new_state,new_data);
+ RC4(rc4_key, data.size, data.data, outp);
+
+ CONSUME_REDS(env, data);
+ return enif_make_tuple2(env, new_state, new_data);
+
+ bad_arg:
+ err:
+ return enif_make_badarg(env);
+
#else
return enif_raise_exception(env, atom_notsup);
#endif