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