mycrypt_prng.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* ---- PRNG Stuff ---- */
  2. struct yarrow_prng {
  3. int cipher, hash;
  4. unsigned char pool[MAXBLOCKSIZE];
  5. symmetric_CTR ctr;
  6. };
  7. struct rc4_prng {
  8. int x, y;
  9. unsigned char buf[256];
  10. };
  11. typedef union Prng_state {
  12. struct yarrow_prng yarrow;
  13. struct rc4_prng rc4;
  14. } prng_state;
  15. extern struct _prng_descriptor {
  16. char *name;
  17. int (*start)(prng_state *);
  18. int (*add_entropy)(const unsigned char *, unsigned long, prng_state *);
  19. int (*ready)(prng_state *);
  20. unsigned long (*read)(unsigned char *, unsigned long len, prng_state *);
  21. } prng_descriptor[];
  22. #ifdef YARROW
  23. int yarrow_start(prng_state *prng);
  24. int yarrow_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
  25. int yarrow_ready(prng_state *prng);
  26. unsigned long yarrow_read(unsigned char *buf, unsigned long len, prng_state *prng);
  27. extern const struct _prng_descriptor yarrow_desc;
  28. #endif
  29. #ifdef RC4
  30. int rc4_start(prng_state *prng);
  31. int rc4_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
  32. int rc4_ready(prng_state *prng);
  33. unsigned long rc4_read(unsigned char *buf, unsigned long len, prng_state *prng);
  34. extern const struct _prng_descriptor rc4_desc;
  35. #endif
  36. #ifdef SPRNG
  37. int sprng_start(prng_state *prng);
  38. int sprng_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
  39. int sprng_ready(prng_state *prng);
  40. unsigned long sprng_read(unsigned char *buf, unsigned long len, prng_state *prng);
  41. extern const struct _prng_descriptor sprng_desc;
  42. #endif
  43. int find_prng(const char *name);
  44. int register_prng(const struct _prng_descriptor *prng);
  45. int unregister_prng(const struct _prng_descriptor *prng);
  46. int prng_is_valid(int idx);
  47. /* Slow RNG you **might** be able to use to seed a PRNG with. Be careful as this
  48. * might not work on all platforms as planned
  49. */
  50. /* ch2-02-1 */
  51. unsigned long rng_get_bytes(unsigned char *buf,
  52. unsigned long len,
  53. void (*callback)(void));
  54. /* ch2-02-1 */
  55. int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));