Method: RFuzz::FuzzRnd#initialize
- Defined in:
- ext/fuzzrnd/fuzzrnd.c
#seed ⇒ Object
Seeds the global ArcFour random generator with the given seed. The same seeds should produce the exact same stream of random data so that you can get large amounts of randomness but replay possible interactions using just an initial key.
This function also doubles as the FuzzRnd.initialize method since they do nearly the same thing.
Taken from www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt sample code, but compared with the output of the ArcFour implementation in the Phelix test code to make sure it is the same initialization. The main difference is that this init takes an arbitrary keysize while the original Phelix ArcFour only took a 32bit key.
Returns itself so you can seed and then get data easily.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'ext/fuzzrnd/fuzzrnd.c', line 99
VALUE FuzzRnd_seed(VALUE self, VALUE data) {
unsigned int t, u;
unsigned int keyindex;
unsigned int stateindex;
unsigned char *state;
unsigned int counter;
char *key = NULL;
size_t key_len = 0;
REQUIRE_TYPE(data, T_STRING);
key = RSTRING(data)->ptr;
key_len = RSTRING(data)->len;
state = ArcFour.sbox;
ArcFour.i = 0;
ArcFour.j = 0;
for (counter = 0; counter < 256; counter++)
state[counter] = counter;
keyindex = 0;
stateindex = 0;
for (counter = 0; counter < 256; counter++)
{
t = state[counter];
stateindex = (stateindex + key[keyindex] + t) & 0xff;
u = state[stateindex];
state[stateindex] = t;
state[counter] = u;
if (++keyindex >= key_len)
keyindex = 0;
}
return self;
}
|