Skip to main content

ml_dsa/signing/
steps.rs

1//! Straight-line computations inside one signing attempt.
2//!
3//! Keep the rejection decisions in the caller so these computations can be
4//! checked with all intermediate values still classified as secret.
5
6use crate::{
7    MlDsaParams,
8    algebra::{AlgebraExt, NttPolynomial, NttVector, Vector},
9    ntt::NttInverse,
10};
11
12/// Intermediate values used by the first rejection check and hint computation.
13pub(crate) struct Response<P: MlDsaParams> {
14    pub(crate) z: Vector<P::L>,
15    pub(crate) cs2: Vector<P::K>,
16    pub(crate) r0: Vector<P::K>,
17}
18
19/// Compute the response `z`, `cs2`, and the low bits `r0` checked before hint generation.
20#[inline]
21pub(crate) fn response<P: MlDsaParams>(
22    y: &Vector<P::L>,
23    w: &Vector<P::K>,
24    c_hat: &NttPolynomial,
25    s1_hat: &NttVector<P::L>,
26    s2_hat: &NttVector<P::K>,
27) -> Response<P> {
28    let cs1 = (c_hat * s1_hat).ntt_inverse();
29    let cs2 = (c_hat * s2_hat).ntt_inverse();
30    let z = y + &cs1;
31    let r0 = (w - &cs2).low_bits::<P::TwoGamma2>();
32    Response { z, cs2, r0 }
33}
34
35/// Compute `ct0` and `w - cs2 + ct0` for hint construction.
36#[inline]
37pub(crate) fn hint_polynomials<P: MlDsaParams>(
38    w: &Vector<P::K>,
39    cs2: &Vector<P::K>,
40    c_hat: &NttPolynomial,
41    t0_hat: &NttVector<P::K>,
42) -> (Vector<P::K>, Vector<P::K>) {
43    let ct0 = (c_hat * t0_hat).ntt_inverse();
44    let w_cs2_ct0 = &(w - cs2) + &ct0;
45    (ct0, w_cs2_ct0)
46}