/*\ * RRAND RNG - Ruptor's Fast True Random Number Generator, v2.0 based on RUPT64x2-512/2 * http://cryptolib.com/crypto/rrand * Copyright (c) 1992-2010 Marcos el Ruptor * Released to public domain. \*/ #ifndef _RRAND_H #define _RRAND_H #ifdef __cplusplus extern "C" { #endif #ifndef _STD_TYPES #define _STD_TYPES #define uchar unsigned char #define uint unsigned int #define ulong unsigned long int #if (defined(_MSC_VER) && defined(_M_IX86))||defined(INTEL_COMPILER)||defined(__WATCOMC__) #define ulonglong unsigned __int64 #else #define ulonglong unsigned long long #endif #endif #define RRAND_SIZE 64 /* 16 is actually more than enough for 512-bit security, but we are paranoid */ /* although the ability to support separate states is provided, it is advised to use the same state for all PRNG instances, threads, and if possible, processes */ typedef struct _rrand_state { ulonglong pool[RRAND_SIZE], d0, d1, r; /* RUPT state */ uint offset; /* r % RRAND_SIZE */ } rrand_state; /** * \brief [incremental] RRAND state initialization, slow refill with a large amount of entropy, not absolutely necessary to call, advised to call before generating large secret keys and every few ms in a separate thread * * \param rr RRAND state to be reseeded */ void rrand_init (rrand_state * const rr); /** * \brief RRAND 64-bit random number generation function, fast, ~12 CPB on x64, ~45 CPB on x86 C2D * * \param vr RRAND state * * \return A random unsigned long long */ ulonglong rrand (void * const vr); #ifdef __cplusplus } #endif #endif /* rrand.h */