keccak-tiny.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef KECCAK_FIPS202_H
  2. #define KECCAK_FIPS202_H
  3. #include <stddef.h>
  4. #include "lib/cc/torint.h"
  5. #define KECCAK_MAX_RATE 200
  6. /* Calculate the rate (block size) from the security target. */
  7. #define KECCAK_RATE(bits) (KECCAK_MAX_RATE - (bits / 4))
  8. /* The internal structure of a FIPS202 hash/xof instance. Most callers
  9. * should treat this as an opaque structure.
  10. */
  11. typedef struct keccak_state {
  12. uint8_t a[KECCAK_MAX_RATE];
  13. size_t rate;
  14. uint8_t delim;
  15. uint8_t block[KECCAK_MAX_RATE];
  16. size_t offset;
  17. uint8_t finalized : 1;
  18. } keccak_state;
  19. /* Initialize a Keccak instance suitable for SHA-3 hash functions. */
  20. int keccak_digest_init(keccak_state *s, size_t bits);
  21. /* Feed more data into the SHA-3 hash instance. */
  22. int keccak_digest_update(keccak_state *s, const uint8_t *buf, size_t len);
  23. /* Calculate the SHA-3 hash digest. The state is unmodified to support
  24. * calculating multiple/rolling digests.
  25. */
  26. int keccak_digest_sum(const keccak_state *s, uint8_t *out, size_t outlen);
  27. /* Initialize a Keccak instance suitable for XOFs (SHAKE-128/256). */
  28. int keccak_xof_init(keccak_state *s, size_t bits);
  29. /* Absorb more data into the XOF. Must not be called after a squeeze call. */
  30. int keccak_xof_absorb(keccak_state *s, const uint8_t *buf, size_t len);
  31. /* Squeeze data out of the XOF. Must not attempt to absorb additional data,
  32. * after a squeeze has been called.
  33. */
  34. int keccak_xof_squeeze(keccak_state *s, uint8_t *out, size_t outlen);
  35. /* Clone an existing hash/XOF instance. */
  36. void keccak_clone(keccak_state *out, const keccak_state *in);
  37. /* Cleanse sensitive data from a given hash instance. */
  38. void keccak_cleanse(keccak_state *s);
  39. #define decshake(bits) \
  40. int shake##bits(uint8_t*, size_t, const uint8_t*, size_t);
  41. #define decsha3(bits) \
  42. int sha3_##bits(uint8_t*, size_t, const uint8_t*, size_t);
  43. decshake(128)
  44. decshake(256)
  45. decsha3(224)
  46. decsha3(256)
  47. decsha3(384)
  48. decsha3(512)
  49. #endif