diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index b511c160c9260f..a718be415b9905 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -1505,6 +1505,12 @@ def test_HACL_sha3_attributes(self, size, attrname): def test_HACL_shake_attributes(self, size, attrname): self.check_HACL_attribute(_sha3, f"shake_{size}", attrname) + @requires_blake2 + @support.subTests("version", ["blake2s", "blake2b"]) + @support.subTests("attrname", ["block_size", "digest_size"]) + def test_HACL_blake2_attributes(self, version, attrname): + self.check_HACL_attribute(_blake2, version, attrname) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Library/2026-08-15-13-18-01.gh-issue-155835.mlyLWp.rst b/Misc/NEWS.d/next/Library/2026-08-15-13-18-01.gh-issue-155835.mlyLWp.rst new file mode 100644 index 00000000000000..9ef7d0694e66c3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-15-13-18-01.gh-issue-155835.mlyLWp.rst @@ -0,0 +1,2 @@ +:mod:`hashlib`: Fix a data race when accessing :attr:`~hashlib.hash.digest_size` +on BLAKE-2 objects. Patch by Bénédikt Tran. diff --git a/Modules/blake2module.c b/Modules/blake2module.c index ac7265bb9d6836..c69c4259b12666 100644 --- a/Modules/blake2module.c +++ b/Modules/blake2module.c @@ -950,7 +950,9 @@ static PyObject * py_blake2b_get_digest_size(PyObject *op, void *Py_UNUSED(closure)) { Blake2Object *self = _Blake2Object_CAST(op); + HASHLIB_ACQUIRE_LOCK(self); Hacl_Hash_Blake2b_index info = hacl_get_blake2_info(self); + HASHLIB_RELEASE_LOCK(self); return PyLong_FromLong(info.digest_length); }