rc4 ksa modification



Hello!

I made some modification to standard rc4 ksa, but I'm not sure if it's
ok?

#include <stddef.h>
#include <stdint.h>

struct rc4
{
uint8_t s[256];
uint8_t i;
uint8_t j;
};

void rc4_ksa(struct rc4 *s, const uint8_t *k, const unsigned int klen)
{
unsigned int i;
unsigned int j;
uint8_t t;

s->i = 0;
s->j = 0;

for(i = 0; i < 256; i++) s->s[i] = i;

/* mix key twice plus 256 for shorter keys, against weak keys?
(instead of drop) */
for(j = 0, i = (klen << 1) + 256; i; i--)
{
s->j = s->j + s->s[s->i] + k[j++];
if(j == klen) j = 0;

t = s->s[s->i];
s->s[s->i] = s->s[s->j];
s->s[s->j] = t;

s->i++;
}
/* standard rc4 sets s->i = s->j = 0 here, but what is the point?
(It's better if attacker doesn't know i and j) */
}
.



Relevant Pages