poly1305.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Common values for the Poly1305 algorithm
  4. */
  5. #ifndef _CRYPTO_POLY1305_H
  6. #define _CRYPTO_POLY1305_H
  7. #include <linux/types.h>
  8. #define POLY1305_BLOCK_SIZE 16
  9. #define POLY1305_KEY_SIZE 32
  10. #define POLY1305_DIGEST_SIZE 16
  11. /* The poly1305_key and poly1305_state types are mostly opaque and
  12. * implementation-defined. Limbs might be in base 2^64 or base 2^26, or
  13. * different yet. The union type provided keeps these 64-bit aligned for the
  14. * case in which this is implemented using 64x64 multiplies.
  15. */
  16. struct poly1305_key {
  17. union {
  18. u32 r[5];
  19. u64 r64[3];
  20. };
  21. };
  22. struct poly1305_core_key {
  23. struct poly1305_key key;
  24. struct poly1305_key precomputed_s;
  25. };
  26. struct poly1305_state {
  27. union {
  28. u32 h[5];
  29. u64 h64[3];
  30. };
  31. };
  32. /* Combined state for block function. */
  33. struct poly1305_block_state {
  34. /* accumulator */
  35. struct poly1305_state h;
  36. /* key */
  37. union {
  38. struct poly1305_key opaque_r[CONFIG_CRYPTO_LIB_POLY1305_RSIZE];
  39. struct poly1305_core_key core_r;
  40. };
  41. };
  42. struct poly1305_desc_ctx {
  43. /* partial buffer */
  44. u8 buf[POLY1305_BLOCK_SIZE];
  45. /* bytes used in partial buffer */
  46. unsigned int buflen;
  47. /* finalize key */
  48. u32 s[4];
  49. struct poly1305_block_state state;
  50. };
  51. void poly1305_init(struct poly1305_desc_ctx *desc,
  52. const u8 key[at_least POLY1305_KEY_SIZE]);
  53. void poly1305_update(struct poly1305_desc_ctx *desc,
  54. const u8 *src, unsigned int nbytes);
  55. void poly1305_final(struct poly1305_desc_ctx *desc, u8 *digest);
  56. #endif