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