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_box_H 5 */ 6 7 module deimos.sodium.crypto_box; 8 9 /* 10 * THREAD SAFETY: crypto_box_keypair() is thread-safe, 11 * provided that sodium_init() was called before. 12 * 13 * Other functions are always thread-safe. 14 */ 15 16 import deimos.sodium.crypto_box_curve25519xsalsa20poly1305 : crypto_box_curve25519xsalsa20poly1305_SEEDBYTES, 17 crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES, 18 crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES, 19 crypto_box_curve25519xsalsa20poly1305_NONCEBYTES, 20 crypto_box_curve25519xsalsa20poly1305_MACBYTES, 21 crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX, 22 crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES, 23 crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, 24 crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; 25 26 27 extern(C) @nogc : 28 29 30 alias crypto_box_SEEDBYTES = crypto_box_curve25519xsalsa20poly1305_SEEDBYTES; 31 32 size_t crypto_box_seedbytes() pure @trusted; 33 34 alias crypto_box_PUBLICKEYBYTES = crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES; 35 36 size_t crypto_box_publickeybytes() pure @trusted; 37 38 alias crypto_box_SECRETKEYBYTES = crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES; 39 40 size_t crypto_box_secretkeybytes() pure @trusted; 41 42 alias crypto_box_NONCEBYTES = crypto_box_curve25519xsalsa20poly1305_NONCEBYTES; 43 44 size_t crypto_box_noncebytes() pure @trusted; 45 46 alias crypto_box_MACBYTES = crypto_box_curve25519xsalsa20poly1305_MACBYTES; 47 48 size_t crypto_box_macbytes() pure @trusted; 49 50 alias crypto_box_MESSAGEBYTES_MAX = crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX; 51 52 size_t crypto_box_messagebytes_max() pure @trusted; 53 54 enum crypto_box_PRIMITIVE = "curve25519xsalsa20poly1305"; 55 56 const(char)* crypto_box_primitive() pure @trusted; 57 58 int crypto_box_seed_keypair(ubyte* pk, ubyte* sk, 59 const(ubyte)* seed) pure; // __attribute__ ((nonnull)); 60 61 int crypto_box_keypair(ubyte* pk, ubyte* sk) nothrow; // __attribute__ ((nonnull)); 62 63 int crypto_box_easy(ubyte* c, const(ubyte)* m, 64 ulong mlen, const(ubyte)* n, 65 const(ubyte)* pk, const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6))); 66 67 int crypto_box_open_easy(ubyte* m, const(ubyte)* c, 68 ulong clen, const(ubyte)* n, 69 const(ubyte)* pk, const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6))); 70 71 int crypto_box_detached(ubyte* c, ubyte* mac, 72 const(ubyte)* m, ulong mlen, 73 const(ubyte)* n, const(ubyte)* pk, 74 const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7))); 75 76 int crypto_box_open_detached(ubyte* m, const(ubyte)* c, 77 const(ubyte)* mac, 78 ulong clen, 79 const(ubyte)* n, 80 const(ubyte)* pk, 81 const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6, 7))); 82 83 /* -- Precomputation interface -- */ 84 85 alias crypto_box_BEFORENMBYTES = crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES; 86 87 size_t crypto_box_beforenmbytes() pure @trusted; 88 89 int crypto_box_beforenm(ubyte* k, const(ubyte)* pk, 90 const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); 91 92 int crypto_box_easy_afternm(ubyte* c, const(ubyte)* m, 93 ulong mlen, const(ubyte)* n, 94 const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 4, 5))); 95 96 int crypto_box_open_easy_afternm(ubyte* m, const(ubyte)* c, 97 ulong clen, const(ubyte)* n, 98 const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5))); 99 100 int crypto_box_detached_afternm(ubyte* c, ubyte* mac, 101 const(ubyte)* m, ulong mlen, 102 const(ubyte)* n, const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 2, 5, 6))); 103 104 int crypto_box_open_detached_afternm(ubyte* m, const(ubyte)* c, 105 const(ubyte)* mac, 106 ulong clen, const(ubyte)* n, 107 const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 3, 5, 6))); 108 109 /* -- Ephemeral SK interface -- */ 110 111 enum crypto_box_SEALBYTES = (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES); 112 113 size_t crypto_box_sealbytes() pure @trusted; 114 115 int crypto_box_seal(ubyte* c, const(ubyte)* m, 116 ulong mlen, const(ubyte)* pk) pure; // __attribute__ ((nonnull(1, 4))); 117 118 int crypto_box_seal_open(ubyte* m, const(ubyte)* c, 119 ulong clen, 120 const(ubyte)* pk, const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5))); 121 122 /* -- NaCl compatibility interface ; Requires padding -- */ 123 124 alias crypto_box_ZEROBYTES = crypto_box_curve25519xsalsa20poly1305_ZEROBYTES; 125 126 size_t crypto_box_zerobytes() pure @trusted; 127 128 alias crypto_box_BOXZEROBYTES = crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES; 129 130 size_t crypto_box_boxzerobytes() pure @trusted; 131 132 int crypto_box(ubyte* c, const(ubyte)* m, 133 ulong mlen, const(ubyte)* n, 134 const(ubyte)* pk, const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6))); 135 136 int crypto_box_open(ubyte* m, const(ubyte)* c, 137 ulong clen, const(ubyte)* n, 138 const(ubyte)* pk, const(ubyte)* sk) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5, 6))); 139 140 int crypto_box_afternm(ubyte* c, const(ubyte)* m, 141 ulong mlen, const(ubyte)* n, 142 const(ubyte)* k); // __attribute__ ((nonnull(1, 4, 5))); 143 144 int crypto_box_open_afternm(ubyte* m, const(ubyte)* c, 145 ulong clen, const(ubyte)* n, 146 const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(2, 4, 5)));