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_aead_chacha20poly1305_H 5 */ 6 7 module deimos.sodium.crypto_aead_chacha20poly1305; 8 9 import deimos.sodium.export_; 10 11 12 extern(C) @nogc : 13 14 15 /* -- IETF ChaCha20-Poly1305 construction with a 96-bit nonce and a 32-bit internal counter -- */ 16 17 enum crypto_aead_chacha20poly1305_ietf_KEYBYTES = 32U; 18 19 size_t crypto_aead_chacha20poly1305_ietf_keybytes() pure @trusted; 20 21 enum crypto_aead_chacha20poly1305_ietf_NSECBYTES = 0U; 22 23 size_t crypto_aead_chacha20poly1305_ietf_nsecbytes() pure @trusted; 24 25 enum crypto_aead_chacha20poly1305_ietf_NPUBBYTES = 12U; 26 27 size_t crypto_aead_chacha20poly1305_ietf_npubbytes() pure @trusted; 28 29 enum crypto_aead_chacha20poly1305_ietf_ABYTES = 16U; 30 31 size_t crypto_aead_chacha20poly1305_ietf_abytes() pure @trusted; 32 33 version(bin_v1_0_16) 34 enum crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX = 35 SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ietf_ABYTES, 36 (64UL * (1UL << 32) - 64UL) - crypto_aead_chacha20poly1305_ietf_ABYTES); 37 else 38 enum crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX = 39 SODIUM_MIN(SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ietf_ABYTES, 40 (64UL * ((1UL << 32) - 1UL))); 41 42 size_t crypto_aead_chacha20poly1305_ietf_messagebytes_max() pure @trusted; 43 44 int crypto_aead_chacha20poly1305_ietf_encrypt(ubyte* c, 45 ulong* clen_p, 46 const(ubyte)* m, 47 ulong mlen, 48 const(ubyte)* ad, 49 ulong adlen, 50 const(ubyte)* nsec, 51 const(ubyte)* npub, 52 const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 8, 9))); 53 54 int crypto_aead_chacha20poly1305_ietf_decrypt(ubyte* m, 55 ulong* mlen_p, 56 ubyte* nsec, 57 const(ubyte)* c, 58 ulong clen, 59 const(ubyte)* ad, 60 ulong adlen, 61 const(ubyte)* npub, 62 const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9))); 63 64 int crypto_aead_chacha20poly1305_ietf_encrypt_detached(ubyte* c, 65 ubyte* mac, 66 ulong* maclen_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) pure; // __attribute__ ((nonnull(1, 2, 9, 10))); 74 75 int crypto_aead_chacha20poly1305_ietf_decrypt_detached(ubyte* m, 76 ubyte* nsec, 77 const(ubyte)* c, 78 ulong clen, 79 const(ubyte)* mac, 80 const(ubyte)* ad, 81 ulong adlen, 82 const(ubyte)* npub, 83 const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9))); 84 85 void crypto_aead_chacha20poly1305_ietf_keygen(ref ubyte[crypto_aead_chacha20poly1305_ietf_KEYBYTES] k) nothrow @trusted; // __attribute__ ((nonnull)); 86 87 /* -- Original ChaCha20-Poly1305 construction with a 64-bit nonce and a 64-bit internal counter -- */ 88 89 enum crypto_aead_chacha20poly1305_KEYBYTES = 32U; 90 91 size_t crypto_aead_chacha20poly1305_keybytes() pure @trusted; 92 93 enum crypto_aead_chacha20poly1305_NSECBYTES = 0U; 94 95 size_t crypto_aead_chacha20poly1305_nsecbytes() pure @trusted; 96 97 enum crypto_aead_chacha20poly1305_NPUBBYTES = 8U; 98 99 size_t crypto_aead_chacha20poly1305_npubbytes() pure @trusted; 100 101 enum crypto_aead_chacha20poly1305_ABYTES = 16U; 102 103 size_t crypto_aead_chacha20poly1305_abytes() pure @trusted; 104 105 enum crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX = 106 (SODIUM_SIZE_MAX - crypto_aead_chacha20poly1305_ABYTES); 107 108 size_t crypto_aead_chacha20poly1305_messagebytes_max() pure @trusted; 109 110 int crypto_aead_chacha20poly1305_encrypt(ubyte* c, 111 ulong* clen_p, 112 const(ubyte)* m, 113 ulong mlen, 114 const(ubyte)* ad, 115 ulong adlen, 116 const(ubyte)* nsec, 117 const(ubyte)* npub, 118 const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 8, 9))); 119 120 int crypto_aead_chacha20poly1305_decrypt(ubyte* m, 121 ulong* mlen_p, 122 ubyte* nsec, 123 const(ubyte)* c, 124 ulong clen, 125 const(ubyte)* ad, 126 ulong adlen, 127 const(ubyte)* npub, 128 const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(4, 8, 9))); 129 130 int crypto_aead_chacha20poly1305_encrypt_detached(ubyte* c, 131 ubyte* mac, 132 ulong* maclen_p, 133 const(ubyte)* m, 134 ulong mlen, 135 const(ubyte)* ad, 136 ulong adlen, 137 const(ubyte)* nsec, 138 const(ubyte)* npub, 139 const(ubyte)* k) pure; // __attribute__ ((nonnull(1, 2, 9, 10))); 140 141 int crypto_aead_chacha20poly1305_decrypt_detached(ubyte* m, 142 ubyte* nsec, 143 const(ubyte)* c, 144 ulong clen, 145 const(ubyte)* mac, 146 const(ubyte)* ad, 147 ulong adlen, 148 const(ubyte)* npub, 149 const(ubyte)* k) pure nothrow; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9))); 150 151 void crypto_aead_chacha20poly1305_keygen(ref ubyte[crypto_aead_chacha20poly1305_KEYBYTES] k) nothrow @trusted; // __attribute__ ((nonnull)); 152 153 /* Aliases */ 154 155 alias crypto_aead_chacha20poly1305_IETF_KEYBYTES = crypto_aead_chacha20poly1305_ietf_KEYBYTES; 156 alias crypto_aead_chacha20poly1305_IETF_NSECBYTES = crypto_aead_chacha20poly1305_ietf_NSECBYTES; 157 alias crypto_aead_chacha20poly1305_IETF_NPUBBYTES = crypto_aead_chacha20poly1305_ietf_NPUBBYTES; 158 alias crypto_aead_chacha20poly1305_IETF_ABYTES = crypto_aead_chacha20poly1305_ietf_ABYTES; 159 alias crypto_aead_chacha20poly1305_IETF_MESSAGEBYTES_MAX = crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX;