poly1305.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Common values for the Poly1305 algorithm
  4. */
  5. #ifndef _CRYPTO_INTERNAL_POLY1305_H
  6. #define _CRYPTO_INTERNAL_POLY1305_H
  7. #include <crypto/poly1305.h>
  8. #include <linux/types.h>
  9. /*
  10. * Poly1305 core functions. These only accept whole blocks; the caller must
  11. * handle any needed block buffering and padding. 'hibit' must be 1 for any
  12. * full blocks, or 0 for the final block if it had to be padded. If 'nonce' is
  13. * non-NULL, then it's added at the end to compute the Poly1305 MAC. Otherwise,
  14. * only the ε-almost-∆-universal hash function (not the full MAC) is computed.
  15. */
  16. void poly1305_core_setkey(struct poly1305_core_key *key,
  17. const u8 raw_key[POLY1305_BLOCK_SIZE]);
  18. static inline void poly1305_core_init(struct poly1305_state *state)
  19. {
  20. *state = (struct poly1305_state){};
  21. }
  22. void poly1305_core_blocks(struct poly1305_state *state,
  23. const struct poly1305_core_key *key, const void *src,
  24. unsigned int nblocks, u32 hibit);
  25. void poly1305_core_emit(const struct poly1305_state *state, const u32 nonce[4],
  26. void *dst);
  27. static inline void
  28. poly1305_block_init_generic(struct poly1305_block_state *desc,
  29. const u8 raw_key[POLY1305_BLOCK_SIZE])
  30. {
  31. poly1305_core_init(&desc->h);
  32. poly1305_core_setkey(&desc->core_r, raw_key);
  33. }
  34. static inline void poly1305_blocks_generic(struct poly1305_block_state *state,
  35. const u8 *src, unsigned int len,
  36. u32 padbit)
  37. {
  38. poly1305_core_blocks(&state->h, &state->core_r, src,
  39. len / POLY1305_BLOCK_SIZE, padbit);
  40. }
  41. static inline void poly1305_emit_generic(const struct poly1305_state *state,
  42. u8 digest[POLY1305_DIGEST_SIZE],
  43. const u32 nonce[4])
  44. {
  45. poly1305_core_emit(state, nonce, digest);
  46. }
  47. #endif