+#ifdef WIN32
+ {
+ HCRYPTPROV hCryptProv;
+ if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
+ {
+ if(!CryptGenRandom(hCryptProv, sizeof(buf), (PBYTE) &buf[0]))
+ {
+ fprintf(stderr, "WARNING: could not initialize random number generator (CryptGenRandom failed)\n");
+ ret = 0;
+ }
+ CryptReleaseContext(hCryptProv, 0);
+ }
+ else if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET))
+ {
+ if(!CryptGenRandom(hCryptProv, sizeof(buf), (PBYTE) &buf[0]))
+ {
+ fprintf(stderr, "WARNING: could not initialize random number generator (CryptGenRandom failed)\n");
+ ret = 0;
+ }
+ CryptReleaseContext(hCryptProv, 0);
+ }
+ else
+ {
+ fprintf(stderr, "WARNING: could not initialize random number generator (CryptAcquireContext failed)\n");
+ ret = 0;
+ }
+ }
+#else
+ f = fopen("/dev/urandom", "rb");
+ if(!f)
+ f = fopen("/dev/random", "rb");
+ if(f)
+ {
+ setbuf(f, NULL);
+ if(fread(buf, sizeof(buf), 1, f) != 1)
+ {
+ fprintf(stderr, "WARNING: could not initialize random number generator (read from random device failed)\n");
+ ret = 0;
+ }
+ fclose(f);
+ }
+ else
+ {
+ fprintf(stderr, "WARNING: could not initialize random number generator (no random device found)\n");
+ ret = 0;
+ }
+#endif
+ RAND_add(buf, sizeof(buf), sizeof(buf));
+