CryptGenRandom.c 487 B

12345678910111213141516171819202122
  1. #include <windows.h>
  2. #include <wincrypt.h>
  3. #include <process.h>
  4. #include <assert.h>
  5. void randombytes(unsigned char *x,unsigned long long xlen)
  6. {
  7. static int provider_set = 0;
  8. static HCRYPTPROV provider;
  9. if (!provider_set) {
  10. if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
  11. if (GetLastError() != (DWORD)NTE_BAD_KEYSET) {
  12. assert(0);
  13. }
  14. }
  15. provider_set = 1;
  16. }
  17. if (!CryptGenRandom(provider, xlen, x)) {
  18. assert(0);
  19. }
  20. }