mirror of
https://github.com/python/cpython.git
synced 2025-07-07 11:25:30 +00:00
gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (#134713)
OpenSSL and HACL*-based hash functions constructors now support both `data` and `string` parameters. Previously these constructor functions inconsistently supported sometimes `data` and sometimes `string`, while the documentation expected `data` to be given in all cases.
This commit is contained in:
parent
4d31d19a1d
commit
c6e63d9d35
16 changed files with 830 additions and 421 deletions
|
@ -141,29 +141,29 @@ def __get_openssl_constructor(name):
|
|||
return __get_builtin_constructor(name)
|
||||
|
||||
|
||||
def __py_new(name, data=b'', **kwargs):
|
||||
def __py_new(name, *args, **kwargs):
|
||||
"""new(name, data=b'', **kwargs) - Return a new hashing object using the
|
||||
named algorithm; optionally initialized with data (which must be
|
||||
a bytes-like object).
|
||||
"""
|
||||
return __get_builtin_constructor(name)(data, **kwargs)
|
||||
return __get_builtin_constructor(name)(*args, **kwargs)
|
||||
|
||||
|
||||
def __hash_new(name, data=b'', **kwargs):
|
||||
def __hash_new(name, *args, **kwargs):
|
||||
"""new(name, data=b'') - Return a new hashing object using the named algorithm;
|
||||
optionally initialized with data (which must be a bytes-like object).
|
||||
"""
|
||||
if name in __block_openssl_constructor:
|
||||
# Prefer our builtin blake2 implementation.
|
||||
return __get_builtin_constructor(name)(data, **kwargs)
|
||||
return __get_builtin_constructor(name)(*args, **kwargs)
|
||||
try:
|
||||
return _hashlib.new(name, data, **kwargs)
|
||||
return _hashlib.new(name, *args, **kwargs)
|
||||
except ValueError:
|
||||
# If the _hashlib module (OpenSSL) doesn't support the named
|
||||
# hash, try using our builtin implementations.
|
||||
# This allows for SHA224/256 and SHA384/512 support even though
|
||||
# the OpenSSL library prior to 0.9.8 doesn't provide them.
|
||||
return __get_builtin_constructor(name)(data)
|
||||
return __get_builtin_constructor(name)(*args, **kwargs)
|
||||
|
||||
|
||||
try:
|
||||
|
|
|
@ -12,6 +12,7 @@ import io
|
|||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import sysconfig
|
||||
import tempfile
|
||||
|
@ -140,11 +141,10 @@ class HashLibTestCase(unittest.TestCase):
|
|||
# of hashlib.new given the algorithm name.
|
||||
for algorithm, constructors in self.constructors_to_test.items():
|
||||
constructors.add(getattr(hashlib, algorithm))
|
||||
def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm, **kwargs):
|
||||
if data is None:
|
||||
return hashlib.new(_alg, **kwargs)
|
||||
return hashlib.new(_alg, data, **kwargs)
|
||||
constructors.add(_test_algorithm_via_hashlib_new)
|
||||
def c(*args, __algorithm_name=algorithm, **kwargs):
|
||||
return hashlib.new(__algorithm_name, *args, **kwargs)
|
||||
c.__name__ = f'do_test_algorithm_via_hashlib_new_{algorithm}'
|
||||
constructors.add(c)
|
||||
|
||||
_hashlib = self._conditional_import_module('_hashlib')
|
||||
self._hashlib = _hashlib
|
||||
|
@ -249,6 +249,56 @@ class HashLibTestCase(unittest.TestCase):
|
|||
self._hashlib.new("md5", usedforsecurity=False)
|
||||
self._hashlib.openssl_md5(usedforsecurity=False)
|
||||
|
||||
def test_clinic_signature(self):
|
||||
for constructor in self.hash_constructors:
|
||||
with self.subTest(constructor.__name__):
|
||||
constructor(b'')
|
||||
constructor(data=b'')
|
||||
constructor(string=b'') # should be deprecated in the future
|
||||
|
||||
def test_clinic_signature_errors(self):
|
||||
nomsg = b''
|
||||
mymsg = b'msg'
|
||||
conflicting_call = re.escape(
|
||||
"'data' and 'string' are mutually exclusive "
|
||||
"and support for 'string' keyword parameter "
|
||||
"is slated for removal in a future version."
|
||||
)
|
||||
duplicated_param = re.escape("given by name ('data') and position")
|
||||
unexpected_param = re.escape("got an unexpected keyword argument '_'")
|
||||
for args, kwds, errmsg in [
|
||||
# Reject duplicated arguments before unknown keyword arguments.
|
||||
((nomsg,), dict(data=nomsg, _=nomsg), duplicated_param),
|
||||
((mymsg,), dict(data=nomsg, _=nomsg), duplicated_param),
|
||||
# Reject duplicated arguments before conflicting ones.
|
||||
*itertools.product(
|
||||
[[nomsg], [mymsg]],
|
||||
[dict(data=nomsg), dict(data=nomsg, string=nomsg)],
|
||||
[duplicated_param]
|
||||
),
|
||||
# Reject unknown keyword arguments before conflicting ones.
|
||||
*itertools.product(
|
||||
[()],
|
||||
[
|
||||
dict(_=None),
|
||||
dict(data=nomsg, _=None),
|
||||
dict(string=nomsg, _=None),
|
||||
dict(string=nomsg, data=nomsg, _=None),
|
||||
],
|
||||
[unexpected_param]
|
||||
),
|
||||
((nomsg,), dict(_=None), unexpected_param),
|
||||
((mymsg,), dict(_=None), unexpected_param),
|
||||
# Reject conflicting arguments.
|
||||
[(nomsg,), dict(string=nomsg), conflicting_call],
|
||||
[(mymsg,), dict(string=nomsg), conflicting_call],
|
||||
[(), dict(data=nomsg, string=nomsg), conflicting_call],
|
||||
]:
|
||||
for constructor in self.hash_constructors:
|
||||
with self.subTest(constructor.__name__, args=args, kwds=kwds):
|
||||
with self.assertRaisesRegex(TypeError, errmsg):
|
||||
constructor(*args, **kwds)
|
||||
|
||||
def test_unknown_hash(self):
|
||||
self.assertRaises(ValueError, hashlib.new, 'spam spam spam spam spam')
|
||||
self.assertRaises(TypeError, hashlib.new, 1)
|
||||
|
@ -718,8 +768,6 @@ class HashLibTestCase(unittest.TestCase):
|
|||
self.assertRaises(ValueError, constructor, node_offset=-1)
|
||||
self.assertRaises(OverflowError, constructor, node_offset=max_offset+1)
|
||||
|
||||
self.assertRaises(TypeError, constructor, data=b'')
|
||||
self.assertRaises(TypeError, constructor, string=b'')
|
||||
self.assertRaises(TypeError, constructor, '')
|
||||
|
||||
constructor(
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Built-in HACL* and OpenSSL implementations of hash function constructors
|
||||
now correctly accept the same *documented* named arguments. For instance,
|
||||
:func:`~hashlib.md5` could be previously invoked as ``md5(data=data)``
|
||||
or ``md5(string=string)`` depending on the underlying implementation
|
||||
but these calls were not compatible. Patch by Bénédikt Tran.
|
|
@ -1039,6 +1039,14 @@ exit:
|
|||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
#define CALL_HASHLIB_NEW(MODULE, NAME, DATA, STRING, USEDFORSECURITY) \
|
||||
do { \
|
||||
PyObject *data_obj; \
|
||||
if (_Py_hashlib_data_argument(&data_obj, DATA, STRING) < 0) { \
|
||||
return NULL; \
|
||||
} \
|
||||
return _hashlib_HASH(MODULE, NAME, data_obj, USEDFORSECURITY); \
|
||||
} while (0)
|
||||
|
||||
/* The module-level function: new() */
|
||||
|
||||
|
@ -1046,9 +1054,10 @@ exit:
|
|||
_hashlib.new as _hashlib_HASH_new
|
||||
|
||||
name: str
|
||||
string as data_obj: object(c_default="NULL") = b''
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Return a new hash object using the named algorithm.
|
||||
|
||||
|
@ -1059,131 +1068,137 @@ The MD5 and SHA1 algorithms are always supported.
|
|||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_HASH_new_impl(PyObject *module, const char *name,
|
||||
PyObject *data_obj, int usedforsecurity)
|
||||
/*[clinic end generated code: output=30c6e7b9a5a4dce3 input=28848db5ccd0a9b5]*/
|
||||
_hashlib_HASH_new_impl(PyObject *module, const char *name, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=b905aaf9840c1bbd input=c34af6c6e696d44e]*/
|
||||
{
|
||||
return _hashlib_HASH(module, name, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, name, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_md5
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a md5 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_md5_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=87b0186440a44f8c input=990e36d5e689b16e]*/
|
||||
_hashlib_openssl_md5_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=ca8cf184d90f7432 input=e7c0adbd6a867db1]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_md5, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_md5, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha1
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha1 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha1_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=6813024cf690670d input=948f2f4b6deabc10]*/
|
||||
_hashlib_openssl_sha1_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=1736fb7b310d64be input=f7e5bb1711e952d8]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha1, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha1, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha224
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha224 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha224_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=a2dfe7cc4eb14ebb input=f9272821fadca505]*/
|
||||
_hashlib_openssl_sha224_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=0d6ff57be5e5c140 input=3820fff7ed3a53b8]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha224, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha224, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha256
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha256 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha256_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=1f874a34870f0a68 input=549fad9d2930d4c5]*/
|
||||
_hashlib_openssl_sha256_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=412ea7111555b6e7 input=9a2f115cf1f7e0eb]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha256, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha256, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha384
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha384 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha384_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=58529eff9ca457b2 input=48601a6e3bf14ad7]*/
|
||||
_hashlib_openssl_sha384_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=2e0dc395b59ed726 input=1ea48f6f01e77cfb]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha384, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha384, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha512
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha512 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha512_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=2c744c9e4a40d5f6 input=c5c46a2a817aa98f]*/
|
||||
_hashlib_openssl_sha512_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=4bdd760388dbfc0f input=3cf56903e07d1f5c]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha512, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha512, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1192,77 +1207,81 @@ _hashlib_openssl_sha512_impl(PyObject *module, PyObject *data_obj,
|
|||
/*[clinic input]
|
||||
_hashlib.openssl_sha3_224
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha3-224 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha3_224_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=144641c1d144b974 input=e3a01b2888916157]*/
|
||||
_hashlib_openssl_sha3_224_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=6d8dc2a924f3ba35 input=7f14f16a9f6a3158]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha3_224, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha3_224, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha3_256
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha3-256 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha3_256_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=c61f1ab772d06668 input=e2908126c1b6deed]*/
|
||||
_hashlib_openssl_sha3_256_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=9e520f537b3a4622 input=7987150939d5e352]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha3_256, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha3_256, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha3_384
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha3-384 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha3_384_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=f68e4846858cf0ee input=ec0edf5c792f8252]*/
|
||||
_hashlib_openssl_sha3_384_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=d239ba0463fd6138 input=fc943401f67e3b81]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha3_384, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha3_384, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_sha3_512
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a sha3-512 hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_sha3_512_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=2eede478c159354a input=64e2cc0c094d56f4]*/
|
||||
_hashlib_openssl_sha3_512_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=17662f21038c2278 input=6601ddd2c6c1516d]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_sha3_512, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_sha3_512, data, string, usedforsecurity);
|
||||
}
|
||||
#endif /* PY_OPENSSL_HAS_SHA3 */
|
||||
|
||||
|
@ -1270,42 +1289,46 @@ _hashlib_openssl_sha3_512_impl(PyObject *module, PyObject *data_obj,
|
|||
/*[clinic input]
|
||||
_hashlib.openssl_shake_128
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a shake-128 variable hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_shake_128_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=bc49cdd8ada1fa97 input=6c9d67440eb33ec8]*/
|
||||
_hashlib_openssl_shake_128_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=4e6afed8d18980ad input=373c3f1c93d87b37]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_shake_128, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_shake_128, data, string, usedforsecurity);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.openssl_shake_256
|
||||
|
||||
string as data_obj: object(py_default="b''") = NULL
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Returns a shake-256 variable hash object; optionally initialized with a string
|
||||
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_hashlib_openssl_shake_256_impl(PyObject *module, PyObject *data_obj,
|
||||
int usedforsecurity)
|
||||
/*[clinic end generated code: output=358d213be8852df7 input=479cbe9fefd4a9f8]*/
|
||||
_hashlib_openssl_shake_256_impl(PyObject *module, PyObject *data,
|
||||
int usedforsecurity, PyObject *string)
|
||||
/*[clinic end generated code: output=62481bce4a77d16c input=101c139ea2ddfcbf]*/
|
||||
{
|
||||
return _hashlib_HASH(module, Py_hash_shake_256, data_obj, usedforsecurity);
|
||||
CALL_HASHLIB_NEW(module, Py_hash_shake_256, data, string, usedforsecurity);
|
||||
}
|
||||
#endif /* PY_OPENSSL_HAS_SHAKE */
|
||||
|
||||
#undef CALL_HASHLIB_NEW
|
||||
|
||||
/*[clinic input]
|
||||
_hashlib.pbkdf2_hmac as pbkdf2_hmac
|
||||
|
||||
|
|
|
@ -655,8 +655,7 @@ error:
|
|||
/*[clinic input]
|
||||
@classmethod
|
||||
_blake2.blake2b.__new__ as py_blake2b_new
|
||||
data: object(c_default="NULL") = b''
|
||||
/
|
||||
data as data_obj: object(c_default="NULL") = b''
|
||||
*
|
||||
digest_size: int(c_default="HACL_HASH_BLAKE2B_OUT_BYTES") = _blake2.blake2b.MAX_DIGEST_SIZE
|
||||
key: Py_buffer(c_default="NULL", py_default="b''") = None
|
||||
|
@ -670,26 +669,31 @@ _blake2.blake2b.__new__ as py_blake2b_new
|
|||
inner_size: int = 0
|
||||
last_node: bool = False
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Return a new BLAKE2b hash object.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
|
||||
py_blake2b_new_impl(PyTypeObject *type, PyObject *data_obj, int digest_size,
|
||||
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
|
||||
int fanout, int depth, unsigned long leaf_size,
|
||||
unsigned long long node_offset, int node_depth,
|
||||
int inner_size, int last_node, int usedforsecurity)
|
||||
/*[clinic end generated code: output=32bfd8f043c6896f input=8fee2b7b11428b2d]*/
|
||||
int inner_size, int last_node, int usedforsecurity,
|
||||
PyObject *string)
|
||||
/*[clinic end generated code: output=de64bd850606b6a0 input=78cf60a2922d2f90]*/
|
||||
{
|
||||
PyObject *data;
|
||||
if (_Py_hashlib_data_argument(&data, data_obj, string) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return py_blake2b_or_s_new(type, data, digest_size, key, salt, person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
@classmethod
|
||||
_blake2.blake2s.__new__ as py_blake2s_new
|
||||
data: object(c_default="NULL") = b''
|
||||
/
|
||||
data as data_obj: object(c_default="NULL") = b''
|
||||
*
|
||||
digest_size: int(c_default="HACL_HASH_BLAKE2S_OUT_BYTES") = _blake2.blake2s.MAX_DIGEST_SIZE
|
||||
key: Py_buffer(c_default="NULL", py_default="b''") = None
|
||||
|
@ -703,18 +707,24 @@ _blake2.blake2s.__new__ as py_blake2s_new
|
|||
inner_size: int = 0
|
||||
last_node: bool = False
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Return a new BLAKE2s hash object.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
|
||||
py_blake2s_new_impl(PyTypeObject *type, PyObject *data_obj, int digest_size,
|
||||
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
|
||||
int fanout, int depth, unsigned long leaf_size,
|
||||
unsigned long long node_offset, int node_depth,
|
||||
int inner_size, int last_node, int usedforsecurity)
|
||||
/*[clinic end generated code: output=556181f73905c686 input=8165a11980eac7f3]*/
|
||||
int inner_size, int last_node, int usedforsecurity,
|
||||
PyObject *string)
|
||||
/*[clinic end generated code: output=582a0c4295cc3a3c input=6843d6332eefd295]*/
|
||||
{
|
||||
PyObject *data;
|
||||
if (_Py_hashlib_data_argument(&data, data_obj, string) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return py_blake2b_or_s_new(type, data, digest_size, key, salt, person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity);
|
||||
}
|
||||
|
||||
|
|
441
Modules/clinic/_hashopenssl.c.h
generated
441
Modules/clinic/_hashopenssl.c.h
generated
File diff suppressed because it is too large
Load diff
98
Modules/clinic/blake2module.c.h
generated
98
Modules/clinic/blake2module.c.h
generated
|
@ -10,20 +10,21 @@ preserve
|
|||
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
|
||||
|
||||
PyDoc_STRVAR(py_blake2b_new__doc__,
|
||||
"blake2b(data=b\'\', /, *, digest_size=_blake2.blake2b.MAX_DIGEST_SIZE,\n"
|
||||
"blake2b(data=b\'\', *, digest_size=_blake2.blake2b.MAX_DIGEST_SIZE,\n"
|
||||
" key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n"
|
||||
" node_offset=0, node_depth=0, inner_size=0, last_node=False,\n"
|
||||
" usedforsecurity=True)\n"
|
||||
" usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new BLAKE2b hash object.");
|
||||
|
||||
static PyObject *
|
||||
py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
|
||||
py_blake2b_new_impl(PyTypeObject *type, PyObject *data_obj, int digest_size,
|
||||
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
|
||||
int fanout, int depth, unsigned long leaf_size,
|
||||
unsigned long long node_offset, int node_depth,
|
||||
int inner_size, int last_node, int usedforsecurity);
|
||||
int inner_size, int last_node, int usedforsecurity,
|
||||
PyObject *string);
|
||||
|
||||
static PyObject *
|
||||
py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
|
@ -31,7 +32,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 12
|
||||
#define NUM_KEYWORDS 14
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -40,7 +41,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(digest_size), &_Py_ID(key), &_Py_ID(salt), &_Py_ID(person), &_Py_ID(fanout), &_Py_ID(depth), &_Py_ID(leaf_size), &_Py_ID(node_offset), &_Py_ID(node_depth), &_Py_ID(inner_size), &_Py_ID(last_node), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(digest_size), &_Py_ID(key), &_Py_ID(salt), &_Py_ID(person), &_Py_ID(fanout), &_Py_ID(depth), &_Py_ID(leaf_size), &_Py_ID(node_offset), &_Py_ID(node_depth), &_Py_ID(inner_size), &_Py_ID(last_node), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -49,18 +50,18 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "blake2b",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[13];
|
||||
PyObject *argsbuf[14];
|
||||
PyObject * const *fastargs;
|
||||
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
||||
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
|
||||
PyObject *data = NULL;
|
||||
PyObject *data_obj = NULL;
|
||||
int digest_size = HACL_HASH_BLAKE2B_OUT_BYTES;
|
||||
Py_buffer key = {NULL, NULL};
|
||||
Py_buffer salt = {NULL, NULL};
|
||||
|
@ -73,18 +74,23 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
int inner_size = 0;
|
||||
int last_node = 0;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string = NULL;
|
||||
|
||||
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
if (!fastargs) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional_posonly;
|
||||
if (!noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
noptargs--;
|
||||
data = fastargs[0];
|
||||
skip_optional_posonly:
|
||||
if (fastargs[0]) {
|
||||
data_obj = fastargs[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
}
|
||||
skip_optional_pos:
|
||||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
|
@ -182,12 +188,18 @@ skip_optional_posonly:
|
|||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(fastargs[12]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (fastargs[12]) {
|
||||
usedforsecurity = PyObject_IsTrue(fastargs[12]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string = fastargs[13];
|
||||
skip_optional_kwonly:
|
||||
return_value = py_blake2b_new_impl(type, data, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity);
|
||||
return_value = py_blake2b_new_impl(type, data_obj, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity, string);
|
||||
|
||||
exit:
|
||||
/* Cleanup for key */
|
||||
|
@ -207,20 +219,21 @@ exit:
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(py_blake2s_new__doc__,
|
||||
"blake2s(data=b\'\', /, *, digest_size=_blake2.blake2s.MAX_DIGEST_SIZE,\n"
|
||||
"blake2s(data=b\'\', *, digest_size=_blake2.blake2s.MAX_DIGEST_SIZE,\n"
|
||||
" key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n"
|
||||
" node_offset=0, node_depth=0, inner_size=0, last_node=False,\n"
|
||||
" usedforsecurity=True)\n"
|
||||
" usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new BLAKE2s hash object.");
|
||||
|
||||
static PyObject *
|
||||
py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
|
||||
py_blake2s_new_impl(PyTypeObject *type, PyObject *data_obj, int digest_size,
|
||||
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
|
||||
int fanout, int depth, unsigned long leaf_size,
|
||||
unsigned long long node_offset, int node_depth,
|
||||
int inner_size, int last_node, int usedforsecurity);
|
||||
int inner_size, int last_node, int usedforsecurity,
|
||||
PyObject *string);
|
||||
|
||||
static PyObject *
|
||||
py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
|
@ -228,7 +241,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 12
|
||||
#define NUM_KEYWORDS 14
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -237,7 +250,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(digest_size), &_Py_ID(key), &_Py_ID(salt), &_Py_ID(person), &_Py_ID(fanout), &_Py_ID(depth), &_Py_ID(leaf_size), &_Py_ID(node_offset), &_Py_ID(node_depth), &_Py_ID(inner_size), &_Py_ID(last_node), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(digest_size), &_Py_ID(key), &_Py_ID(salt), &_Py_ID(person), &_Py_ID(fanout), &_Py_ID(depth), &_Py_ID(leaf_size), &_Py_ID(node_offset), &_Py_ID(node_depth), &_Py_ID(inner_size), &_Py_ID(last_node), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -246,18 +259,18 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "blake2s",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[13];
|
||||
PyObject *argsbuf[14];
|
||||
PyObject * const *fastargs;
|
||||
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
||||
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
|
||||
PyObject *data = NULL;
|
||||
PyObject *data_obj = NULL;
|
||||
int digest_size = HACL_HASH_BLAKE2S_OUT_BYTES;
|
||||
Py_buffer key = {NULL, NULL};
|
||||
Py_buffer salt = {NULL, NULL};
|
||||
|
@ -270,18 +283,23 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
int inner_size = 0;
|
||||
int last_node = 0;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string = NULL;
|
||||
|
||||
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
if (!fastargs) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional_posonly;
|
||||
if (!noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
noptargs--;
|
||||
data = fastargs[0];
|
||||
skip_optional_posonly:
|
||||
if (fastargs[0]) {
|
||||
data_obj = fastargs[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
}
|
||||
skip_optional_pos:
|
||||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
|
@ -379,12 +397,18 @@ skip_optional_posonly:
|
|||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(fastargs[12]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (fastargs[12]) {
|
||||
usedforsecurity = PyObject_IsTrue(fastargs[12]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string = fastargs[13];
|
||||
skip_optional_kwonly:
|
||||
return_value = py_blake2s_new_impl(type, data, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity);
|
||||
return_value = py_blake2s_new_impl(type, data_obj, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity, string);
|
||||
|
||||
exit:
|
||||
/* Cleanup for key */
|
||||
|
@ -478,4 +502,4 @@ _blake2_blake2b_hexdigest(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return _blake2_blake2b_hexdigest_impl((Blake2Object *)self);
|
||||
}
|
||||
/*[clinic end generated code: output=d30e8293bd8e2950 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=eed18dcfaf6f7731 input=a9049054013a1b77]*/
|
||||
|
|
34
Modules/clinic/md5module.c.h
generated
34
Modules/clinic/md5module.c.h
generated
|
@ -89,7 +89,7 @@ MD5Type_update(PyObject *self, PyObject *obj)
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(_md5_md5__doc__,
|
||||
"md5($module, /, string=b\'\', *, usedforsecurity=True)\n"
|
||||
"md5($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new MD5 hash object; optionally initialized with a string.");
|
||||
|
@ -98,7 +98,8 @@ PyDoc_STRVAR(_md5_md5__doc__,
|
|||
{"md5", _PyCFunction_CAST(_md5_md5), METH_FASTCALL|METH_KEYWORDS, _md5_md5__doc__},
|
||||
|
||||
static PyObject *
|
||||
_md5_md5_impl(PyObject *module, PyObject *string, int usedforsecurity);
|
||||
_md5_md5_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj);
|
||||
|
||||
static PyObject *
|
||||
_md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
|
@ -106,7 +107,7 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 2
|
||||
#define NUM_KEYWORDS 3
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -115,7 +116,7 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -124,17 +125,18 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "md5",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *argsbuf[3];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
PyObject *string = NULL;
|
||||
PyObject *data = NULL;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string_obj = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
|
@ -145,7 +147,7 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
|||
goto skip_optional_pos;
|
||||
}
|
||||
if (args[0]) {
|
||||
string = args[0];
|
||||
data = args[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
|
@ -154,14 +156,20 @@ skip_optional_pos:
|
|||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (args[1]) {
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string_obj = args[2];
|
||||
skip_optional_kwonly:
|
||||
return_value = _md5_md5_impl(module, string, usedforsecurity);
|
||||
return_value = _md5_md5_impl(module, data, usedforsecurity, string_obj);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=73f4d2034d9fcc63 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=920fe54b9ed06f92 input=a9049054013a1b77]*/
|
||||
|
|
34
Modules/clinic/sha1module.c.h
generated
34
Modules/clinic/sha1module.c.h
generated
|
@ -89,7 +89,7 @@ SHA1Type_update(PyObject *self, PyObject *obj)
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(_sha1_sha1__doc__,
|
||||
"sha1($module, /, string=b\'\', *, usedforsecurity=True)\n"
|
||||
"sha1($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new SHA1 hash object; optionally initialized with a string.");
|
||||
|
@ -98,7 +98,8 @@ PyDoc_STRVAR(_sha1_sha1__doc__,
|
|||
{"sha1", _PyCFunction_CAST(_sha1_sha1), METH_FASTCALL|METH_KEYWORDS, _sha1_sha1__doc__},
|
||||
|
||||
static PyObject *
|
||||
_sha1_sha1_impl(PyObject *module, PyObject *string, int usedforsecurity);
|
||||
_sha1_sha1_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj);
|
||||
|
||||
static PyObject *
|
||||
_sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
|
@ -106,7 +107,7 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 2
|
||||
#define NUM_KEYWORDS 3
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -115,7 +116,7 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -124,17 +125,18 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "sha1",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *argsbuf[3];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
PyObject *string = NULL;
|
||||
PyObject *data = NULL;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string_obj = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
|
@ -145,7 +147,7 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
|||
goto skip_optional_pos;
|
||||
}
|
||||
if (args[0]) {
|
||||
string = args[0];
|
||||
data = args[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
|
@ -154,14 +156,20 @@ skip_optional_pos:
|
|||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (args[1]) {
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string_obj = args[2];
|
||||
skip_optional_kwonly:
|
||||
return_value = _sha1_sha1_impl(module, string, usedforsecurity);
|
||||
return_value = _sha1_sha1_impl(module, data, usedforsecurity, string_obj);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=06161e87e2d645d4 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=fd5a917404b68c4f input=a9049054013a1b77]*/
|
||||
|
|
130
Modules/clinic/sha2module.c.h
generated
130
Modules/clinic/sha2module.c.h
generated
|
@ -169,7 +169,7 @@ SHA512Type_update(PyObject *self, PyObject *obj)
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(_sha2_sha256__doc__,
|
||||
"sha256($module, /, string=b\'\', *, usedforsecurity=True)\n"
|
||||
"sha256($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new SHA-256 hash object; optionally initialized with a string.");
|
||||
|
@ -178,7 +178,8 @@ PyDoc_STRVAR(_sha2_sha256__doc__,
|
|||
{"sha256", _PyCFunction_CAST(_sha2_sha256), METH_FASTCALL|METH_KEYWORDS, _sha2_sha256__doc__},
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha256_impl(PyObject *module, PyObject *string, int usedforsecurity);
|
||||
_sha2_sha256_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj);
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
|
@ -186,7 +187,7 @@ _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 2
|
||||
#define NUM_KEYWORDS 3
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -195,7 +196,7 @@ _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -204,17 +205,18 @@ _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "sha256",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *argsbuf[3];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
PyObject *string = NULL;
|
||||
PyObject *data = NULL;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string_obj = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
|
@ -225,7 +227,7 @@ _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
goto skip_optional_pos;
|
||||
}
|
||||
if (args[0]) {
|
||||
string = args[0];
|
||||
data = args[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
|
@ -234,19 +236,25 @@ skip_optional_pos:
|
|||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (args[1]) {
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string_obj = args[2];
|
||||
skip_optional_kwonly:
|
||||
return_value = _sha2_sha256_impl(module, string, usedforsecurity);
|
||||
return_value = _sha2_sha256_impl(module, data, usedforsecurity, string_obj);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_sha2_sha224__doc__,
|
||||
"sha224($module, /, string=b\'\', *, usedforsecurity=True)\n"
|
||||
"sha224($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new SHA-224 hash object; optionally initialized with a string.");
|
||||
|
@ -255,7 +263,8 @@ PyDoc_STRVAR(_sha2_sha224__doc__,
|
|||
{"sha224", _PyCFunction_CAST(_sha2_sha224), METH_FASTCALL|METH_KEYWORDS, _sha2_sha224__doc__},
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha224_impl(PyObject *module, PyObject *string, int usedforsecurity);
|
||||
_sha2_sha224_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj);
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
|
@ -263,7 +272,7 @@ _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 2
|
||||
#define NUM_KEYWORDS 3
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -272,7 +281,7 @@ _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -281,17 +290,18 @@ _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "sha224",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *argsbuf[3];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
PyObject *string = NULL;
|
||||
PyObject *data = NULL;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string_obj = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
|
@ -302,7 +312,7 @@ _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
goto skip_optional_pos;
|
||||
}
|
||||
if (args[0]) {
|
||||
string = args[0];
|
||||
data = args[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
|
@ -311,19 +321,25 @@ skip_optional_pos:
|
|||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (args[1]) {
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string_obj = args[2];
|
||||
skip_optional_kwonly:
|
||||
return_value = _sha2_sha224_impl(module, string, usedforsecurity);
|
||||
return_value = _sha2_sha224_impl(module, data, usedforsecurity, string_obj);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_sha2_sha512__doc__,
|
||||
"sha512($module, /, string=b\'\', *, usedforsecurity=True)\n"
|
||||
"sha512($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new SHA-512 hash object; optionally initialized with a string.");
|
||||
|
@ -332,7 +348,8 @@ PyDoc_STRVAR(_sha2_sha512__doc__,
|
|||
{"sha512", _PyCFunction_CAST(_sha2_sha512), METH_FASTCALL|METH_KEYWORDS, _sha2_sha512__doc__},
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha512_impl(PyObject *module, PyObject *string, int usedforsecurity);
|
||||
_sha2_sha512_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj);
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
|
@ -340,7 +357,7 @@ _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 2
|
||||
#define NUM_KEYWORDS 3
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -349,7 +366,7 @@ _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -358,17 +375,18 @@ _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "sha512",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *argsbuf[3];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
PyObject *string = NULL;
|
||||
PyObject *data = NULL;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string_obj = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
|
@ -379,7 +397,7 @@ _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
goto skip_optional_pos;
|
||||
}
|
||||
if (args[0]) {
|
||||
string = args[0];
|
||||
data = args[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
|
@ -388,19 +406,25 @@ skip_optional_pos:
|
|||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (args[1]) {
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string_obj = args[2];
|
||||
skip_optional_kwonly:
|
||||
return_value = _sha2_sha512_impl(module, string, usedforsecurity);
|
||||
return_value = _sha2_sha512_impl(module, data, usedforsecurity, string_obj);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_sha2_sha384__doc__,
|
||||
"sha384($module, /, string=b\'\', *, usedforsecurity=True)\n"
|
||||
"sha384($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new SHA-384 hash object; optionally initialized with a string.");
|
||||
|
@ -409,7 +433,8 @@ PyDoc_STRVAR(_sha2_sha384__doc__,
|
|||
{"sha384", _PyCFunction_CAST(_sha2_sha384), METH_FASTCALL|METH_KEYWORDS, _sha2_sha384__doc__},
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha384_impl(PyObject *module, PyObject *string, int usedforsecurity);
|
||||
_sha2_sha384_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj);
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
|
@ -417,7 +442,7 @@ _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 2
|
||||
#define NUM_KEYWORDS 3
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -426,7 +451,7 @@ _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -435,17 +460,18 @@ _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "sha384",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *argsbuf[3];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
PyObject *string = NULL;
|
||||
PyObject *data = NULL;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string_obj = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
|
@ -456,7 +482,7 @@ _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
|||
goto skip_optional_pos;
|
||||
}
|
||||
if (args[0]) {
|
||||
string = args[0];
|
||||
data = args[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
|
@ -465,14 +491,20 @@ skip_optional_pos:
|
|||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (args[1]) {
|
||||
usedforsecurity = PyObject_IsTrue(args[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string_obj = args[2];
|
||||
skip_optional_kwonly:
|
||||
return_value = _sha2_sha384_impl(module, string, usedforsecurity);
|
||||
return_value = _sha2_sha384_impl(module, data, usedforsecurity, string_obj);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=af11090855b7c85a input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=90625b237c774a9f input=a9049054013a1b77]*/
|
||||
|
|
128
Modules/clinic/sha3module.c.h
generated
128
Modules/clinic/sha3module.c.h
generated
|
@ -10,13 +10,14 @@ preserve
|
|||
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
|
||||
|
||||
PyDoc_STRVAR(py_sha3_new__doc__,
|
||||
"sha3_224(data=b\'\', /, *, usedforsecurity=True)\n"
|
||||
"sha3_224(data=b\'\', *, usedforsecurity=True, string=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a new SHA3 hash object.");
|
||||
|
||||
static PyObject *
|
||||
py_sha3_new_impl(PyTypeObject *type, PyObject *data, int usedforsecurity);
|
||||
py_sha3_new_impl(PyTypeObject *type, PyObject *data_obj, int usedforsecurity,
|
||||
PyObject *string);
|
||||
|
||||
static PyObject *
|
||||
py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
|
@ -24,7 +25,7 @@ py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 1
|
||||
#define NUM_KEYWORDS 3
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
|
@ -33,7 +34,7 @@ py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(usedforsecurity), },
|
||||
.ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
@ -42,40 +43,51 @@ py_sha3_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"", "usedforsecurity", NULL};
|
||||
static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "sha3_224",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *argsbuf[3];
|
||||
PyObject * const *fastargs;
|
||||
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
||||
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
|
||||
PyObject *data = NULL;
|
||||
PyObject *data_obj = NULL;
|
||||
int usedforsecurity = 1;
|
||||
PyObject *string = NULL;
|
||||
|
||||
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
|
||||
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
if (!fastargs) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional_posonly;
|
||||
if (!noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
noptargs--;
|
||||
data = fastargs[0];
|
||||
skip_optional_posonly:
|
||||
if (fastargs[0]) {
|
||||
data_obj = fastargs[0];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_pos;
|
||||
}
|
||||
}
|
||||
skip_optional_pos:
|
||||
if (!noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
usedforsecurity = PyObject_IsTrue(fastargs[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
if (fastargs[1]) {
|
||||
usedforsecurity = PyObject_IsTrue(fastargs[1]);
|
||||
if (usedforsecurity < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
string = fastargs[2];
|
||||
skip_optional_kwonly:
|
||||
return_value = py_sha3_new_impl(type, data, usedforsecurity);
|
||||
return_value = py_sha3_new_impl(type, data_obj, usedforsecurity, string);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
|
@ -158,24 +170,57 @@ _sha3_sha3_224_update(PyObject *self, PyObject *data)
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(_sha3_shake_128_digest__doc__,
|
||||
"digest($self, length, /)\n"
|
||||
"digest($self, /, length)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return the digest value as a bytes object.");
|
||||
|
||||
#define _SHA3_SHAKE_128_DIGEST_METHODDEF \
|
||||
{"digest", (PyCFunction)_sha3_shake_128_digest, METH_O, _sha3_shake_128_digest__doc__},
|
||||
{"digest", _PyCFunction_CAST(_sha3_shake_128_digest), METH_FASTCALL|METH_KEYWORDS, _sha3_shake_128_digest__doc__},
|
||||
|
||||
static PyObject *
|
||||
_sha3_shake_128_digest_impl(SHA3object *self, unsigned long length);
|
||||
|
||||
static PyObject *
|
||||
_sha3_shake_128_digest(PyObject *self, PyObject *arg)
|
||||
_sha3_shake_128_digest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 1
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
Py_hash_t ob_hash;
|
||||
PyObject *ob_item[NUM_KEYWORDS];
|
||||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(length), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
||||
#else // !Py_BUILD_CORE
|
||||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"length", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "digest",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
unsigned long length;
|
||||
|
||||
if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
if (!_PyLong_UnsignedLong_Converter(args[0], &length)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = _sha3_shake_128_digest_impl((SHA3object *)self, length);
|
||||
|
@ -185,24 +230,57 @@ exit:
|
|||
}
|
||||
|
||||
PyDoc_STRVAR(_sha3_shake_128_hexdigest__doc__,
|
||||
"hexdigest($self, length, /)\n"
|
||||
"hexdigest($self, /, length)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return the digest value as a string of hexadecimal digits.");
|
||||
|
||||
#define _SHA3_SHAKE_128_HEXDIGEST_METHODDEF \
|
||||
{"hexdigest", (PyCFunction)_sha3_shake_128_hexdigest, METH_O, _sha3_shake_128_hexdigest__doc__},
|
||||
{"hexdigest", _PyCFunction_CAST(_sha3_shake_128_hexdigest), METH_FASTCALL|METH_KEYWORDS, _sha3_shake_128_hexdigest__doc__},
|
||||
|
||||
static PyObject *
|
||||
_sha3_shake_128_hexdigest_impl(SHA3object *self, unsigned long length);
|
||||
|
||||
static PyObject *
|
||||
_sha3_shake_128_hexdigest(PyObject *self, PyObject *arg)
|
||||
_sha3_shake_128_hexdigest(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 1
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
Py_hash_t ob_hash;
|
||||
PyObject *ob_item[NUM_KEYWORDS];
|
||||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_hash = -1,
|
||||
.ob_item = { &_Py_ID(length), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
||||
#else // !Py_BUILD_CORE
|
||||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"length", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "hexdigest",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
unsigned long length;
|
||||
|
||||
if (!_PyLong_UnsignedLong_Converter(arg, &length)) {
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
||||
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
if (!_PyLong_UnsignedLong_Converter(args[0], &length)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = _sha3_shake_128_hexdigest_impl((SHA3object *)self, length);
|
||||
|
@ -210,4 +288,4 @@ _sha3_shake_128_hexdigest(PyObject *self, PyObject *arg)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=5b3ac1c06c6899ea input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=65e437799472b89f input=a9049054013a1b77]*/
|
||||
|
|
|
@ -76,3 +76,32 @@
|
|||
* to allow the user to optimize based on the platform they're using. */
|
||||
#define HASHLIB_GIL_MINSIZE 2048
|
||||
|
||||
static inline int
|
||||
_Py_hashlib_data_argument(PyObject **res, PyObject *data, PyObject *string)
|
||||
{
|
||||
if (data != NULL && string == NULL) {
|
||||
// called as H(data) or H(data=...)
|
||||
*res = data;
|
||||
return 1;
|
||||
}
|
||||
else if (data == NULL && string != NULL) {
|
||||
// called as H(string=...)
|
||||
*res = string;
|
||||
return 1;
|
||||
}
|
||||
else if (data == NULL && string == NULL) {
|
||||
// fast path when no data is given
|
||||
assert(!PyErr_Occurred());
|
||||
*res = NULL;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
// called as H(data=..., string)
|
||||
*res = NULL;
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"'data' and 'string' are mutually exclusive "
|
||||
"and support for 'string' keyword parameter "
|
||||
"is slated for removal in a future version.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,17 +276,24 @@ static PyType_Spec md5_type_spec = {
|
|||
/*[clinic input]
|
||||
_md5.md5
|
||||
|
||||
string: object(c_default="NULL") = b''
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string as string_obj: object(c_default="NULL") = None
|
||||
|
||||
Return a new MD5 hash object; optionally initialized with a string.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_md5_md5_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
||||
/*[clinic end generated code: output=587071f76254a4ac input=7a144a1905636985]*/
|
||||
_md5_md5_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj)
|
||||
/*[clinic end generated code: output=d45e187d3d16f3a8 input=7ea5c5366dbb44bf]*/
|
||||
{
|
||||
PyObject *string;
|
||||
if (_Py_hashlib_data_argument(&string, data, string_obj) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MD5object *new;
|
||||
Py_buffer buf;
|
||||
|
||||
|
|
|
@ -272,19 +272,25 @@ static PyType_Spec sha1_type_spec = {
|
|||
/*[clinic input]
|
||||
_sha1.sha1
|
||||
|
||||
string: object(c_default="NULL") = b''
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string as string_obj: object(c_default="NULL") = None
|
||||
|
||||
Return a new SHA1 hash object; optionally initialized with a string.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_sha1_sha1_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
||||
/*[clinic end generated code: output=6f8b3af05126e18e input=bd54b68e2bf36a8a]*/
|
||||
_sha1_sha1_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj)
|
||||
/*[clinic end generated code: output=0d453775924f88a7 input=807f25264e0ac656]*/
|
||||
{
|
||||
SHA1object *new;
|
||||
Py_buffer buf;
|
||||
PyObject *string;
|
||||
if (_Py_hashlib_data_argument(&string, data, string_obj) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (string) {
|
||||
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
|
||||
|
|
|
@ -594,18 +594,24 @@ static PyType_Spec sha512_type_spec = {
|
|||
/*[clinic input]
|
||||
_sha2.sha256
|
||||
|
||||
string: object(c_default="NULL") = b''
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string as string_obj: object(c_default="NULL") = None
|
||||
|
||||
Return a new SHA-256 hash object; optionally initialized with a string.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha256_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
||||
/*[clinic end generated code: output=243c9dd289931f87 input=6249da1de607280a]*/
|
||||
_sha2_sha256_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj)
|
||||
/*[clinic end generated code: output=49828a7bcd418f45 input=9ce1d70e669abc14]*/
|
||||
{
|
||||
Py_buffer buf;
|
||||
PyObject *string;
|
||||
if (_Py_hashlib_data_argument(&string, data, string_obj) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (string) {
|
||||
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
|
||||
|
@ -651,18 +657,25 @@ _sha2_sha256_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
|||
/*[clinic input]
|
||||
_sha2.sha224
|
||||
|
||||
string: object(c_default="NULL") = b''
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string as string_obj: object(c_default="NULL") = None
|
||||
|
||||
Return a new SHA-224 hash object; optionally initialized with a string.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha224_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
||||
/*[clinic end generated code: output=68191f232e4a3843 input=c42bcba47fd7d2b7]*/
|
||||
_sha2_sha224_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj)
|
||||
/*[clinic end generated code: output=2163cb03b6cf6157 input=612f7682a889bc2a]*/
|
||||
{
|
||||
Py_buffer buf;
|
||||
PyObject *string;
|
||||
if (_Py_hashlib_data_argument(&string, data, string_obj) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (string) {
|
||||
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
|
||||
}
|
||||
|
@ -706,19 +719,25 @@ _sha2_sha224_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
|||
/*[clinic input]
|
||||
_sha2.sha512
|
||||
|
||||
string: object(c_default="NULL") = b''
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string as string_obj: object(c_default="NULL") = None
|
||||
|
||||
Return a new SHA-512 hash object; optionally initialized with a string.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha512_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
||||
/*[clinic end generated code: output=d55c8996eca214d7 input=0576ae2a6ebfad25]*/
|
||||
_sha2_sha512_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj)
|
||||
/*[clinic end generated code: output=cc3fcfce001a4538 input=19c9f2c06d59563a]*/
|
||||
{
|
||||
SHA512object *new;
|
||||
Py_buffer buf;
|
||||
PyObject *string;
|
||||
if (_Py_hashlib_data_argument(&string, data, string_obj) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sha2_state *state = sha2_get_state(module);
|
||||
|
||||
|
@ -763,19 +782,25 @@ _sha2_sha512_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
|||
/*[clinic input]
|
||||
_sha2.sha384
|
||||
|
||||
string: object(c_default="NULL") = b''
|
||||
data: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string as string_obj: object(c_default="NULL") = None
|
||||
|
||||
Return a new SHA-384 hash object; optionally initialized with a string.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_sha2_sha384_impl(PyObject *module, PyObject *string, int usedforsecurity)
|
||||
/*[clinic end generated code: output=b29a0d81d51d1368 input=4e9199d8de0d2f9b]*/
|
||||
_sha2_sha384_impl(PyObject *module, PyObject *data, int usedforsecurity,
|
||||
PyObject *string_obj)
|
||||
/*[clinic end generated code: output=b6e3db593b5a0330 input=9fd50c942ad9e0bf]*/
|
||||
{
|
||||
SHA512object *new;
|
||||
Py_buffer buf;
|
||||
PyObject *string;
|
||||
if (_Py_hashlib_data_argument(&string, data, string_obj) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sha2_state *state = sha2_get_state(module);
|
||||
|
||||
|
|
|
@ -105,18 +105,25 @@ sha3_update(Hacl_Hash_SHA3_state_t *state, uint8_t *buf, Py_ssize_t len)
|
|||
/*[clinic input]
|
||||
@classmethod
|
||||
_sha3.sha3_224.__new__ as py_sha3_new
|
||||
data: object(c_default="NULL") = b''
|
||||
/
|
||||
|
||||
data as data_obj: object(c_default="NULL") = b''
|
||||
*
|
||||
usedforsecurity: bool = True
|
||||
string: object(c_default="NULL") = None
|
||||
|
||||
Return a new SHA3 hash object.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
py_sha3_new_impl(PyTypeObject *type, PyObject *data, int usedforsecurity)
|
||||
/*[clinic end generated code: output=90409addc5d5e8b0 input=637e5f8f6a93982a]*/
|
||||
py_sha3_new_impl(PyTypeObject *type, PyObject *data_obj, int usedforsecurity,
|
||||
PyObject *string)
|
||||
/*[clinic end generated code: output=dcec1eca20395f2a input=c106e0b4e2d67d58]*/
|
||||
{
|
||||
PyObject *data;
|
||||
if (_Py_hashlib_data_argument(&data, data_obj, string) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_buffer buf = {NULL, NULL};
|
||||
SHA3State *state = _PyType_GetModuleState(type);
|
||||
SHA3object *self = newSHA3object(type);
|
||||
|
@ -503,14 +510,13 @@ _SHAKE_digest(PyObject *op, unsigned long digestlen, int hex)
|
|||
_sha3.shake_128.digest
|
||||
|
||||
length: unsigned_long
|
||||
/
|
||||
|
||||
Return the digest value as a bytes object.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_sha3_shake_128_digest_impl(SHA3object *self, unsigned long length)
|
||||
/*[clinic end generated code: output=2313605e2f87bb8f input=418ef6a36d2e6082]*/
|
||||
/*[clinic end generated code: output=2313605e2f87bb8f input=93d6d6ff32904f18]*/
|
||||
{
|
||||
return _SHAKE_digest((PyObject *)self, length, 0);
|
||||
}
|
||||
|
@ -520,14 +526,13 @@ _sha3_shake_128_digest_impl(SHA3object *self, unsigned long length)
|
|||
_sha3.shake_128.hexdigest
|
||||
|
||||
length: unsigned_long
|
||||
/
|
||||
|
||||
Return the digest value as a string of hexadecimal digits.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_sha3_shake_128_hexdigest_impl(SHA3object *self, unsigned long length)
|
||||
/*[clinic end generated code: output=bf8e2f1e490944a8 input=69fb29b0926ae321]*/
|
||||
/*[clinic end generated code: output=bf8e2f1e490944a8 input=562d74e7060b56ab]*/
|
||||
{
|
||||
return _SHAKE_digest((PyObject *)self, length, 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue