diff options
Diffstat (limited to 'src/dnsstub/dns_random.c')
-rw-r--r-- | src/dnsstub/dns_random.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/dnsstub/dns_random.c b/src/dnsstub/dns_random.c index 200cd6c..8b89244 100644 --- a/src/dnsstub/dns_random.c +++ b/src/dnsstub/dns_random.c @@ -1,7 +1,8 @@ #include <unistd.h> + +#include "dnsresolv.h" #include "taia.h" #include "uint_t.h" -#include "dnsresolv.h" /** @file dns_random.c @@ -15,13 +16,17 @@ static uint32 in[12]; static uint32 out[8]; static int outleft = 0; -#define ROTATE(x,b) (((x) << (b)) | ((x) >> (32 - (b)))) -#define MUSH(i,b) x = t[i] += (((x ^ seed[i]) + sum) ^ ROTATE(x,b)); +#define ROTATE(x, b) (((x) << (b)) | ((x) >> (32 - (b)))) +#define MUSH(i, b) x = t[i] += (((x ^ seed[i]) + sum) ^ ROTATE(x, b)) static void surf(void) { - uint32 t[12]; uint32 x; uint32 sum = 0; - int r; int i; int loop; + uint32 t[12]; + uint32 x; + uint32 sum = 0; + int r; + int i; + int loop; for (i = 0; i < 12; ++i) t[i] = in[i] ^ seed[12 + i]; for (i = 0; i < 8; ++i) out[i] = seed[24 + i]; @@ -29,9 +34,21 @@ static void surf(void) for (loop = 0; loop < 2; ++loop) { for (r = 0; r < 16; ++r) { sum += 0x9e3779b9; - MUSH(0,5) MUSH(1,7) MUSH(2,9) MUSH(3,13) - MUSH(4,5) MUSH(5,7) MUSH(6,9) MUSH(7,13) - MUSH(8,5) MUSH(9,7) MUSH(10,9) MUSH(11,13) + + MUSH(0, 5); + MUSH(1, 7); + MUSH(2, 9); + MUSH(3, 13); + + MUSH(4, 5); + MUSH(5, 7); + MUSH(6, 9); + MUSH(7, 13); + + MUSH(8, 5); + MUSH(9, 7); + MUSH(10, 9); + MUSH(11, 13); } for (i = 0; i < 8; ++i) out[i] ^= t[i + 4]; } @@ -43,13 +60,11 @@ void dns_random_init(const char data[128]) struct taia t; char tpack[16]; - for (i = 0; i < 32; ++i) - uint32_unpack((char *)data + 4 * i,seed + i); + for (i = 0; i < 32; ++i) uint32_unpack((char *)data + 4 * i, seed + i); taia_now(&t); - taia_pack(tpack,&t); - for (i = 0; i < 4; ++i) - uint32_unpack(tpack + 4 * i,in + 4 + i); + taia_pack(tpack, &t); + for (i = 0; i < 4; ++i) uint32_unpack(tpack + 4 * i, in + 4 + i); in[8] = getpid(); in[9] = getppid(); @@ -61,7 +76,9 @@ unsigned int dns_random(unsigned int n) if (!n) return 0; if (!outleft) { - if (!++in[0]) if (!++in[1]) if (!++in[2]) ++in[3]; + if (!++in[0]) + if (!++in[1]) + if (!++in[2]) ++in[3]; surf(); outleft = 8; } |