if(idx1 >= keylen)
idx1 = 0;
}
-
+
+#ifdef RC4_MITIGATE
+ /*
+ * Discard the first 3072 pseudorandom bytes to mitigate some arcfour
+ * vulnerabilities related to the weak key scheduling algorithm.
+ * Unfortunately this makes the implementation incompatible with legacy
+ * ones, meaning that all servers of the network should enable this at the
+ * same time. Ideally, inter-server links should eventually use SSL.
+ */
+ {
+ RC4BYTE *s = rc4->mstate;
+ RC4DWORD x, y, a, b;
+
+ for (x = rc4->x, y = rc4->y, i = 0;
+ i < 3072; i++) {
+ x = (x + 1) & 0xff;
+ a = s[x];
+ y = (y + a) & 0xff;
+ b = s[y];
+ s[x] = b;
+ s[y] = a;
+ }
+ rc4->x = (RC4BYTE)x;
+ rc4->y = (RC4BYTE)y;
+ }
+#endif
+
return (void *) rc4;
}