1 /*******************************************************************************
2 
3     D language bindings for libsodium's crypto_stream_chacha20.h
4 
5     License: ISC (see LICENSE.txt)
6 
7 *******************************************************************************/
8 
9 module libsodium.crypto_stream_chacha20;
10 
11 @nogc nothrow:
12 
13 import libsodium.export_;
14 
15 extern (C):
16 
17 /*
18  *  WARNING: This is just a stream cipher. It is NOT authenticated encryption.
19  *  While it provides some protection against eavesdropping, it does NOT
20  *  provide any security against active attacks.
21  *  Unless you know what you're doing, what you are looking for is probably
22  *  the crypto_box functions.
23  */
24 
25 enum crypto_stream_chacha20_KEYBYTES = 32U;
26 size_t crypto_stream_chacha20_keybytes ();
27 
28 enum crypto_stream_chacha20_NONCEBYTES = 8U;
29 size_t crypto_stream_chacha20_noncebytes ();
30 
31 enum crypto_stream_chacha20_MESSAGEBYTES_MAX = SODIUM_SIZE_MAX;
32 size_t crypto_stream_chacha20_messagebytes_max ();
33 
34 /* ChaCha20 with a 64-bit nonce and a 64-bit counter, as originally designed */
35 
36 int crypto_stream_chacha20 (
37     ubyte* c,
38     ulong clen,
39     const(ubyte)* n,
40     const(ubyte)* k);
41 
42 int crypto_stream_chacha20_xor (
43     ubyte* c,
44     const(ubyte)* m,
45     ulong mlen,
46     const(ubyte)* n,
47     const(ubyte)* k);
48 
49 int crypto_stream_chacha20_xor_ic (
50     ubyte* c,
51     const(ubyte)* m,
52     ulong mlen,
53     const(ubyte)* n,
54     ulong ic,
55     const(ubyte)* k);
56 
57 void crypto_stream_chacha20_keygen (
58     ref ubyte[crypto_stream_chacha20_KEYBYTES] k);
59 
60 /* ChaCha20 with a 96-bit nonce and a 32-bit counter (IETF) */
61 
62 enum crypto_stream_chacha20_ietf_KEYBYTES = 32U;
63 size_t crypto_stream_chacha20_ietf_keybytes ();
64 
65 enum crypto_stream_chacha20_ietf_NONCEBYTES = 12U;
66 size_t crypto_stream_chacha20_ietf_noncebytes ();
67 
68 enum crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX = SODIUM_MIN(SODIUM_SIZE_MAX, 64UL * (1UL << 32));
69 size_t crypto_stream_chacha20_ietf_messagebytes_max ();
70 
71 int crypto_stream_chacha20_ietf (
72     ubyte* c,
73     ulong clen,
74     const(ubyte)* n,
75     const(ubyte)* k);
76 
77 int crypto_stream_chacha20_ietf_xor (
78     ubyte* c,
79     const(ubyte)* m,
80     ulong mlen,
81     const(ubyte)* n,
82     const(ubyte)* k);
83 
84 int crypto_stream_chacha20_ietf_xor_ic (
85     ubyte* c,
86     const(ubyte)* m,
87     ulong mlen,
88     const(ubyte)* n,
89     uint ic,
90     const(ubyte)* k);
91 
92 void crypto_stream_chacha20_ietf_keygen (
93     ref ubyte[crypto_stream_chacha20_ietf_KEYBYTES] k);
94 
95 /* Aliases */
96 
97 enum crypto_stream_chacha20_IETF_KEYBYTES = crypto_stream_chacha20_ietf_KEYBYTES;
98 enum crypto_stream_chacha20_IETF_NONCEBYTES = crypto_stream_chacha20_ietf_NONCEBYTES;
99 enum crypto_stream_chacha20_IETF_MESSAGEBYTES_MAX = crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX;