Rev | Line | |
---|
[9] | 1 | /*
|
---|
| 2 | rand256.c
|
---|
| 3 |
|
---|
| 4 | Created: Oct 2000 by Philip Homburg <philip@f-mnx.phicoh.com>
|
---|
| 5 |
|
---|
| 6 | Generate 256-bit random numbers
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #include <sha2.h>
|
---|
| 10 | #include "inet.h"
|
---|
| 11 | #include "rand256.h"
|
---|
| 12 |
|
---|
| 13 | PRIVATE u32_t base_bits[8];
|
---|
| 14 |
|
---|
| 15 | PUBLIC void init_rand256(bits)
|
---|
| 16 | u8_t bits[32];
|
---|
| 17 | {
|
---|
| 18 | memcpy(base_bits, bits, sizeof(base_bits));
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | PUBLIC void rand256(bits)
|
---|
| 22 | u8_t bits[32];
|
---|
| 23 | {
|
---|
| 24 | u32_t a;
|
---|
| 25 | SHA256_CTX ctx;
|
---|
| 26 |
|
---|
| 27 | a= ++base_bits[0];
|
---|
| 28 | if (a == 0)
|
---|
| 29 | base_bits[1]++;
|
---|
| 30 | SHA256_Init(&ctx);
|
---|
| 31 | SHA256_Update(&ctx, (unsigned char *)base_bits, sizeof(base_bits));
|
---|
| 32 | SHA256_Final(bits, &ctx);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | /*
|
---|
| 36 | * $PchId: rand256.c,v 1.1 2005/06/28 14:13:43 philip Exp $
|
---|
| 37 | */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.