2
0

Poly1305.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  4. *
  5. * (c) ZeroTier, Inc.
  6. * https://www.zerotier.com/
  7. */
  8. #ifndef ZT_POLY1305_HPP
  9. #define ZT_POLY1305_HPP
  10. namespace ZeroTier {
  11. #define ZT_POLY1305_KEY_LEN 32
  12. #define ZT_POLY1305_MAC_LEN 16
  13. /**
  14. * Poly1305 one-time authentication code
  15. *
  16. * This takes a one-time-use 32-byte key and generates a 16-byte message
  17. * authentication code. The key must never be re-used for a different
  18. * message.
  19. *
  20. * In Packet this is done by using the first 32 bytes of the stream cipher
  21. * keystream as a one-time-use key. These 32 bytes are then discarded and
  22. * the packet is encrypted with the next N bytes.
  23. */
  24. class Poly1305 {
  25. public:
  26. /**
  27. * Compute a one-time authentication code
  28. *
  29. * @param auth Buffer to receive code -- MUST be 16 bytes in length
  30. * @param data Data to authenticate
  31. * @param len Length of data to authenticate in bytes
  32. * @param key 32-byte one-time use key to authenticate data (must not be reused)
  33. */
  34. static void compute(void* auth, const void* data, unsigned int len, const void* key);
  35. };
  36. } // namespace ZeroTier
  37. #endif