Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ottery_entropy_cryptgenrandom.c 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Libottery by Nick Mathewson.
  2. This software has been dedicated to the public domain under the CC0
  3. public domain dedication.
  4. To the extent possible under law, the person who associated CC0 with
  5. libottery has waived all copyright and related or neighboring rights
  6. to libottery.
  7. You should have received a copy of the CC0 legalcode along with this
  8. work in doc/cc0.txt. If not, see
  9. <http://creativecommons.org/publicdomain/zero/1.0/>.
  10. */
  11. #define OTTERY_INTERNAL
  12. #include "ottery-internal.h"
  13. #include "ottery.h"
  14. #ifdef _WIN32
  15. /** Generate random bytes using the Windows CryptGenRandom operating-system
  16. * RNG. */
  17. static int
  18. ottery_get_entropy_cryptgenrandom(const struct ottery_entropy_config *cfg,
  19. struct ottery_entropy_state *state,
  20. uint8_t *out, size_t outlen)
  21. {
  22. /* On Windows, CryptGenRandom is supposed to be a well-seeded
  23. * cryptographically strong random number generator. */
  24. HCRYPTPROV provider;
  25. int retval = 0;
  26. (void) cfg;
  27. (void) state;
  28. if (0 == CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
  29. CRYPT_VERIFYCONTEXT))
  30. return OTTERY_ERR_INIT_STRONG_RNG;
  31. if (0 == CryptGenRandom(provider, outlen, out))
  32. retval = OTTERY_ERR_ACCESS_STRONG_RNG;
  33. CryptReleaseContext(provider, 0);
  34. return retval;
  35. }
  36. #define ENTROPY_SOURCE_CRYPTGENRANDOM \
  37. { ottery_get_entropy_cryptgenrandom, \
  38. SRC(CRYPTGENRANDOM)|DOM(OS)|FL(STRONG) }
  39. #endif