crypto_secretbox_xsalsa20poly1305.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef crypto_secretbox_xsalsa20poly1305_H
  2. #define crypto_secretbox_xsalsa20poly1305_H
  3. #include <stddef.h>
  4. #include "crypto_stream_xsalsa20.h"
  5. #include "export.h"
  6. #ifdef __cplusplus
  7. # ifdef __GNUC__
  8. # pragma GCC diagnostic ignored "-Wlong-long"
  9. # endif
  10. extern "C" {
  11. #endif
  12. #define crypto_secretbox_xsalsa20poly1305_KEYBYTES 32U
  13. SODIUM_EXPORT
  14. size_t crypto_secretbox_xsalsa20poly1305_keybytes(void);
  15. #define crypto_secretbox_xsalsa20poly1305_NONCEBYTES 24U
  16. SODIUM_EXPORT
  17. size_t crypto_secretbox_xsalsa20poly1305_noncebytes(void);
  18. #define crypto_secretbox_xsalsa20poly1305_MACBYTES 16U
  19. SODIUM_EXPORT
  20. size_t crypto_secretbox_xsalsa20poly1305_macbytes(void);
  21. /* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */
  22. #define crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX \
  23. (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_secretbox_xsalsa20poly1305_MACBYTES)
  24. SODIUM_EXPORT
  25. size_t crypto_secretbox_xsalsa20poly1305_messagebytes_max(void);
  26. SODIUM_EXPORT
  27. int crypto_secretbox_xsalsa20poly1305(unsigned char *c,
  28. const unsigned char *m,
  29. unsigned long long mlen,
  30. const unsigned char *n,
  31. const unsigned char *k)
  32. __attribute__ ((nonnull(1, 4, 5)));
  33. SODIUM_EXPORT
  34. int crypto_secretbox_xsalsa20poly1305_open(unsigned char *m,
  35. const unsigned char *c,
  36. unsigned long long clen,
  37. const unsigned char *n,
  38. const unsigned char *k)
  39. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
  40. SODIUM_EXPORT
  41. void crypto_secretbox_xsalsa20poly1305_keygen(unsigned char k[crypto_secretbox_xsalsa20poly1305_KEYBYTES])
  42. __attribute__ ((nonnull));
  43. /* -- NaCl compatibility interface ; Requires padding -- */
  44. #define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES 16U
  45. SODIUM_EXPORT
  46. size_t crypto_secretbox_xsalsa20poly1305_boxzerobytes(void);
  47. #define crypto_secretbox_xsalsa20poly1305_ZEROBYTES \
  48. (crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES + \
  49. crypto_secretbox_xsalsa20poly1305_MACBYTES)
  50. SODIUM_EXPORT
  51. size_t crypto_secretbox_xsalsa20poly1305_zerobytes(void);
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif