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