1 /******************************************************************************* 2 3 D language bindings for libsodium's crypto_secretbox.h 4 5 License: ISC (see LICENSE.txt) 6 7 *******************************************************************************/ 8 9 module libsodium.crypto_secretbox; 10 11 @nogc nothrow: 12 13 import libsodium.export_; 14 import libsodium.crypto_secretbox_xsalsa20poly1305; 15 16 extern (C): 17 18 enum crypto_secretbox_KEYBYTES = crypto_secretbox_xsalsa20poly1305_KEYBYTES; 19 size_t crypto_secretbox_keybytes (); 20 21 enum crypto_secretbox_NONCEBYTES = crypto_secretbox_xsalsa20poly1305_NONCEBYTES; 22 size_t crypto_secretbox_noncebytes (); 23 24 enum crypto_secretbox_MACBYTES = crypto_secretbox_xsalsa20poly1305_MACBYTES; 25 size_t crypto_secretbox_macbytes (); 26 27 enum crypto_secretbox_PRIMITIVE = "xsalsa20poly1305"; 28 const(char)* crypto_secretbox_primitive (); 29 30 enum crypto_secretbox_MESSAGEBYTES_MAX = crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX; 31 size_t crypto_secretbox_messagebytes_max (); 32 33 int crypto_secretbox_easy ( 34 ubyte* c, 35 const(ubyte)* m, 36 ulong mlen, 37 const(ubyte)* n, 38 const(ubyte)* k); 39 40 int crypto_secretbox_open_easy ( 41 ubyte* m, 42 const(ubyte)* c, 43 ulong clen, 44 const(ubyte)* n, 45 const(ubyte)* k); 46 47 int crypto_secretbox_detached ( 48 ubyte* c, 49 ubyte* mac, 50 const(ubyte)* m, 51 ulong mlen, 52 const(ubyte)* n, 53 const(ubyte)* k); 54 55 int crypto_secretbox_open_detached ( 56 ubyte* m, 57 const(ubyte)* c, 58 const(ubyte)* mac, 59 ulong clen, 60 const(ubyte)* n, 61 const(ubyte)* k); 62 63 /** 64 * Generate a random keypair to use with `crypto_secretbox_*` functions 65 * 66 * This function just wraps a call to `randombytes_buf` 67 * It was introduced in v1.0.10, which is older than the Travis-CI package 68 * For ease of use, a D implementation is provided. 69 * 70 * See_Also: 71 * https://github.com/jedisct1/libsodium/blob/1.0.17/src/libsodium/crypto_secretbox/crypto_secretbox.c#L63-L67 72 */ 73 extern(D) void crypto_secretbox_keygen (ref ubyte[crypto_secretbox_KEYBYTES] k) 74 { 75 import libsodium.randombytes; 76 randombytes_buf(k.ptr, crypto_secretbox_KEYBYTES); 77 } 78 79 /* -- NaCl compatibility interface ; Requires padding -- */ 80 81 enum crypto_secretbox_ZEROBYTES = crypto_secretbox_xsalsa20poly1305_ZEROBYTES; 82 size_t crypto_secretbox_zerobytes (); 83 84 enum crypto_secretbox_BOXZEROBYTES = crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES; 85 size_t crypto_secretbox_boxzerobytes (); 86 87 int crypto_secretbox ( 88 ubyte* c, 89 const(ubyte)* m, 90 ulong mlen, 91 const(ubyte)* n, 92 const(ubyte)* k); 93 94 int crypto_secretbox_open ( 95 ubyte* m, 96 const(ubyte)* c, 97 ulong clen, 98 const(ubyte)* n, 99 const(ubyte)* k);