aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRickard Green <[email protected]>2010-08-30 13:23:16 +0200
committerRickard Green <[email protected]>2010-08-30 13:25:13 +0200
commit0bcb7009fe4f3bbdf630c226d7e7335f9c005cf0 (patch)
treeb997b95c74db8b383d8656bb2b92b899ba8bd22f
parent4f100fff5844f7af08b1d9be23e990e4a48b27de (diff)
parentc1af26a59c46a6f9d295a0374326574157f6d8a5 (diff)
downloadotp-0bcb7009fe4f3bbdf630c226d7e7335f9c005cf0.tar.gz
otp-0bcb7009fe4f3bbdf630c226d7e7335f9c005cf0.tar.bz2
otp-0bcb7009fe4f3bbdf630c226d7e7335f9c005cf0.zip
Merge branch 'pg/fix-crypto-rc4_encrypt_with_state' into dev
* pg/fix-crypto-rc4_encrypt_with_state: Fix RC4 stream cipher binding (crypto:rc4_encrypt_with_state/2) OTP-8781 - RC4 stream cipher didn't work. This since the new NIF implementation of crypto:rc4_encrypt_with_state/2 introduced in crypto-2.0 didn't return an updated state. (Thanks to Paul Guyot)
-rw-r--r--lib/crypto/c_src/crypto.c2
-rw-r--r--lib/crypto/test/crypto_SUITE.erl19
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 68079f06c7..8823bba3b6 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -950,7 +950,7 @@ static ERL_NIF_TERM rc4_encrypt_with_state(ErlNifEnv* env, int argc, const ERL_N
RC4(rc4_key, data.size, data.data,
enif_make_new_binary(env, data.size, &new_data));
- return enif_make_tuple2(env,argv[0],new_data);
+ return enif_make_tuple2(env,new_state,new_data);
}
static ERL_NIF_TERM rc2_40_cbc_crypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
diff --git a/lib/crypto/test/crypto_SUITE.erl b/lib/crypto/test/crypto_SUITE.erl
index 576949d38d..06b284d50d 100644
--- a/lib/crypto/test/crypto_SUITE.erl
+++ b/lib/crypto/test/crypto_SUITE.erl
@@ -54,6 +54,7 @@
dh/1,
exor_test/1,
rc4_test/1,
+ rc4_stream_test/1,
blowfish_cfb64/1,
smp/1,
cleanup/1]).
@@ -89,6 +90,7 @@ all(suite) ->
dh,
exor_test,
rc4_test,
+ rc4_stream_test,
mod_exp_test,
blowfish_cfb64,
smp],
@@ -979,6 +981,21 @@ rc4_test(Config) when is_list(Config) ->
CT2 = binary_to_list(crypto:rc4_encrypt(K, R2)),
ok.
+rc4_stream_test(doc) ->
+ ["Test rc4 stream encryption ."];
+rc4_stream_test(suite) ->
+ [];
+rc4_stream_test(Config) when is_list(Config) ->
+ CT1 = <<"hej">>,
+ CT2 = <<" p� dig">>,
+ K = "apaapa",
+ State0 = crypto:rc4_set_key(K),
+ {State1, R1} = crypto:rc4_encrypt_with_state(State0, CT1),
+ {_State2, R2} = crypto:rc4_encrypt_with_state(State1, CT2),
+ R = list_to_binary([R1, R2]),
+ <<71,112,14,44,140,33,212,144,155,47>> = R,
+ ok.
+
blowfish_cfb64(doc) -> ["Test Blowfish encrypt/decrypt."];
blowfish_cfb64(suite) -> [];
blowfish_cfb64(Config) when is_list(Config) ->
@@ -1029,7 +1046,7 @@ worker_loop(0, _) ->
worker_loop(N, Config) ->
Funcs = { md5, md5_update, md5_mac, md5_mac_io, sha, sha_update, des_cbc,
aes_cfb, aes_cbc, des_cbc_iter, rand_uniform_test,
- rsa_verify_test, exor_test, rc4_test, mod_exp_test },
+ rsa_verify_test, exor_test, rc4_test, rc4_stream_test, mod_exp_test },
F = element(random:uniform(size(Funcs)),Funcs),
%%io:format("worker ~p calling ~p\n",[self(),F]),