prng.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * prng.h
  3. *
  4. * pseudorandom source
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. #ifndef PRNG_H
  10. #define PRNG_H
  11. #include "rand_source.h" /* for rand_source_func_t definition */
  12. #include "aes.h" /* for aes */
  13. //FIXME: this is temporary until we pull in the code to use OpenSSL for RNG
  14. #ifdef OPENSSL
  15. #include "aes_icm_ossl.h" /* for aes ctr */
  16. #else
  17. #include "aes_icm.h" /* for aes ctr */
  18. #endif
  19. #define MAX_PRNG_OUT_LEN 0xffffffffU
  20. /*
  21. * x917_prng is an ANSI X9.17-like AES-based PRNG
  22. */
  23. typedef struct {
  24. v128_t state; /* state data */
  25. aes_expanded_key_t key; /* secret key */
  26. uint32_t octet_count; /* number of octets output since last init */
  27. rand_source_func_t rand; /* random source for re-initialization */
  28. } x917_prng_t;
  29. err_status_t
  30. x917_prng_init(rand_source_func_t random_source);
  31. err_status_t
  32. x917_prng_get_octet_string(uint8_t *dest, uint32_t len);
  33. /*
  34. * ctr_prng is an AES-CTR based PRNG
  35. */
  36. typedef struct {
  37. uint32_t octet_count; /* number of octets output since last init */
  38. aes_icm_ctx_t state; /* state data */
  39. rand_source_func_t rand; /* random source for re-initialization */
  40. } ctr_prng_t;
  41. err_status_t
  42. ctr_prng_init(rand_source_func_t random_source);
  43. err_status_t
  44. ctr_prng_get_octet_string(void *dest, uint32_t len);
  45. #endif