1 /******************************************************************************* 2 3 D language bindings for libsodium's crypto_aead_aes256gcm.h 4 5 License: ISC (see LICENSE.txt) 6 7 *******************************************************************************/ 8 9 module libsodium.crypto_aead_aes256gcm; 10 11 @nogc nothrow: 12 13 import libsodium.export_; 14 15 extern (C): 16 17 /* 18 * WARNING: Despite being the most popular AEAD construction due to its 19 * use in TLS, safely using AES-GCM in a different context is tricky. 20 * 21 * No more than ~ 350 GB of input data should be encrypted with a given key. 22 * This is for ~ 16 KB messages -- Actual figures vary according to 23 * message sizes. 24 * 25 * In addition, nonces are short and repeated nonces would totally destroy 26 * the security of this scheme. 27 * 28 * Nonces should thus come from atomic counters, which can be difficult to 29 * set up in a distributed environment. 30 * 31 * Unless you absolutely need AES-GCM, use crypto_aead_xchacha20poly1305_ietf_*() 32 * instead. It doesn't have any of these limitations. 33 * Or, if you don't need to authenticate additional data, just stick to 34 * crypto_secretbox(). 35 */ 36 37 int crypto_aead_aes256gcm_is_available (); 38 39 enum crypto_aead_aes256gcm_KEYBYTES = 32U; 40 size_t crypto_aead_aes256gcm_keybytes (); 41 42 enum crypto_aead_aes256gcm_NSECBYTES = 0U; 43 size_t crypto_aead_aes256gcm_nsecbytes (); 44 45 enum crypto_aead_aes256gcm_NPUBBYTES = 12U; 46 size_t crypto_aead_aes256gcm_npubbytes (); 47 48 enum crypto_aead_aes256gcm_ABYTES = 16U; 49 size_t crypto_aead_aes256gcm_abytes (); 50 51 enum crypto_aead_aes256gcm_MESSAGEBYTES_MAX = 52 SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_aes256gcm_ABYTES, 16UL * ((1UL << 32) - 2UL)); 53 size_t crypto_aead_aes256gcm_messagebytes_max (); 54 55 align(16) struct crypto_aead_aes256gcm_state_ 56 { 57 ubyte[512] opaque; 58 } 59 60 alias crypto_aead_aes256gcm_state = crypto_aead_aes256gcm_state_; 61 62 size_t crypto_aead_aes256gcm_statebytes (); 63 64 int crypto_aead_aes256gcm_encrypt ( 65 ubyte* c, 66 ulong* clen_p, 67 const(ubyte)* m, 68 ulong mlen, 69 const(ubyte)* ad, 70 ulong adlen, 71 const(ubyte)* nsec, 72 const(ubyte)* npub, 73 const(ubyte)* k); 74 75 int crypto_aead_aes256gcm_decrypt ( 76 ubyte* m, 77 ulong* mlen_p, 78 ubyte* nsec, 79 const(ubyte)* c, 80 ulong clen, 81 const(ubyte)* ad, 82 ulong adlen, 83 const(ubyte)* npub, 84 const(ubyte)* k); 85 86 int crypto_aead_aes256gcm_encrypt_detached ( 87 ubyte* c, 88 ubyte* mac, 89 ulong* maclen_p, 90 const(ubyte)* m, 91 ulong mlen, 92 const(ubyte)* ad, 93 ulong adlen, 94 const(ubyte)* nsec, 95 const(ubyte)* npub, 96 const(ubyte)* k); 97 98 int crypto_aead_aes256gcm_decrypt_detached ( 99 ubyte* m, 100 ubyte* nsec, 101 const(ubyte)* c, 102 ulong clen, 103 const(ubyte)* mac, 104 const(ubyte)* ad, 105 ulong adlen, 106 const(ubyte)* npub, 107 const(ubyte)* k); 108 109 /* -- Precomputation interface -- */ 110 111 int crypto_aead_aes256gcm_beforenm ( 112 crypto_aead_aes256gcm_state* ctx_, 113 const(ubyte)* k); 114 115 int crypto_aead_aes256gcm_encrypt_afternm ( 116 ubyte* c, 117 ulong* clen_p, 118 const(ubyte)* m, 119 ulong mlen, 120 const(ubyte)* ad, 121 ulong adlen, 122 const(ubyte)* nsec, 123 const(ubyte)* npub, 124 const(crypto_aead_aes256gcm_state)* ctx_); 125 126 int crypto_aead_aes256gcm_decrypt_afternm ( 127 ubyte* m, 128 ulong* mlen_p, 129 ubyte* nsec, 130 const(ubyte)* c, 131 ulong clen, 132 const(ubyte)* ad, 133 ulong adlen, 134 const(ubyte)* npub, 135 const(crypto_aead_aes256gcm_state)* ctx_); 136 137 int crypto_aead_aes256gcm_encrypt_detached_afternm ( 138 ubyte* c, 139 ubyte* mac, 140 ulong* maclen_p, 141 const(ubyte)* m, 142 ulong mlen, 143 const(ubyte)* ad, 144 ulong adlen, 145 const(ubyte)* nsec, 146 const(ubyte)* npub, 147 const(crypto_aead_aes256gcm_state)* ctx_); 148 149 int crypto_aead_aes256gcm_decrypt_detached_afternm ( 150 ubyte* m, 151 ubyte* nsec, 152 const(ubyte)* c, 153 ulong clen, 154 const(ubyte)* mac, 155 const(ubyte)* ad, 156 ulong adlen, 157 const(ubyte)* npub, 158 const(crypto_aead_aes256gcm_state)* ctx_); 159 160 void crypto_aead_aes256gcm_keygen (ref ubyte[crypto_aead_aes256gcm_KEYBYTES] k);