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 /lib | |
| parent | 2305488d0a81193648dec7304f5a6a768e0c926b (diff) | |
"Changed" the ArcFour implementation. I'm afraid this was a waste of time,
but at least I added a neat unittest...
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/arc.c | 18 | 
1 files changed, 13 insertions, 5 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];  }  /* | 
