diff options
| author | Alexander Motin <mav@FreeBSD.org> | 2008-12-16 13:58:37 +0000 |
|---|---|---|
| committer | Alexander Motin <mav@FreeBSD.org> | 2008-12-16 13:58:37 +0000 |
| commit | f2831a952d06253dd2a15cf5672342d5cffbcb17 (patch) | |
| tree | a1f31956f2edea0480ef1cfc3e6495545975c2ec /sys/crypto | |
| parent | 848552f31fa755beb439d690e2e10c85f012a64a (diff) | |
Notes
Diffstat (limited to 'sys/crypto')
| -rw-r--r-- | sys/crypto/rc4/rc4.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/crypto/rc4/rc4.c b/sys/crypto/rc4/rc4.c index f94a554b98d4..dbdbd7af6aa0 100644 --- a/sys/crypto/rc4/rc4.c +++ b/sys/crypto/rc4/rc4.c @@ -61,7 +61,7 @@ void rc4_init(struct rc4_state *const state, const u_char *key, int keylen) { u_char j; - int i; + int i, k; /* Initialize state with identity permutation */ for (i = 0; i < 256; i++) @@ -70,9 +70,11 @@ rc4_init(struct rc4_state *const state, const u_char *key, int keylen) state->index2 = 0; /* Randomize the permutation using key data */ - for (j = i = 0; i < 256; i++) { - j += state->perm[i] + key[i % keylen]; + for (j = i = k = 0; i < 256; i++) { + j += state->perm[i] + key[k]; swap_bytes(&state->perm[i], &state->perm[j]); + if (++k >= keylen) + k = 0; } } |
