Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated the Windows code example to show how to acquire the crypto context; fixed a compile error

...

Code Block
bgColor#ccccff
langc
#include<Wincrypt#include <Windows.h>
#include <wincrypt.h>
#include <stdio.h>
 
HCRYPTPROV hCryptProv;
prov;
if (CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, 0)) {
  long int li = 0;

  if (!CryptGenRandom(hCryptProvprov, sizeof(&li), (BYTE *)&li)) {
    /* Handle error */
} else {
    printf("Random number: %ld\n", li);
  CryptReleaseContext(prov, 0);
}

Risk Assessment

Using the rand() function leads to possibly predictable random numbers.

...