xref: /freebsd/sys/contrib/libsodium/src/libsodium/include/sodium/crypto_box.h (revision 3611ec604864a7d4dcc9a3ea898c80eb35eef8a0)
1 #ifndef crypto_box_H
2 #define crypto_box_H
3 
4 /*
5  * THREAD SAFETY: crypto_box_keypair() is thread-safe,
6  * provided that sodium_init() was called before.
7  *
8  * Other functions are always thread-safe.
9  */
10 
11 #include <stddef.h>
12 
13 #include "crypto_box_curve25519xsalsa20poly1305.h"
14 #include "export.h"
15 
16 #ifdef __cplusplus
17 # ifdef __GNUC__
18 #  pragma GCC diagnostic ignored "-Wlong-long"
19 # endif
20 extern "C" {
21 #endif
22 
23 #define crypto_box_SEEDBYTES crypto_box_curve25519xsalsa20poly1305_SEEDBYTES
24 SODIUM_EXPORT
25 size_t  crypto_box_seedbytes(void);
26 
27 #define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
28 SODIUM_EXPORT
29 size_t  crypto_box_publickeybytes(void);
30 
31 #define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
32 SODIUM_EXPORT
33 size_t  crypto_box_secretkeybytes(void);
34 
35 #define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
36 SODIUM_EXPORT
37 size_t  crypto_box_noncebytes(void);
38 
39 #define crypto_box_MACBYTES crypto_box_curve25519xsalsa20poly1305_MACBYTES
40 SODIUM_EXPORT
41 size_t  crypto_box_macbytes(void);
42 
43 #define crypto_box_MESSAGEBYTES_MAX crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX
44 SODIUM_EXPORT
45 size_t  crypto_box_messagebytes_max(void);
46 
47 #define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"
48 SODIUM_EXPORT
49 const char *crypto_box_primitive(void);
50 
51 SODIUM_EXPORT
52 int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
53                             const unsigned char *seed);
54 
55 SODIUM_EXPORT
56 int crypto_box_keypair(unsigned char *pk, unsigned char *sk);
57 
58 SODIUM_EXPORT
59 int crypto_box_easy(unsigned char *c, const unsigned char *m,
60                     unsigned long long mlen, const unsigned char *n,
61                     const unsigned char *pk, const unsigned char *sk)
62             __attribute__ ((warn_unused_result));
63 
64 SODIUM_EXPORT
65 int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
66                          unsigned long long clen, const unsigned char *n,
67                          const unsigned char *pk, const unsigned char *sk)
68             __attribute__ ((warn_unused_result));
69 
70 SODIUM_EXPORT
71 int crypto_box_detached(unsigned char *c, unsigned char *mac,
72                         const unsigned char *m, unsigned long long mlen,
73                         const unsigned char *n, const unsigned char *pk,
74                         const unsigned char *sk)
75             __attribute__ ((warn_unused_result));
76 
77 SODIUM_EXPORT
78 int crypto_box_open_detached(unsigned char *m, const unsigned char *c,
79                              const unsigned char *mac,
80                              unsigned long long clen,
81                              const unsigned char *n,
82                              const unsigned char *pk,
83                              const unsigned char *sk)
84             __attribute__ ((warn_unused_result));
85 
86 /* -- Precomputation interface -- */
87 
88 #define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
89 SODIUM_EXPORT
90 size_t  crypto_box_beforenmbytes(void);
91 
92 SODIUM_EXPORT
93 int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
94                         const unsigned char *sk)
95             __attribute__ ((warn_unused_result));
96 
97 SODIUM_EXPORT
98 int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
99                             unsigned long long mlen, const unsigned char *n,
100                             const unsigned char *k);
101 
102 SODIUM_EXPORT
103 int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
104                                  unsigned long long clen, const unsigned char *n,
105                                  const unsigned char *k)
106             __attribute__ ((warn_unused_result));
107 
108 SODIUM_EXPORT
109 int crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,
110                                 const unsigned char *m, unsigned long long mlen,
111                                 const unsigned char *n, const unsigned char *k);
112 
113 SODIUM_EXPORT
114 int crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c,
115                                      const unsigned char *mac,
116                                      unsigned long long clen, const unsigned char *n,
117                                      const unsigned char *k)
118             __attribute__ ((warn_unused_result));
119 
120 /* -- Ephemeral SK interface -- */
121 
122 #define crypto_box_SEALBYTES (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
123 SODIUM_EXPORT
124 size_t crypto_box_sealbytes(void);
125 
126 SODIUM_EXPORT
127 int crypto_box_seal(unsigned char *c, const unsigned char *m,
128                     unsigned long long mlen, const unsigned char *pk);
129 
130 SODIUM_EXPORT
131 int crypto_box_seal_open(unsigned char *m, const unsigned char *c,
132                          unsigned long long clen,
133                          const unsigned char *pk, const unsigned char *sk)
134             __attribute__ ((warn_unused_result));
135 
136 /* -- NaCl compatibility interface ; Requires padding -- */
137 
138 #define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
139 SODIUM_EXPORT
140 size_t  crypto_box_zerobytes(void);
141 
142 #define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
143 SODIUM_EXPORT
144 size_t  crypto_box_boxzerobytes(void);
145 
146 SODIUM_EXPORT
147 int crypto_box(unsigned char *c, const unsigned char *m,
148                unsigned long long mlen, const unsigned char *n,
149                const unsigned char *pk, const unsigned char *sk)
150             __attribute__ ((warn_unused_result));
151 
152 SODIUM_EXPORT
153 int crypto_box_open(unsigned char *m, const unsigned char *c,
154                     unsigned long long clen, const unsigned char *n,
155                     const unsigned char *pk, const unsigned char *sk)
156             __attribute__ ((warn_unused_result));
157 
158 SODIUM_EXPORT
159 int crypto_box_afternm(unsigned char *c, const unsigned char *m,
160                        unsigned long long mlen, const unsigned char *n,
161                        const unsigned char *k);
162 
163 SODIUM_EXPORT
164 int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
165                             unsigned long long clen, const unsigned char *n,
166                             const unsigned char *k)
167             __attribute__ ((warn_unused_result));
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif
174