Poly1305.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_POLY1305_HPP
  14. #define ZT_POLY1305_HPP
  15. namespace ZeroTier {
  16. #define ZT_POLY1305_KEY_SIZE 32
  17. #define ZT_POLY1305_MAC_SIZE 16
  18. /**
  19. * Poly1305 one-time MAC calculator
  20. */
  21. class Poly1305
  22. {
  23. public:
  24. ZT_INLINE Poly1305()
  25. {}
  26. ZT_INLINE Poly1305(const void *key)
  27. { this->init(key); }
  28. void init(const void *key) noexcept;
  29. void update(const void *data, unsigned int len) noexcept;
  30. void finish(void *auth) noexcept;
  31. static ZT_INLINE void compute(void *const auth, const void *const data, const unsigned int len, const void *const key) noexcept
  32. {
  33. Poly1305 p(key);
  34. p.update(data, len);
  35. p.finish(auth);
  36. }
  37. private:
  38. struct
  39. {
  40. size_t aligner;
  41. unsigned char opaque[136];
  42. } ctx;
  43. };
  44. } // namespace ZeroTier
  45. #endif