libsodium (1.0.19)
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 __attribute__ ((nonnull));
55
56 SODIUM_EXPORT
57 int crypto_box_keypair(unsigned char *pk, unsigned char *sk)
58 __attribute__ ((nonnull));
59
60 SODIUM_EXPORT
61 int crypto_box_easy(unsigned char *c, const unsigned char *m,
62 unsigned long long mlen, const unsigned char *n,
63 const unsigned char *pk, const unsigned char *sk)
64 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
65
66 SODIUM_EXPORT
67 int crypto_box_open_easy(unsigned char *m, const unsigned char *c,
68 unsigned long long clen, const unsigned char *n,
69 const unsigned char *pk, const unsigned char *sk)
70 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
71
72 SODIUM_EXPORT
73 int crypto_box_detached(unsigned char *c, unsigned char *mac,
74 const unsigned char *m, unsigned long long mlen,
75 const unsigned char *n, const unsigned char *pk,
76 const unsigned char *sk)
77 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7)));
78
79 SODIUM_EXPORT
80 int crypto_box_open_detached(unsigned char *m, const unsigned char *c,
81 const unsigned char *mac,
82 unsigned long long clen,
83 const unsigned char *n,
84 const unsigned char *pk,
85 const unsigned char *sk)
86 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6, 7)));
87
88 /* -- Precomputation interface -- */
89
90 #define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
91 SODIUM_EXPORT
92 size_t crypto_box_beforenmbytes(void);
93
94 SODIUM_EXPORT
95 int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
96 const unsigned char *sk)
97 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
98
99 SODIUM_EXPORT
100 int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m,
101 unsigned long long mlen, const unsigned char *n,
102 const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
103
104 SODIUM_EXPORT
105 int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c,
106 unsigned long long clen, const unsigned char *n,
107 const unsigned char *k)
108 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
109
110 SODIUM_EXPORT
111 int crypto_box_detached_afternm(unsigned char *c, unsigned char *mac,
112 const unsigned char *m, unsigned long long mlen,
113 const unsigned char *n, const unsigned char *k)
114 __attribute__ ((nonnull(1, 2, 5, 6)));
115
116 SODIUM_EXPORT
117 int crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c,
118 const unsigned char *mac,
119 unsigned long long clen, const unsigned char *n,
120 const unsigned char *k)
121 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));
122
123 /* -- Ephemeral SK interface -- */
124
125 #define crypto_box_SEALBYTES (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
126 SODIUM_EXPORT
127 size_t crypto_box_sealbytes(void);
128
129 SODIUM_EXPORT
130 int crypto_box_seal(unsigned char *c, const unsigned char *m,
131 unsigned long long mlen, const unsigned char *pk)
132 __attribute__ ((nonnull(1, 4)));
133
134 SODIUM_EXPORT
135 int crypto_box_seal_open(unsigned char *m, const unsigned char *c,
136 unsigned long long clen,
137 const unsigned char *pk, const unsigned char *sk)
138 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
139
140 /* -- NaCl compatibility interface ; Requires padding -- */
141
142 #define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
143 SODIUM_EXPORT
144 size_t crypto_box_zerobytes(void);
145
146 #define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
147 SODIUM_EXPORT
148 size_t crypto_box_boxzerobytes(void);
149
150 SODIUM_EXPORT
151 int crypto_box(unsigned char *c, const unsigned char *m,
152 unsigned long long mlen, const unsigned char *n,
153 const unsigned char *pk, const unsigned char *sk)
154 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6)));
155
156 SODIUM_EXPORT
157 int crypto_box_open(unsigned char *m, const unsigned char *c,
158 unsigned long long clen, const unsigned char *n,
159 const unsigned char *pk, const unsigned char *sk)
160 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6)));
161
162 SODIUM_EXPORT
163 int crypto_box_afternm(unsigned char *c, const unsigned char *m,
164 unsigned long long mlen, const unsigned char *n,
165 const unsigned char *k) __attribute__ ((nonnull(1, 4, 5)));
166
167 SODIUM_EXPORT
168 int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
169 unsigned long long clen, const unsigned char *n,
170 const unsigned char *k)
171 __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif