diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2007-10-07 23:07:25 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2007-10-07 23:07:25 +0100 |
commit | e2869bf14ee7aca93d29edd142d60a7184b4d449 (patch) | |
tree | 6ad9a927fe9d8747647684d149b0b68efe75c9d5 | |
parent | 2305488d0a81193648dec7304f5a6a768e0c926b (diff) |
"Changed" the ArcFour implementation. I'm afraid this was a waste of time,
but at least I added a neat unittest...
-rw-r--r-- | lib/arc.c | 18 | ||||
-rw-r--r-- | tests/check_arc.c | 2 |
2 files changed, 14 insertions, 6 deletions
@@ -60,23 +60,30 @@ struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles ) { struct arc_state *st; int i, j, tmp; + unsigned char S2[256]; st = g_malloc( sizeof( struct arc_state ) ); st->i = st->j = 0; - for( i = 0; i < 256; i ++ ) - st->S[i] = i; - if( kl <= 0 ) kl = strlen( (char*) key ); + for( i = 0; i < 256; i ++ ) + { + st->S[i] = i; + S2[i] = key[i%kl]; + } + for( i = j = 0; i < 256; i ++ ) { - j = ( j + st->S[i] + key[i%kl] ) & 0xff; + j = ( j + st->S[i] + S2[i] ) & 0xff; tmp = st->S[i]; st->S[i] = st->S[j]; st->S[j] = tmp; } + memset( S2, 0, 256 ); + i = j = 0; + for( i = 0; i < cycles; i ++ ) arc_getbyte( st ); @@ -103,8 +110,9 @@ unsigned char arc_getbyte( struct arc_state *st ) tmp = st->S[st->i]; st->S[st->i] = st->S[st->j]; st->S[st->j] = tmp; + tmp = (st->S[st->i] + st->S[st->j]) & 0xff; - return st->S[(st->S[st->i] + st->S[st->j]) & 0xff]; + return st->S[tmp]; } /* diff --git a/tests/check_arc.c b/tests/check_arc.c index a9bc2770..989a0a66 100644 --- a/tests/check_arc.c +++ b/tests/check_arc.c @@ -40,7 +40,7 @@ static void check_codec(int l) struct { - const unsigned char crypted[24]; + unsigned char crypted[24]; int len; char *decrypted; } decrypt_tests[] = { |