Skip to content

Commit 017ce32

Browse files
authored
ml-dsa: push the heavy bits of the signature on the heap (#1419)
Before this commit, the `ml_dsa::Signature` would cost up to 2120 bytes on the stack. This pushes the Hint to the heap if alloc feature is enabled.
1 parent a51becc commit 017ce32

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

ml-dsa/src/hint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use hybrid_array::{
77
Array,
88
typenum::{U256, Unsigned},
99
};
10-
use module_lattice::{Field, Truncate};
10+
use module_lattice::{Field, MaybeBox, Truncate};
1111

1212
/// Algorithm 39 `MakeHint`: computes hint bit indicating whether adding `z` to `r` alters the high
1313
/// bits of `r`.
@@ -44,7 +44,7 @@ fn use_hint<TwoGamma2: Unsigned>(h: bool, r: Elem) -> Elem {
4444
}
4545

4646
#[derive(Clone, PartialEq, Debug)]
47-
pub(crate) struct Hint<P>(pub Array<Array<bool, U256>, P::K>)
47+
pub(crate) struct Hint<P>(pub MaybeBox<Array<Array<bool, U256>, P::K>>)
4848
where
4949
P: SignatureParams;
5050

@@ -53,7 +53,7 @@ where
5353
P: SignatureParams,
5454
{
5555
fn default() -> Self {
56-
Self(Array::default())
56+
Self(MaybeBox::new(Array::default()))
5757
}
5858
}
5959

@@ -65,7 +65,7 @@ where
6565
let zi = z.0.iter();
6666
let ri = r.0.iter();
6767

68-
Self(
68+
Self(MaybeBox::new(
6969
zi.zip(ri)
7070
.map(|(zv, rv)| {
7171
let zvi = zv.0.iter();
@@ -76,7 +76,7 @@ where
7676
.collect()
7777
})
7878
.collect(),
79-
)
79+
))
8080
}
8181

8282
pub(crate) fn hamming_weight(&self) -> usize {

0 commit comments

Comments
 (0)