crypto_aead_chacha20poly1305.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef crypto_aead_chacha20poly1305_H
  2. #define crypto_aead_chacha20poly1305_H
  3. #include <stddef.h>
  4. #include "export.h"
  5. #ifdef __cplusplus
  6. # ifdef __GNUC__
  7. # pragma GCC diagnostic ignored "-Wlong-long"
  8. # endif
  9. extern "C" {
  10. #endif
  11. /* -- IETF ChaCha20-Poly1305 construction with a 96-bit nonce and a 32-bit internal counter -- */
  12. #define crypto_aead_chacha20poly1305_ietf_KEYBYTES 32U
  13. SODIUM_EXPORT
  14. size_t crypto_aead_chacha20poly1305_ietf_keybytes(void);
  15. #define crypto_aead_chacha20poly1305_ietf_NSECBYTES 0U
  16. SODIUM_EXPORT
  17. size_t crypto_aead_chacha20poly1305_ietf_nsecbytes(void);
  18. #define crypto_aead_chacha20poly1305_ietf_NPUBBYTES 12U
  19. SODIUM_EXPORT
  20. size_t crypto_aead_chacha20poly1305_ietf_npubbytes(void);
  21. #define crypto_aead_chacha20poly1305_ietf_ABYTES 16U
  22. SODIUM_EXPORT
  23. size_t crypto_aead_chacha20poly1305_ietf_abytes(void);
  24. #define crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX \
  25. SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ietf_ABYTES, \
  26. (64ULL * ((1ULL << 32) - 1ULL)))
  27. SODIUM_EXPORT
  28. size_t crypto_aead_chacha20poly1305_ietf_messagebytes_max(void);
  29. SODIUM_EXPORT
  30. int crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c,
  31. unsigned long long *clen_p,
  32. const unsigned char *m,
  33. unsigned long long mlen,
  34. const unsigned char *ad,
  35. unsigned long long adlen,
  36. const unsigned char *nsec,
  37. const unsigned char *npub,
  38. const unsigned char *k)
  39. __attribute__ ((nonnull(1, 8, 9)));
  40. SODIUM_EXPORT
  41. int crypto_aead_chacha20poly1305_ietf_decrypt(unsigned char *m,
  42. unsigned long long *mlen_p,
  43. unsigned char *nsec,
  44. const unsigned char *c,
  45. unsigned long long clen,
  46. const unsigned char *ad,
  47. unsigned long long adlen,
  48. const unsigned char *npub,
  49. const unsigned char *k)
  50. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));
  51. SODIUM_EXPORT
  52. int crypto_aead_chacha20poly1305_ietf_encrypt_detached(unsigned char *c,
  53. unsigned char *mac,
  54. unsigned long long *maclen_p,
  55. const unsigned char *m,
  56. unsigned long long mlen,
  57. const unsigned char *ad,
  58. unsigned long long adlen,
  59. const unsigned char *nsec,
  60. const unsigned char *npub,
  61. const unsigned char *k)
  62. __attribute__ ((nonnull(1, 2, 9, 10)));
  63. SODIUM_EXPORT
  64. int crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,
  65. unsigned char *nsec,
  66. const unsigned char *c,
  67. unsigned long long clen,
  68. const unsigned char *mac,
  69. const unsigned char *ad,
  70. unsigned long long adlen,
  71. const unsigned char *npub,
  72. const unsigned char *k)
  73. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));
  74. SODIUM_EXPORT
  75. void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_chacha20poly1305_ietf_KEYBYTES])
  76. __attribute__ ((nonnull));
  77. /* -- Original ChaCha20-Poly1305 construction with a 64-bit nonce and a 64-bit internal counter -- */
  78. #define crypto_aead_chacha20poly1305_KEYBYTES 32U
  79. SODIUM_EXPORT
  80. size_t crypto_aead_chacha20poly1305_keybytes(void);
  81. #define crypto_aead_chacha20poly1305_NSECBYTES 0U
  82. SODIUM_EXPORT
  83. size_t crypto_aead_chacha20poly1305_nsecbytes(void);
  84. #define crypto_aead_chacha20poly1305_NPUBBYTES 8U
  85. SODIUM_EXPORT
  86. size_t crypto_aead_chacha20poly1305_npubbytes(void);
  87. #define crypto_aead_chacha20poly1305_ABYTES 16U
  88. SODIUM_EXPORT
  89. size_t crypto_aead_chacha20poly1305_abytes(void);
  90. #define crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX \
  91. (SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ABYTES)
  92. SODIUM_EXPORT
  93. size_t crypto_aead_chacha20poly1305_messagebytes_max(void);
  94. SODIUM_EXPORT
  95. int crypto_aead_chacha20poly1305_encrypt(unsigned char *c,
  96. unsigned long long *clen_p,
  97. const unsigned char *m,
  98. unsigned long long mlen,
  99. const unsigned char *ad,
  100. unsigned long long adlen,
  101. const unsigned char *nsec,
  102. const unsigned char *npub,
  103. const unsigned char *k)
  104. __attribute__ ((nonnull(1, 8, 9)));
  105. SODIUM_EXPORT
  106. int crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
  107. unsigned long long *mlen_p,
  108. unsigned char *nsec,
  109. const unsigned char *c,
  110. unsigned long long clen,
  111. const unsigned char *ad,
  112. unsigned long long adlen,
  113. const unsigned char *npub,
  114. const unsigned char *k)
  115. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9)));
  116. SODIUM_EXPORT
  117. int crypto_aead_chacha20poly1305_encrypt_detached(unsigned char *c,
  118. unsigned char *mac,
  119. unsigned long long *maclen_p,
  120. const unsigned char *m,
  121. unsigned long long mlen,
  122. const unsigned char *ad,
  123. unsigned long long adlen,
  124. const unsigned char *nsec,
  125. const unsigned char *npub,
  126. const unsigned char *k)
  127. __attribute__ ((nonnull(1, 2, 9, 10)));
  128. SODIUM_EXPORT
  129. int crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,
  130. unsigned char *nsec,
  131. const unsigned char *c,
  132. unsigned long long clen,
  133. const unsigned char *mac,
  134. const unsigned char *ad,
  135. unsigned long long adlen,
  136. const unsigned char *npub,
  137. const unsigned char *k)
  138. __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9)));
  139. SODIUM_EXPORT
  140. void crypto_aead_chacha20poly1305_keygen(unsigned char k[crypto_aead_chacha20poly1305_KEYBYTES])
  141. __attribute__ ((nonnull));
  142. /* Aliases */
  143. #define crypto_aead_chacha20poly1305_IETF_KEYBYTES crypto_aead_chacha20poly1305_ietf_KEYBYTES
  144. #define crypto_aead_chacha20poly1305_IETF_NSECBYTES crypto_aead_chacha20poly1305_ietf_NSECBYTES
  145. #define crypto_aead_chacha20poly1305_IETF_NPUBBYTES crypto_aead_chacha20poly1305_ietf_NPUBBYTES
  146. #define crypto_aead_chacha20poly1305_IETF_ABYTES crypto_aead_chacha20poly1305_ietf_ABYTES
  147. #define crypto_aead_chacha20poly1305_IETF_MESSAGEBYTES_MAX crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif