xref: /freebsd/sys/contrib/libsodium/src/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h (revision 3611ec604864a7d4dcc9a3ea898c80eb35eef8a0)
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, ((1ULL << 32) - 2ULL) * 64ULL)
34 SODIUM_EXPORT
35 size_t crypto_secretstream_xchacha20poly1305_messagebytes_max(void);
36 
37 #define crypto_secretstream_xchacha20poly1305_TAG_MESSAGE 0x00
38 SODIUM_EXPORT
39 unsigned char crypto_secretstream_xchacha20poly1305_tag_message(void);
40 
41 #define crypto_secretstream_xchacha20poly1305_TAG_PUSH    0x01
42 SODIUM_EXPORT
43 unsigned char crypto_secretstream_xchacha20poly1305_tag_push(void);
44 
45 #define crypto_secretstream_xchacha20poly1305_TAG_REKEY   0x02
46 SODIUM_EXPORT
47 unsigned char crypto_secretstream_xchacha20poly1305_tag_rekey(void);
48 
49 #define crypto_secretstream_xchacha20poly1305_TAG_FINAL \
50     (crypto_secretstream_xchacha20poly1305_TAG_PUSH | \
51      crypto_secretstream_xchacha20poly1305_TAG_REKEY)
52 SODIUM_EXPORT
53 unsigned char crypto_secretstream_xchacha20poly1305_tag_final(void);
54 
55 typedef struct crypto_secretstream_xchacha20poly1305_state {
56     unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES];
57     unsigned char nonce[crypto_stream_chacha20_ietf_NONCEBYTES];
58     unsigned char _pad[8];
59 } crypto_secretstream_xchacha20poly1305_state;
60 
61 SODIUM_EXPORT
62 size_t crypto_secretstream_xchacha20poly1305_statebytes(void);
63 
64 SODIUM_EXPORT
65 void crypto_secretstream_xchacha20poly1305_keygen
66    (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]);
67 
68 SODIUM_EXPORT
69 int crypto_secretstream_xchacha20poly1305_init_push
70    (crypto_secretstream_xchacha20poly1305_state *state,
71     unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
72     const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]);
73 
74 SODIUM_EXPORT
75 int crypto_secretstream_xchacha20poly1305_push
76    (crypto_secretstream_xchacha20poly1305_state *state,
77     unsigned char *c, unsigned long long *clen_p,
78     const unsigned char *m, unsigned long long mlen,
79     const unsigned char *ad, unsigned long long adlen, unsigned char tag);
80 
81 SODIUM_EXPORT
82 int crypto_secretstream_xchacha20poly1305_init_pull
83    (crypto_secretstream_xchacha20poly1305_state *state,
84     const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
85     const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]);
86 
87 SODIUM_EXPORT
88 int crypto_secretstream_xchacha20poly1305_pull
89    (crypto_secretstream_xchacha20poly1305_state *state,
90     unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p,
91     const unsigned char *c, unsigned long long clen,
92     const unsigned char *ad, unsigned long long adlen);
93 
94 SODIUM_EXPORT
95 void crypto_secretstream_xchacha20poly1305_rekey
96     (crypto_secretstream_xchacha20poly1305_state *state);
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif
103