1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/crypto/libntrup/src/ref/random32.c
2019-02-18 05:12:13 -08:00

28 lines
552 B
C

#include <sodium/randombytes.h>
#include "small.h"
#ifdef KAT
/* NIST KAT generator fails to provide chunk-independence */
static unsigned char x[4 * 761];
static long long pos = 4 * 761;
#endif
crypto_int32
small_random32(void)
{
#ifdef KAT
if(pos == 4 * 761)
{
randombytes(x, sizeof x);
pos = 0;
}
pos += 4;
return x[pos - 4] + (x[pos - 3] << 8) + (x[pos - 2] << 16)
+ (x[pos - 1] << 24);
#else
unsigned char x[4];
randombytes(x, 4);
uint32_t x4 = x[3] << 24;
return x[0] + (x[1] << 8) + (x[2] << 16) + x4;
#endif
}