aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arc.c18
-rw-r--r--tests/check_arc.c2
2 files changed, 14 insertions, 6 deletions
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];
}
/*
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[] = {