Poly1305.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c)2019 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: 2026-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_LEN 32
  17. #define ZT_POLY1305_MAC_LEN 16
  18. /**
  19. * Poly1305 one-time authentication code
  20. *
  21. * This takes a one-time-use 32-byte key and generates a 16-byte message
  22. * authentication code. The key must never be re-used for a different
  23. * message.
  24. *
  25. * In Packet this is done by using the first 32 bytes of the stream cipher
  26. * keystream as a one-time-use key. These 32 bytes are then discarded and
  27. * the packet is encrypted with the next N bytes.
  28. */
  29. class Poly1305 {
  30. public:
  31. /**
  32. * Compute a one-time authentication code
  33. *
  34. * @param auth Buffer to receive code -- MUST be 16 bytes in length
  35. * @param data Data to authenticate
  36. * @param len Length of data to authenticate in bytes
  37. * @param key 32-byte one-time use key to authenticate data (must not be reused)
  38. */
  39. static void compute(void* auth, const void* data, unsigned int len, const void* key);
  40. };
  41. } // namespace ZeroTier
  42. #endif