Skip to content

ml-dsa: add internal MaybeBox type#1320

Merged
tarcieri merged 1 commit intomasterfrom
ml-dsa/maybebox
Apr 30, 2026
Merged

ml-dsa: add internal MaybeBox type#1320
tarcieri merged 1 commit intomasterfrom
ml-dsa/maybebox

Conversation

@tarcieri
Copy link
Copy Markdown
Member

Adds an internal type for opportunistic heap offload which uses Box when the alloc feature is available and falls back to stack allocation when it is not.

So far it's only used for the z component of Signature but is useful elsewhere, e.g. for VerifyingKey.

It's so generally useful it should probably get extracted somewhere, to module-lattice at the very least, but this is enough to get started.

Adds an internal type for opportunistic heap offload which uses `Box`
when the `alloc` feature is available and falls back to stack allocation
when it is not.

So far it's only used for the `z` component of `Signature` but is useful
elsewhere, e.g. for `VerifyingKey`.

It's so generally useful it should probably get extracted somewhere, to
`module-lattice` at the very least, but this is enough to get started.
@tarcieri tarcieri merged commit f3c409e into master Apr 30, 2026
9 checks passed
@tarcieri tarcieri deleted the ml-dsa/maybebox branch April 30, 2026 17:13
tarcieri added a commit to RustCrypto/traits that referenced this pull request May 9, 2026
Adds a type which is always available, but when the newly added `alloc`
feature is enabled, provides opportunistic heap allocation with `Box`,
falling back on stack allocation if it is not.

Originally added to the `ml-dsa` crate in RustCrypto/signatures#1320 to
address the large size of post-quantum keys and signatures while still
retaining `no_alloc` support.

However, it is generally useful anywhere we work with secret values to
e.g. prevent moves from making copies of them on the stack, even if they
aren't excessively large.
tarcieri added a commit to RustCrypto/KEMs that referenced this pull request May 10, 2026
Adds a type which is always available, but when the newly added `alloc`
feature is enabled, provides opportunistic heap allocation with `Box`,
falling back on stack allocation if it is not.

Originally added to the `ml-dsa` crate in RustCrypto/signatures#1320 to
address the large size of post-quantum keys and signatures while still
retaining `no_alloc` support.

However, it is generally useful anywhere we work with secret values to
e.g. prevent moves from making copies of them on the stack, even if they
aren't excessively large.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant