24 #include "runtime.hpp"
42 RandomNumberGenerator::RandomNumberGenerator()
47 seed_.GenerateSeed(key,
sizeof(key));
48 cipher_.SetKey(key,
sizeof(key));
49 GenerateBlock(junk,
sizeof(junk));
54 void RandomNumberGenerator::GenerateBlock(byte* output, word32 sz)
56 memset(output, 0, sz);
57 cipher_.Process(output, output, sz);
61 byte RandomNumberGenerator::GenerateByte()
76 if(!CryptAcquireContext(&handle_, 0, 0, PROV_RSA_FULL,
78 error_.SetError(WINCRYPT_E);
84 CryptReleaseContext(handle_, 0);
88 void OS_Seed::GenerateSeed(byte* output, word32 sz)
90 if (!CryptGenRandom(handle_, sz, output))
91 error_.SetError(CRYPTGEN_E);
101 fd_ = open(
"/dev/urandom",O_RDONLY);
103 fd_ = open(
"/dev/random",O_RDONLY);
105 error_.SetError(OPEN_RAN_E);
117 void OS_Seed::GenerateSeed(byte* output, word32 sz)
120 int len = read(fd_, output, sz);
122 error_.SetError(READ_RAN_E);