Poly1305.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: 2024-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. ZT_INLINE Poly1305(const void *key) { this->init(key); }
  26. void init(const void *key) noexcept;
  27. void update(const void *data,unsigned int len) noexcept;
  28. void finish(void *auth) noexcept;
  29. static ZT_INLINE void compute(void *const auth, const void *const data, const unsigned int len, const void *const key) noexcept
  30. {
  31. Poly1305 p(key);
  32. p.update(data,len);
  33. p.finish(auth);
  34. }
  35. private:
  36. struct {
  37. size_t aligner;
  38. unsigned char opaque[136];
  39. } ctx;
  40. };
  41. } // namespace ZeroTier
  42. #endif