#include "utils.h"
-#include "monocypher.h"
#include "stdio.h"
static void store64_le(u8 out[8], u64 in)
| ((u64)s[7] << 56);
}
-// Deterministic "random" number generator, so we can make "random", yet
-// reproducible tests. To change the random stream, change the seed.
-void p_random(u8 *stream, size_t size)
+
+// Pseudo-random 64 bit number, based on xorshift*
+u64 rand64()
{
- static crypto_chacha_ctx ctx;
- static int is_init = 0;
- if (!is_init) {
- static const u8 seed[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- crypto_chacha20_init(&ctx, seed, seed);
- is_init = 1;
- }
- crypto_chacha20_stream(&ctx, stream, size);
+ static u64 x = 12345; // Must be seeded with a nonzero value.
+ x ^= x >> 12;
+ x ^= x << 25;
+ x ^= x >> 27;
+ return x * 0x2545F4914F6CDD1D; // magic constant
}
-// Random 64 bit number
-u64 rand64()
+void p_random(u8 *stream, size_t size)
{
- u8 tmp;
- u64 result = 0;
- FOR (i, 0, 8) {
- p_random(&tmp, 1);
- result <<= 8;
- result += tmp;
+ FOR (i, 0, size) {
+ stream[i] = (u8)rand64();
}
- return result;
}
void print_vector(u8 *buf, size_t size)