1 /*******************************************************************************
2 
3     D language bindings for libsodium's crypto_secretstream_xchacha20poly1305.h
4 
5     License: ISC (see LICENSE.txt)
6 
7 *******************************************************************************/
8 
9 module libsodium.crypto_secretstream_xchacha20poly1305;
10 
11 @nogc nothrow:
12 
13 import libsodium.export_;
14 import libsodium.crypto_aead_xchacha20poly1305;
15 import libsodium.crypto_stream_chacha20;
16 
17 extern (C):
18 
19 enum crypto_secretstream_xchacha20poly1305_ABYTES = 1U + crypto_aead_xchacha20poly1305_ietf_ABYTES;
20 size_t crypto_secretstream_xchacha20poly1305_abytes ();
21 
22 enum crypto_secretstream_xchacha20poly1305_HEADERBYTES = crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
23 size_t crypto_secretstream_xchacha20poly1305_headerbytes ();
24 
25 enum crypto_secretstream_xchacha20poly1305_KEYBYTES = crypto_aead_xchacha20poly1305_ietf_KEYBYTES;
26 size_t crypto_secretstream_xchacha20poly1305_keybytes ();
27 
28 enum crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX = SODIUM_MIN(SODIUM_SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES, 64UL * ((1UL << 32) - 2UL));
29 size_t crypto_secretstream_xchacha20poly1305_messagebytes_max ();
30 
31 enum crypto_secretstream_xchacha20poly1305_TAG_MESSAGE = 0x00;
32 ubyte crypto_secretstream_xchacha20poly1305_tag_message ();
33 
34 enum crypto_secretstream_xchacha20poly1305_TAG_PUSH = 0x01;
35 ubyte crypto_secretstream_xchacha20poly1305_tag_push ();
36 
37 enum crypto_secretstream_xchacha20poly1305_TAG_REKEY = 0x02;
38 ubyte crypto_secretstream_xchacha20poly1305_tag_rekey ();
39 
40 enum crypto_secretstream_xchacha20poly1305_TAG_FINAL = crypto_secretstream_xchacha20poly1305_TAG_PUSH | crypto_secretstream_xchacha20poly1305_TAG_REKEY;
41 ubyte crypto_secretstream_xchacha20poly1305_tag_final ();
42 
43 struct crypto_secretstream_xchacha20poly1305_state
44 {
45     ubyte[crypto_stream_chacha20_ietf_KEYBYTES] k;
46     ubyte[crypto_stream_chacha20_ietf_NONCEBYTES] nonce;
47     ubyte[8] _pad;
48 }
49 
50 size_t crypto_secretstream_xchacha20poly1305_statebytes ();
51 
52 void crypto_secretstream_xchacha20poly1305_keygen (
53     ref ubyte[crypto_secretstream_xchacha20poly1305_KEYBYTES] k);
54 
55 int crypto_secretstream_xchacha20poly1305_init_push (
56     crypto_secretstream_xchacha20poly1305_state* state,
57     ref ubyte[crypto_secretstream_xchacha20poly1305_HEADERBYTES] header,
58     ref const(ubyte)[crypto_secretstream_xchacha20poly1305_KEYBYTES] k);
59 
60 int crypto_secretstream_xchacha20poly1305_push (
61     crypto_secretstream_xchacha20poly1305_state* state,
62     ubyte* c,
63     ulong* clen_p,
64     const(ubyte)* m,
65     ulong mlen,
66     const(ubyte)* ad,
67     ulong adlen,
68     ubyte tag);
69 
70 int crypto_secretstream_xchacha20poly1305_init_pull (
71     crypto_secretstream_xchacha20poly1305_state* state,
72     ref const(ubyte)[crypto_secretstream_xchacha20poly1305_HEADERBYTES] header,
73     ref const(ubyte)[crypto_secretstream_xchacha20poly1305_KEYBYTES] k);
74 
75 int crypto_secretstream_xchacha20poly1305_pull (
76     crypto_secretstream_xchacha20poly1305_state* state,
77     ubyte* m,
78     ulong* mlen_p,
79     ubyte* tag_p,
80     const(ubyte)* c,
81     ulong clen,
82     const(ubyte)* ad,
83     ulong adlen);
84 
85 void crypto_secretstream_xchacha20poly1305_rekey (
86     crypto_secretstream_xchacha20poly1305_state* state);