prng.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "aes_icm.h" /* for aes ctr */
  14. #define MAX_PRNG_OUT_LEN 0xffffffffU
  15. /*
  16. * x917_prng is an ANSI X9.17-like AES-based PRNG
  17. */
  18. typedef struct {
  19. v128_t state; /* state data */
  20. aes_expanded_key_t key; /* secret key */
  21. uint32_t octet_count; /* number of octets output since last init */
  22. rand_source_func_t rand; /* random source for re-initialization */
  23. } x917_prng_t;
  24. err_status_t
  25. x917_prng_init(rand_source_func_t random_source);
  26. err_status_t
  27. x917_prng_get_octet_string(uint8_t *dest, uint32_t len);
  28. /*
  29. * ctr_prng is an AES-CTR based PRNG
  30. */
  31. typedef struct {
  32. uint32_t octet_count; /* number of octets output since last init */
  33. aes_icm_ctx_t state; /* state data */
  34. rand_source_func_t rand; /* random source for re-initialization */
  35. } ctr_prng_t;
  36. err_status_t
  37. ctr_prng_init(rand_source_func_t random_source);
  38. err_status_t
  39. ctr_prng_get_octet_string(void *dest, uint32_t len);
  40. #endif