1 /*
2 Written in the D programming language.
3 For git maintenance (ensure at least one congruent line with originating C header):
4 #define crypto_secretbox_H
5 */
6 
7 module deimos.sodium.crypto_secretbox;
8 
9 import deimos.sodium.crypto_secretbox_xsalsa20poly1305 : crypto_secretbox_xsalsa20poly1305_KEYBYTES,
10                                                          crypto_secretbox_xsalsa20poly1305_NONCEBYTES,
11                                                          crypto_secretbox_xsalsa20poly1305_MACBYTES,
12                                                          crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX,
13                                                          crypto_secretbox_xsalsa20poly1305_ZEROBYTES,
14                                                          crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES;
15 
16 
17 extern(C) @nogc :
18 
19 
20 alias crypto_secretbox_KEYBYTES = crypto_secretbox_xsalsa20poly1305_KEYBYTES;
21 
22 size_t  crypto_secretbox_keybytes() pure @trusted;
23 
24 alias crypto_secretbox_NONCEBYTES = crypto_secretbox_xsalsa20poly1305_NONCEBYTES;
25 
26 size_t  crypto_secretbox_noncebytes() pure @trusted;
27 
28 alias crypto_secretbox_MACBYTES = crypto_secretbox_xsalsa20poly1305_MACBYTES;
29 
30 size_t  crypto_secretbox_macbytes() pure @trusted;
31 
32 enum crypto_secretbox_PRIMITIVE = "xsalsa20poly1305";
33 
34 /* Deviating from C header, in D the following function expresses __attribute__ ((warn_unused_result)) as well (if compiler switch -w is thrown) */
35 const(char)* crypto_secretbox_primitive() pure nothrow @trusted;
36 
37 alias crypto_secretbox_MESSAGEBYTES_MAX = crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX;
38 
39 size_t crypto_secretbox_messagebytes_max() pure @trusted;
40 
41 int crypto_secretbox_easy(ubyte* c, const(ubyte)* m,
42                           ulong mlen, const(ubyte)* n,
43                           const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 4, 5)));
44 
45 int crypto_secretbox_open_easy(ubyte* m, const(ubyte)* c,
46                                ulong clen, const(ubyte)* n,
47                                const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));
48 
49 int crypto_secretbox_detached(ubyte* c, ubyte* mac,
50                               const(ubyte)* m,
51                               ulong mlen,
52                               const(ubyte)* n,
53                               const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 2, 5, 6)));
54 
55 int crypto_secretbox_open_detached(ubyte* m,
56                                    const(ubyte)* c,
57                                    const(ubyte)* mac,
58                                    ulong clen,
59                                    const(ubyte)* n,
60                                    const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6)));
61 
62 void crypto_secretbox_keygen(ref ubyte[crypto_secretbox_KEYBYTES] k) nothrow @trusted; // __attribute__ ((nonnull));
63 
64 /* -- NaCl compatibility interface ; Requires padding -- */
65 
66 alias crypto_secretbox_ZEROBYTES = crypto_secretbox_xsalsa20poly1305_ZEROBYTES;
67 
68 size_t  crypto_secretbox_zerobytes() pure @trusted;
69 
70 alias crypto_secretbox_BOXZEROBYTES = crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES;
71 
72 size_t  crypto_secretbox_boxzerobytes() pure @trusted;
73 
74 int crypto_secretbox(ubyte* c, const(ubyte)* m,
75                      ulong mlen, const(ubyte)* n,
76                      const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 4, 5)));
77 
78 int crypto_secretbox_open(ubyte* m, const(ubyte)* c,
79                           ulong clen, const(ubyte)* n,
80                           const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));