crypto_secretstream_xchacha20poly1305.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef crypto_secretstream_xchacha20poly1305_H
  2. #define crypto_secretstream_xchacha20poly1305_H
  3. #include <stddef.h>
  4. #include "crypto_aead_xchacha20poly1305.h"
  5. #include "crypto_stream_chacha20.h"
  6. #include "export.h"
  7. #ifdef __cplusplus
  8. # ifdef __GNUC__
  9. # pragma GCC diagnostic ignored "-Wlong-long"
  10. # endif
  11. extern "C" {
  12. #endif
  13. #define crypto_secretstream_xchacha20poly1305_ABYTES \
  14. (1U + crypto_aead_xchacha20poly1305_ietf_ABYTES)
  15. SODIUM_EXPORT
  16. size_t crypto_secretstream_xchacha20poly1305_abytes(void);
  17. #define crypto_secretstream_xchacha20poly1305_HEADERBYTES \
  18. crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
  19. SODIUM_EXPORT
  20. size_t crypto_secretstream_xchacha20poly1305_headerbytes(void);
  21. #define crypto_secretstream_xchacha20poly1305_KEYBYTES \
  22. crypto_aead_xchacha20poly1305_ietf_KEYBYTES
  23. SODIUM_EXPORT
  24. size_t crypto_secretstream_xchacha20poly1305_keybytes(void);
  25. #define crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX \
  26. SODIUM_MIN(SODIUM_SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES, \
  27. (64ULL * ((1ULL << 32) - 2ULL)))
  28. SODIUM_EXPORT
  29. size_t crypto_secretstream_xchacha20poly1305_messagebytes_max(void);
  30. #define crypto_secretstream_xchacha20poly1305_TAG_MESSAGE 0x00
  31. SODIUM_EXPORT
  32. unsigned char crypto_secretstream_xchacha20poly1305_tag_message(void);
  33. #define crypto_secretstream_xchacha20poly1305_TAG_PUSH 0x01
  34. SODIUM_EXPORT
  35. unsigned char crypto_secretstream_xchacha20poly1305_tag_push(void);
  36. #define crypto_secretstream_xchacha20poly1305_TAG_REKEY 0x02
  37. SODIUM_EXPORT
  38. unsigned char crypto_secretstream_xchacha20poly1305_tag_rekey(void);
  39. #define crypto_secretstream_xchacha20poly1305_TAG_FINAL \
  40. (crypto_secretstream_xchacha20poly1305_TAG_PUSH | \
  41. crypto_secretstream_xchacha20poly1305_TAG_REKEY)
  42. SODIUM_EXPORT
  43. unsigned char crypto_secretstream_xchacha20poly1305_tag_final(void);
  44. typedef struct crypto_secretstream_xchacha20poly1305_state {
  45. unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES];
  46. unsigned char nonce[crypto_stream_chacha20_ietf_NONCEBYTES];
  47. unsigned char _pad[8];
  48. } crypto_secretstream_xchacha20poly1305_state;
  49. SODIUM_EXPORT
  50. size_t crypto_secretstream_xchacha20poly1305_statebytes(void);
  51. SODIUM_EXPORT
  52. void crypto_secretstream_xchacha20poly1305_keygen
  53. (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
  54. __attribute__ ((nonnull));
  55. SODIUM_EXPORT
  56. int crypto_secretstream_xchacha20poly1305_init_push
  57. (crypto_secretstream_xchacha20poly1305_state *state,
  58. unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
  59. const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
  60. __attribute__ ((nonnull));
  61. SODIUM_EXPORT
  62. int crypto_secretstream_xchacha20poly1305_push
  63. (crypto_secretstream_xchacha20poly1305_state *state,
  64. unsigned char *c, unsigned long long *clen_p,
  65. const unsigned char *m, unsigned long long mlen,
  66. const unsigned char *ad, unsigned long long adlen, unsigned char tag)
  67. __attribute__ ((nonnull(1)));
  68. SODIUM_EXPORT
  69. int crypto_secretstream_xchacha20poly1305_init_pull
  70. (crypto_secretstream_xchacha20poly1305_state *state,
  71. const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
  72. const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES])
  73. __attribute__ ((nonnull));
  74. SODIUM_EXPORT
  75. int crypto_secretstream_xchacha20poly1305_pull
  76. (crypto_secretstream_xchacha20poly1305_state *state,
  77. unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p,
  78. const unsigned char *c, unsigned long long clen,
  79. const unsigned char *ad, unsigned long long adlen)
  80. __attribute__ ((nonnull(1)));
  81. SODIUM_EXPORT
  82. void crypto_secretstream_xchacha20poly1305_rekey
  83. (crypto_secretstream_xchacha20poly1305_state *state);
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. #endif