sl_sha2.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* sl_sha2.h :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2018/09/26 20:13:19 by bchanot #+# #+# */
  9. /* Updated: 2018/10/10 12:55:47 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #ifndef SL_SHA2_H
  13. # define SL_SHA2_H
  14. # define EP0_SHA2(x) (ROR32(x, 2) ^ ROR32(x, 13) ^ ROR32(x, 22))
  15. # define EP1_SHA2(x) (ROR32(x, 6) ^ ROR32(x, 11) ^ ROR32(x, 25))
  16. # define SIG0_SHA2(x) (ROR32(x, 7) ^ ROR32(x, 18) ^ ((x) >> 3))
  17. # define SIG1_SHA2(x) (ROR32(x, 17) ^ ROR32(x, 19) ^ ((x) >> 10))
  18. # define SHA224 0
  19. # define SHA256 1
  20. typedef struct s_sha2
  21. {
  22. t_uint8 buff[64];
  23. t_uint32 state[8];
  24. t_uint32 count[2];
  25. } t_sha2;
  26. typedef struct s_process_sha2
  27. {
  28. t_uint32 a;
  29. t_uint32 b;
  30. t_uint32 c;
  31. t_uint32 d;
  32. t_uint32 e;
  33. t_uint32 f;
  34. t_uint32 g;
  35. t_uint32 h;
  36. } t_process_sha2;
  37. void sl_sha2_get_registers(t_uint32 *m, t_process_sha2 *t, \
  38. size_t i);
  39. void sl_sha2_process_init_add(t_sha2 *ctx, t_process_sha2 *t, \
  40. t_bool init);
  41. void sl_sha2_init(t_sha2 *ctx, t_uint8 sha);
  42. void sl_sha2_update(t_sha2 *ctx, const t_uint8 *data, size_t len);
  43. void sl_sha2_final(t_sha2 *ctx);
  44. void sl_sha2_get_hash(t_sha2 *ctx, t_uint8 *hash);
  45. #endif