1 module secured.openssl; 2 3 import deimos.openssl.evp; 4 import core.stdc.stdint; 5 6 private: 7 8 enum int EVP_PKEY_ALG_CTRL = 0x1000; 9 enum int EVP_PKEY_CTRL_HKDF_MD = (EVP_PKEY_ALG_CTRL + 3); 10 enum int EVP_PKEY_CTRL_HKDF_SALT = (EVP_PKEY_ALG_CTRL + 4); 11 enum int EVP_PKEY_CTRL_HKDF_KEY = (EVP_PKEY_ALG_CTRL + 5); 12 enum int EVP_PKEY_CTRL_HKDF_INFO = (EVP_PKEY_ALG_CTRL + 6); 13 enum int EVP_PKEY_CTRL_HKDF_MODE = (EVP_PKEY_ALG_CTRL + 7); 14 enum int EVP_PKEY_CTRL_PASS = (EVP_PKEY_ALG_CTRL + 8); 15 enum int EVP_PKEY_CTRL_SCRYPT_SALT = (EVP_PKEY_ALG_CTRL + 9); 16 enum int EVP_PKEY_CTRL_SCRYPT_N = (EVP_PKEY_ALG_CTRL + 10); 17 enum int EVP_PKEY_CTRL_SCRYPT_R = (EVP_PKEY_ALG_CTRL + 11); 18 enum int EVP_PKEY_CTRL_SCRYPT_P = (EVP_PKEY_ALG_CTRL + 12); 19 enum int EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES = (EVP_PKEY_ALG_CTRL + 13); 20 21 extern (C): 22 nothrow: 23 public: 24 25 ulong ERR_get_error(); 26 ulong ERR_peek_error(); 27 void ERR_error_string_n(ulong e, char *buf, size_t len); 28 29 EVP_MD_CTX* EVP_MD_CTX_new(); 30 void EVP_MD_CTX_free(EVP_MD_CTX* free); 31 void EVP_MD_CIPHER_free(EVP_CIPHER_CTX* free); 32 int EVP_PBE_scrypt(const char *pass, size_t passlen, const ubyte *salt, size_t saltlen, ulong N, ulong r, ulong p, ulong maxmem, ubyte *key, size_t keylen); 33 34 const(EVP_CIPHER)* EVP_chacha20(); 35 const(EVP_CIPHER)* EVP_chacha20_poly1305(); 36 37 extern(D): 38 39 enum int EVP_PKEY_HKDF = 1036; 40 enum int EVP_PKEY_SCRYPT = 973; 41 enum int EVP_CTRL_AEAD_SET_IVLEN = 0x9; 42 enum int EVP_CTRL_AEAD_GET_TAG = 0x10; 43 enum int EVP_CTRL_AEAD_SET_TAG = 0x11; 44 45 int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *pctx, const EVP_MD *md) { 46 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_MD, 0, cast(void *)(md)); 47 } 48 49 int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *pctx, const ubyte[] salt) { 50 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_SALT, cast(int)salt.length, cast(void *)salt.ptr); 51 } 52 53 int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *pctx, const ubyte[] key) { 54 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_KEY, cast(int)key.length, cast(void *)key.ptr); 55 } 56 57 int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *pctx, string info) { 58 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_INFO, cast(int)(cast(ubyte[])info).length, cast(void *)info); 59 } 60 61 int EVP_PKEY_CTX_set1_pbe_pass(EVP_PKEY_CTX *pctx, const ubyte[] password) { 62 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_PASS, cast(int)password.length, cast(void *)(password)); 63 } 64 65 int EVP_PKEY_CTX_set1_scrypt_salt(EVP_PKEY_CTX *pctx, const ubyte[] salt) { 66 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_SALT, cast(int)salt.length, cast(void *)(salt)); 67 } 68 69 int EVP_PKEY_CTX_set_scrypt_N(EVP_PKEY_CTX *pctx, ulong n) { 70 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_N, 0, cast(void*)n); 71 } 72 73 int EVP_PKEY_CTX_set_scrypt_r(EVP_PKEY_CTX *pctx, ulong r) { 74 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_R, 0, cast(void*)r); 75 } 76 77 int EVP_PKEY_CTX_set_scrypt_p(EVP_PKEY_CTX *pctx, ulong p) { 78 return EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_SCRYPT_P, 0, cast(void*)p); 79 }