11 RCSID(
"$Id: 26a821633e00d0fed1f4db9f17345c271f85a515 $")
13 #include <freeradius-devel/util/rand.h>
16 #define RANDSIZ (1 << RANDSIZL)
18 #define ind(mm,x) ((mm)[(x >> 2) &(RANDSIZ-1)])
19 #define rngstep(mix, a, b, mm, m, m2, r, x) \
22 a = ((a^(mix)) + *(m2++)) & 0xffffffff; \
23 *(m++) = y = (ind(mm, x) + a + b) & 0xffffffff; \
24 *(r++) = b = (ind(mm, y >> RANDSIZL) + x) & 0xffffffff; \
35 #define rotr(x, n) (((x) << n) | ((x) >> (32 - n)))
36 #define ind(mm,x) ((mm)[rotr(x, 2) & (RANDSIZ-1)])
37 #define rngstep(mix, a, b, mm, m, m2, r, x) \
40 a = ((a^(mix)) + *(m2++)) & 0xffffffff; \
41 *(m++) = y = (ind(mm, x) + (a ^ b)) & 0xffffffff; \
42 *(r++) = b = ((ind(mm, y >> RANDSIZL) ^ a) + x) & 0xffffffff; \
48 register uint32_t a, b, x,
y, *m, *mm, *m2, *r, *mend;
53 b = (ctx->
randb + (++ctx->
randc)) & 0xffffffff;
55 for (m = mm, mend = m2 = m + (
RANDSIZ / 2); m < mend; ) {
56 rngstep(a << 13, a, b, mm, m, m2, r, x);
57 rngstep(a >> 6 , a, b, mm, m, m2, r, x);
58 rngstep(a << 2 , a, b, mm, m, m2, r, x);
59 rngstep(a >> 16, a, b, mm, m, m2, r, x);
61 for (m2 = mm; m2 < mend; ) {
62 rngstep(a << 13, a, b, mm, m, m2, r, x);
63 rngstep(a >> 6 , a, b, mm, m, m2, r, x);
64 rngstep(a << 2 , a, b, mm, m, m2, r, x);
65 rngstep(a >> 16, a, b, mm, m, m2, r, x);
72 #define mix(a,b,c,d,e,f,g,h) \
74 a ^= b << 11; d += a; b += c; \
75 b ^= c >> 2; e += b; c += d; \
76 c ^= d << 8; f += c; d += e; \
77 d ^= e >> 16; g += d; e += f; \
78 e ^= f << 10; h += e; f += g; \
79 f ^= g >> 4; a += f; g += h; \
80 g ^= h << 8; b += g; h += a; \
81 h ^= a >> 9; c += h; a += b; \
94 a = b = c = d = e = f = g = h = 0x9e3779b9;
97 for (i = 0; i < 4; ++i) {
99 mix(a, b, c, d, e, f, g, h);
104 for (i = 0; i <
RANDSIZ; i += 8) {
105 a += r[i ]; b += r[i + 1]; c +=r [i + 2]; d += r[i + 3];
106 e += r[i + 4]; f += r[i + 5]; g +=r [i + 6]; h += r[i + 7];
107 mix(a, b, c, d, e, f, g, h);
108 m[i ] = a; m[i + 1] = b; m[i + 2] = c; m[i + 3] = d;
109 m[i + 4] = e; m[i + 5] = f; m[i + 6] = g; m[i + 7] = h;
112 for (i = 0; i <
RANDSIZ; i += 8) {
113 a += m[i ]; b += m[i + 1]; c += m[i + 2]; d += m[i + 3];
114 e += m[i + 4]; f += m[i + 5]; g += m[i + 6]; h += m[i + 7];
115 mix(a, b, c, d, e, f, g, h);
116 m[i ] = a; m[i + 1] = b; m[i + 2] = c; m[i + 3] = d;
117 m[i + 4] = e; m[i + 5] = f; m[i + 6] = g; m[i + 7] = h;
120 for (i = 0; i <
RANDSIZ; i += 8) {
122 mix(a, b, c, d, e, f, g, h);
123 m[i ] = a; m[i + 1] = b; m[i + 2] = c; m[i + 3] = d;
124 m[i + 4] = e; m[i + 5] = f; m[i + 6] = g; m[i + 7] = h;
149 for (i = 0; i < 2; ++i) {
151 for (j = 0; j < 256; ++j) {
152 printf(
"%.8lx",ctx.
randrsl[j]);
153 if ((j & 7) == 7) printf(
"\n");
int main(int argc, char **argv)
void fr_isaac_init(fr_randctx *ctx, int flag)
void fr_isaac(fr_randctx *ctx)
#define rngstep(mix, a, b, mm, m, m2, r, x)
#define mix(a, b, c, d, e, f, g, h)