sha3.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* sha3.h */
  2. #ifndef RHASH_SHA3_H
  3. #define RHASH_SHA3_H
  4. #include "ustd.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #define sha3_224_hash_size 28
  9. #define sha3_256_hash_size 32
  10. #define sha3_384_hash_size 48
  11. #define sha3_512_hash_size 64
  12. #define sha3_max_permutation_size 25
  13. #define sha3_max_rate_in_qwords 24
  14. /**
  15. * SHA3 Algorithm context.
  16. */
  17. typedef struct sha3_ctx
  18. {
  19. /* 1600 bits algorithm hashing state */
  20. uint64_t hash[sha3_max_permutation_size];
  21. /* 1536-bit buffer for leftovers */
  22. uint64_t message[sha3_max_rate_in_qwords];
  23. /* count of bytes in the message[] buffer */
  24. unsigned rest;
  25. /* size of a message block processed at once */
  26. unsigned block_size;
  27. } sha3_ctx;
  28. /* methods for calculating the hash function */
  29. void rhash_sha3_224_init(sha3_ctx *ctx);
  30. void rhash_sha3_256_init(sha3_ctx *ctx);
  31. void rhash_sha3_384_init(sha3_ctx *ctx);
  32. void rhash_sha3_512_init(sha3_ctx *ctx);
  33. void rhash_sha3_update(sha3_ctx *ctx, const unsigned char* msg, size_t size);
  34. void rhash_sha3_final(sha3_ctx *ctx, unsigned char* result);
  35. #ifdef USE_KECCAK
  36. #define rhash_keccak_224_init rhash_sha3_224_init
  37. #define rhash_keccak_256_init rhash_sha3_256_init
  38. #define rhash_keccak_384_init rhash_sha3_384_init
  39. #define rhash_keccak_512_init rhash_sha3_512_init
  40. #define rhash_keccak_update rhash_sha3_update
  41. void rhash_keccak_final(sha3_ctx *ctx, unsigned char* result);
  42. #endif
  43. #ifdef __cplusplus
  44. } /* extern "C" */
  45. #endif /* __cplusplus */
  46. #endif /* RHASH_SHA3_H */