You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

67 lines
1.5 KiB

  1. /* Copyright (c) 2011 Stanford University.
  2. * Copyright (c) 2014 Cryptography Research, Inc.
  3. * Released under the MIT License. See LICENSE.txt for license information.
  4. */
  5. /* A miniature version of the (as of yet incomplete) crandom project. */
  6. #ifndef __GOLDI_CRANDOM_H__
  7. #define __GOLDI_CRANDOM_H__ 1
  8. #include <stdint.h> /* for uint64_t */
  9. #include <fcntl.h> /* for open */
  10. #include <errno.h> /* for returning errors after open */
  11. #include <stdlib.h> /* for abort */
  12. #include <string.h> /* for memcpy */
  13. #include <strings.h> /* for bzero */
  14. #include <unistd.h> /* for read */
  15. struct crandom_state_t {
  16. unsigned char seed[32];
  17. unsigned char buffer[96];
  18. uint64_t ctr;
  19. uint64_t magic;
  20. unsigned int fill;
  21. int reseed_countdown;
  22. int reseed_interval;
  23. int reseeds_mandatory;
  24. int randomfd;
  25. } __attribute__((aligned(16))) ;
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. int
  30. crandom_init_from_file(
  31. struct crandom_state_t *state,
  32. const char *filename,
  33. int reseed_interval,
  34. int reseeds_mandatory
  35. ) __attribute__((warn_unused_result));
  36. void
  37. crandom_init_from_buffer(
  38. struct crandom_state_t *state,
  39. const char initial_seed[32]
  40. );
  41. /* TODO : attribute warn for not checking return type? */
  42. int
  43. crandom_generate(
  44. struct crandom_state_t *state,
  45. unsigned char *output,
  46. unsigned long long length
  47. );
  48. void
  49. crandom_destroy(
  50. struct crandom_state_t *state
  51. );
  52. #ifdef __cplusplus
  53. }; /* extern "C" */
  54. #endif
  55. #endif /* __GOLDI_CRANDOM_H__ */