diff options
author | Christian Heimes <christian@python.org> | 2016-09-06 18:22:28 (GMT) |
---|---|---|
committer | Christian Heimes <christian@python.org> | 2016-09-06 18:22:28 (GMT) |
commit | 39093e9e6836b98dc67979e4e888e4bc639caa07 (patch) | |
tree | c5be5c5ad31e520580ca9f30d019c47cebb66886 /Modules/clinic/_hashopenssl.c.h | |
parent | ac041c0aa721e2672dfb684562b08ad5465b76b1 (diff) | |
download | cpython-39093e9e6836b98dc67979e4e888e4bc639caa07.zip cpython-39093e9e6836b98dc67979e4e888e4bc639caa07.tar.gz cpython-39093e9e6836b98dc67979e4e888e4bc639caa07.tar.bz2 |
Issue #27928: Add scrypt (password-based key derivation function) to hashlib module (requires OpenSSL 1.1.0).
Diffstat (limited to 'Modules/clinic/_hashopenssl.c.h')
-rw-r--r-- | Modules/clinic/_hashopenssl.c.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h new file mode 100644 index 0000000..96e6cfe --- /dev/null +++ b/Modules/clinic/_hashopenssl.c.h @@ -0,0 +1,60 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +#if (OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)) + +PyDoc_STRVAR(_hashlib_scrypt__doc__, +"scrypt($module, /, password, *, salt=None, n=None, r=None, p=None,\n" +" maxmem=0, dklen=64)\n" +"--\n" +"\n" +"scrypt password-based key derivation function."); + +#define _HASHLIB_SCRYPT_METHODDEF \ + {"scrypt", (PyCFunction)_hashlib_scrypt, METH_VARARGS|METH_KEYWORDS, _hashlib_scrypt__doc__}, + +static PyObject * +_hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt, + PyObject *n_obj, PyObject *r_obj, PyObject *p_obj, + long maxmem, long dklen); + +static PyObject * +_hashlib_scrypt(PyObject *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"password", "salt", "n", "r", "p", "maxmem", "dklen", NULL}; + static _PyArg_Parser _parser = {"y*|$y*O!O!O!ll:scrypt", _keywords, 0}; + Py_buffer password = {NULL, NULL}; + Py_buffer salt = {NULL, NULL}; + PyObject *n_obj = Py_None; + PyObject *r_obj = Py_None; + PyObject *p_obj = Py_None; + long maxmem = 0; + long dklen = 64; + + if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, + &password, &salt, &PyLong_Type, &n_obj, &PyLong_Type, &r_obj, &PyLong_Type, &p_obj, &maxmem, &dklen)) { + goto exit; + } + return_value = _hashlib_scrypt_impl(module, &password, &salt, n_obj, r_obj, p_obj, maxmem, dklen); + +exit: + /* Cleanup for password */ + if (password.obj) { + PyBuffer_Release(&password); + } + /* Cleanup for salt */ + if (salt.obj) { + PyBuffer_Release(&salt); + } + + return return_value; +} + +#endif /* (OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER)) */ + +#ifndef _HASHLIB_SCRYPT_METHODDEF + #define _HASHLIB_SCRYPT_METHODDEF +#endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */ +/*[clinic end generated code: output=8c5386789f77430a input=a9049054013a1b77]*/ |