Poly1305.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #ifndef ZT_POLY1305_HPP
  27. #define ZT_POLY1305_HPP
  28. namespace ZeroTier {
  29. #define ZT_POLY1305_KEY_LEN 32
  30. #define ZT_POLY1305_MAC_LEN 16
  31. /**
  32. * Poly1305 one-time authentication code
  33. *
  34. * This takes a one-time-use 32-byte key and generates a 16-byte message
  35. * authentication code. The key must never be re-used for a different
  36. * message.
  37. *
  38. * In Packet this is done by using the first 32 bytes of the stream cipher
  39. * keystream as a one-time-use key. These 32 bytes are then discarded and
  40. * the packet is encrypted with the next N bytes.
  41. */
  42. class Poly1305
  43. {
  44. public:
  45. /**
  46. * Compute a one-time authentication code
  47. *
  48. * @param auth Buffer to receive code -- MUST be 16 bytes in length
  49. * @param data Data to authenticate
  50. * @param len Length of data to authenticate in bytes
  51. * @param key 32-byte one-time use key to authenticate data (must not be reused)
  52. */
  53. static void compute(void *auth,const void *data,unsigned int len,const void *key);
  54. };
  55. } // namespace ZeroTier
  56. #endif