1 /*******************************************************************************
2 
3     D language bindings for libsodium's crypto_generichash.h
4 
5     License: ISC (see LICENSE.txt)
6 
7 *******************************************************************************/
8 
9 module libsodium.crypto_generichash;
10 
11 @nogc nothrow:
12 
13 import libsodium.export_;
14 import libsodium.crypto_generichash_blake2b;
15 
16 extern (C):
17 
18 enum crypto_generichash_BYTES_MIN = crypto_generichash_blake2b_BYTES_MIN;
19 size_t crypto_generichash_bytes_min () @safe pure;
20 
21 enum crypto_generichash_BYTES_MAX = crypto_generichash_blake2b_BYTES_MAX;
22 size_t crypto_generichash_bytes_max () @safe pure;
23 
24 enum crypto_generichash_BYTES = crypto_generichash_blake2b_BYTES;
25 size_t crypto_generichash_bytes () @safe pure;
26 
27 enum crypto_generichash_KEYBYTES_MIN = crypto_generichash_blake2b_KEYBYTES_MIN;
28 size_t crypto_generichash_keybytes_min () @safe pure;
29 
30 enum crypto_generichash_KEYBYTES_MAX = crypto_generichash_blake2b_KEYBYTES_MAX;
31 size_t crypto_generichash_keybytes_max () @safe pure;
32 
33 enum crypto_generichash_KEYBYTES = crypto_generichash_blake2b_KEYBYTES;
34 size_t crypto_generichash_keybytes () @safe pure;
35 
36 enum crypto_generichash_PRIMITIVE = "blake2b";
37 const(char)* crypto_generichash_primitive () @safe pure;
38 
39 /*
40  * Important when writing bindings for other programming languages:
41  * the state address should be 64-bytes aligned.
42  */
43 alias crypto_generichash_state = crypto_generichash_blake2b_state;
44 
45 size_t crypto_generichash_statebytes () @safe pure;
46 
47 int crypto_generichash (
48     scope ubyte* out_,
49     size_t outlen,
50     scope const(ubyte)* in_,
51     ulong inlen,
52     scope const(ubyte)* key,
53     size_t keylen) pure;
54 
55 /// @safe wrapper around `crypto_generichash`
56 extern(D) int crypto_generichash (
57     scope ubyte[] out_,
58     scope const ubyte[] in_,
59     scope const ubyte[] key) @trusted pure
60 {
61     return crypto_generichash(
62         out_.ptr, out_.length,
63         in_.ptr, in_.length,
64         key.ptr, key.length);
65 }
66 
67 int crypto_generichash_init (
68     scope crypto_generichash_state* state,
69     scope const(ubyte)* key,
70     const size_t keylen,
71     const size_t outlen) pure;
72 
73 /// @safe wrapper around `crypto_generichash_init`
74 extern(D) int crypto_generichash_init (
75     scope ref crypto_generichash_state state,
76     scope const(ubyte)[] key,
77     size_t outlen) @trusted pure
78 {
79     return crypto_generichash_init(&state, key.ptr, key.length, outlen);
80 }
81 
82 int crypto_generichash_update (
83     scope crypto_generichash_state* state,
84     scope const(ubyte)* in_,
85     ulong inlen) pure;
86 
87 /// @safe wrapper around `crypto_generichash_update`
88 extern(D) int crypto_generichash_update (
89     scope ref crypto_generichash_state state,
90     scope const(ubyte)[] in_) @trusted pure
91 {
92     return crypto_generichash_update(&state, in_.ptr, in_.length);
93 }
94 
95 int crypto_generichash_final (
96     scope crypto_generichash_state* state,
97     scope ubyte* out_,
98     const size_t outlen) pure;
99 
100 /// @safe wrapper around `crypto_generichash_final`
101 extern(D) int crypto_generichash_final (
102     scope ref crypto_generichash_state state,
103     scope ubyte[] out_) @trusted pure
104 {
105     return crypto_generichash_final(&state, out_.ptr, out_.length);
106 }
107 
108 void crypto_generichash_keygen (ref ubyte[crypto_generichash_KEYBYTES] k) @safe;