hydrogen_p.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. static int hydro_random_init(void);
  2. /* ---------------- */
  3. #define gimli_BLOCKBYTES 48
  4. #define gimli_CAPACITY 32
  5. #define gimli_RATE 16
  6. #define gimli_TAG_HEADER 0x01
  7. #define gimli_TAG_PAYLOAD 0x02
  8. #define gimli_TAG_FINAL 0x08
  9. #define gimli_TAG_FINAL0 0xf8
  10. #define gimli_TAG_KEY0 0xfe
  11. #define gimli_TAG_KEY 0xff
  12. #define gimli_DOMAIN_AEAD 0x0
  13. #define gimli_DOMAIN_XOF 0xf
  14. static void gimli_core_u8(uint8_t state_u8[gimli_BLOCKBYTES], uint8_t tag);
  15. static inline void
  16. gimli_pad_u8(uint8_t buf[gimli_BLOCKBYTES], size_t pos, uint8_t domain)
  17. {
  18. buf[pos] ^= (domain << 1) | 1;
  19. buf[gimli_RATE - 1] ^= 0x80;
  20. }
  21. static inline void
  22. hydro_mem_ct_zero_u32(uint32_t *dst_, size_t n)
  23. {
  24. volatile uint32_t *volatile dst = (volatile uint32_t * volatile)(void *) dst_;
  25. size_t i;
  26. for (i = 0; i < n; i++) {
  27. dst[i] = 0;
  28. }
  29. }
  30. static inline uint32_t hydro_mem_ct_cmp_u32(const uint32_t *b1_, const uint32_t *b2,
  31. size_t n) _hydro_attr_warn_unused_result_;
  32. static inline uint32_t
  33. hydro_mem_ct_cmp_u32(const uint32_t *b1_, const uint32_t *b2, size_t n)
  34. {
  35. const volatile uint32_t *volatile b1 = (const volatile uint32_t *volatile)(const void *) b1_;
  36. size_t i;
  37. uint32_t cv = 0;
  38. for (i = 0; i < n; i++) {
  39. cv |= b1[i] ^ b2[i];
  40. }
  41. return cv;
  42. }
  43. /* ---------------- */
  44. static int hydro_hash_init_with_tweak(hydro_hash_state *state,
  45. const char ctx[hydro_hash_CONTEXTBYTES], uint64_t tweak,
  46. const uint8_t key[hydro_hash_KEYBYTES]);
  47. /* ---------------- */
  48. #define hydro_secretbox_NONCEBYTES 20
  49. #define hydro_secretbox_MACBYTES 16
  50. /* ---------------- */
  51. #define hydro_x25519_BYTES 32
  52. #define hydro_x25519_PUBLICKEYBYTES 32
  53. #define hydro_x25519_SECRETKEYBYTES 32
  54. static int hydro_x25519_scalarmult(uint8_t out[hydro_x25519_BYTES],
  55. const uint8_t scalar[hydro_x25519_BYTES],
  56. const uint8_t x1[hydro_x25519_BYTES],
  57. bool clamp) _hydro_attr_warn_unused_result_;
  58. static inline int hydro_x25519_scalarmult_base(uint8_t pk[hydro_x25519_PUBLICKEYBYTES],
  59. const uint8_t sk[hydro_x25519_SECRETKEYBYTES])
  60. _hydro_attr_warn_unused_result_;
  61. static inline void
  62. hydro_x25519_scalarmult_base_uniform(uint8_t pk[hydro_x25519_PUBLICKEYBYTES],
  63. const uint8_t sk[hydro_x25519_SECRETKEYBYTES]);