Skip to content

Add variable-length output support to SHAKE digests - #23

Merged
SeanTAllen merged 1 commit into
mainfrom
shake-variable-length
Feb 12, 2026
Merged

Add variable-length output support to SHAKE digests#23
SeanTAllen merged 1 commit into
mainfrom
shake-variable-length

Conversation

@SeanTAllen

Copy link
Copy Markdown
Member

SHAKE128 and SHAKE256 are XOFs that can produce arbitrary-length output, but the constructors hardcoded fixed sizes (16 and 32 bytes). The infrastructure for variable length already existed (_variable_length flag, EVP_DigestFinalXOF dispatch in final()) but was inaccessible.

Adds a size parameter to both constructors with defaults matching the previous fixed values, so existing code is unaffected. On OpenSSL 1.1.x, the parameter is accepted but ignored (the default is always used) to prevent buffer overflow from EVP_DigestFinal_ex writing a fixed-size output.

Four property tests (OpenSSL 3.0.x only) verify output length matches the requested size and that the XOF prefix property holds: a shorter output is a prefix of a longer output from the same input.

Closes #6

SHAKE128 and SHAKE256 are XOFs that can produce arbitrary-length
output, but the constructors hardcoded fixed sizes (16 and 32 bytes).
The infrastructure for variable length already existed (_variable_length
flag, EVP_DigestFinalXOF dispatch in final()) but was inaccessible.

Add a size parameter to both constructors with defaults matching the
previous fixed values. On OpenSSL 1.1.x, the parameter is accepted but
ignored (the default is always used) to prevent buffer overflow from
EVP_DigestFinal_ex writing a fixed-size output.

Four property tests (OpenSSL 3.0.x only) verify output length matches
the requested size and that the XOF prefix property holds: a shorter
output is a prefix of a longer output from the same input.

Closes #6
@SeanTAllen SeanTAllen added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Feb 12, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 12, 2026
@SeanTAllen
SeanTAllen merged commit af50020 into main Feb 12, 2026
14 checks passed
@SeanTAllen
SeanTAllen deleted the shake-variable-length branch February 12, 2026 12:26
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 12, 2026
github-actions Bot pushed a commit that referenced this pull request Feb 12, 2026
github-actions Bot pushed a commit that referenced this pull request Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - added Automatically add "Added" CHANGELOG entry on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Digest API should be updated for variable length hashes

2 participants