From e2869bf14ee7aca93d29edd142d60a7184b4d449 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 7 Oct 2007 23:07:25 +0100 Subject: "Changed" the ArcFour implementation. I'm afraid this was a waste of time, but at least I added a neat unittest... --- lib/arc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'lib/arc.c') diff --git a/lib/arc.c b/lib/arc.c index a8e863f2..617f6b96 100644 --- a/lib/arc.c +++ b/lib/arc.c @@ -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]; } /* -- cgit v1.2.3