opendir change: refinement
[minix.git] / servers / inet / generic / rand256.c
blobf75777532272c503edb55265b44c633e8c9f07c8
1 /*
2 rand256.c
4 Created: Oct 2000 by Philip Homburg <philip@f-mnx.phicoh.com>
6 Generate 256-bit random numbers
7 */
9 #ifdef __NBSD_LIBC
10 #include <sys/sha2.h>
11 #else
12 #include <minix/sha2.h>
13 #endif
14 #include "inet.h"
15 #include "rand256.h"
17 static u32_t base_bits[8];
19 void init_rand256(bits)
20 u8_t bits[32];
22 memcpy(base_bits, bits, sizeof(base_bits));
25 void rand256(bits)
26 u8_t bits[32];
28 u32_t a;
29 SHA256_CTX ctx;
31 a= ++base_bits[0];
32 if (a == 0)
33 base_bits[1]++;
34 SHA256_Init(&ctx);
35 SHA256_Update(&ctx, (unsigned char *)base_bits, sizeof(base_bits));
36 SHA256_Final(bits, &ctx);
40 * $PchId: rand256.c,v 1.1 2005/06/28 14:13:43 philip Exp $