Skip to content

SystemError in OpenSSL's SHAKE when passing negative digest sizes #135759

Closed
@picnixz

Description

@picnixz

Bug report

Bug description:

import _hashlib

_hashlib.openssl_shake_128(b'').digest(-1)     # SystemError
_hashlib.openssl_shake_128(b'').hexdigest(-1)  # MemoryError

import _sha3
_sha3.shake_128(b'').digest(-1)                # ValueError
_sha3.shake_128(b'').hexdigest(-1)             # ValueError

The reason is that OpenSSL implementation accepts a ssize_t but HACL* accepts a uint32_t. I suggest raising a ValueError in OpenSSL's implementation as well. I'll rewrite #135744 for this issue at the same time.

Now, to prevent users passing incorrect data length, I also suggest to restrict has lengths to 2 ** 29 as it was done in HACL* and in #79103 but I'll do it in a follow-up. In the first time, let's only focus on raising a ValueError for all implementations on negative inputs.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Note

See #135759 (comment) for the rationale of a non-backport.

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions