chacha20.h 933 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Based on
  3. * 1. OpenSSL lib
  4. * 2. PurpleI2P source code
  5. * 3. cppcodec lib
  6. *
  7. * PUBLIC DOMAIN C++ WRAPPER
  8. * acetone, 2022
  9. */
  10. #ifndef CHACHA20_H
  11. #define CHACHA20_H
  12. #include <vector>
  13. #include <array>
  14. using uint8_t = unsigned char;
  15. namespace FriendlyCrypto {
  16. #if defined(__FreeBSD__) || defined(__NetBSD__)
  17. #include <sys/endian.h>
  18. #elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__GLIBC__)
  19. #include <endian.h>
  20. #elif defined(__APPLE__) && defined(__MACH__)
  21. #include <libkern/OSByteOrder.h>
  22. #define htole32(x) OSSwapHostToLittleInt32(x)
  23. #else
  24. #define htole32
  25. #endif
  26. std::vector<uint8_t> chaCha20 (const std::vector<uint8_t>& msg, const std::array<uint8_t, 32>& key, const uint8_t * nonce = nullptr) noexcept;
  27. std::vector<uint8_t> chaCha20 (const uint8_t* msg, size_t msgSize, const std::array<uint8_t, 32>& key, const uint8_t * nonce = nullptr) noexcept;
  28. }
  29. #endif // CHACHA20_H