mirror of
https://github.com/RustCrypto/signatures
synced 2026-06-21 13:45:42 +00:00
ml-dsa: use flattened module-lattice API (#1208)
Companion PR to RustCrypto/KEMs#244
This commit is contained in:
Generated
+3
-4
@@ -584,9 +584,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hybrid-array"
|
||||
version = "0.4.6"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b41fb3dc24fe72c2e3a4685eed55917c2fb228851257f4a8f2d985da9443c3e5"
|
||||
checksum = "e1b229d73f5803b562cc26e4da0396c8610a4ee209f4fac8fa4f8d709166dc45"
|
||||
dependencies = [
|
||||
"subtle",
|
||||
"typenum",
|
||||
@@ -731,8 +731,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "module-lattice"
|
||||
version = "0.1.0-rc.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b58fe0672f0701f5c1180c3e5c3d00b08dd9b207e545a38f3174d5363e2ae9e"
|
||||
source = "git+https://github.com/RustCrypto/KEMs#9404362c9180fd142c251502ca32dffe1ff0a4e4"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
"num-traits",
|
||||
|
||||
@@ -26,4 +26,5 @@ ml-dsa = { path = "./ml-dsa" }
|
||||
rfc6979 = { path = "./rfc6979" }
|
||||
slh-dsa = { path = "./slh-dsa" }
|
||||
|
||||
module-lattice = { git = "https://github.com/RustCrypto/KEMs" }
|
||||
rand = { git = "https://github.com/rust-random/rand" }
|
||||
|
||||
+8
-10
@@ -2,20 +2,18 @@ use hybrid_array::{
|
||||
ArraySize,
|
||||
typenum::{Shleft, U1, U13, Unsigned},
|
||||
};
|
||||
pub(crate) use module_lattice::{algebra::Field, utils::Truncate};
|
||||
use module_lattice::{Field, Truncate};
|
||||
|
||||
use module_lattice::{algebra, define_field};
|
||||
|
||||
define_field!(BaseField, u32, u64, u128, 8_380_417);
|
||||
module_lattice::define_field!(BaseField, u32, u64, u128, 8_380_417);
|
||||
|
||||
pub(crate) type Int = <BaseField as Field>::Int;
|
||||
|
||||
pub(crate) type Elem = algebra::Elem<BaseField>;
|
||||
pub(crate) type Polynomial = algebra::Polynomial<BaseField>;
|
||||
pub(crate) type Vector<K> = algebra::Vector<BaseField, K>;
|
||||
pub(crate) type NttPolynomial = algebra::NttPolynomial<BaseField>;
|
||||
pub(crate) type NttVector<K> = algebra::NttVector<BaseField, K>;
|
||||
pub(crate) type NttMatrix<K, L> = algebra::NttMatrix<BaseField, K, L>;
|
||||
pub(crate) type Elem = module_lattice::Elem<BaseField>;
|
||||
pub(crate) type Polynomial = module_lattice::Polynomial<BaseField>;
|
||||
pub(crate) type Vector<K> = module_lattice::Vector<BaseField, K>;
|
||||
pub(crate) type NttPolynomial = module_lattice::NttPolynomial<BaseField>;
|
||||
pub(crate) type NttVector<K> = module_lattice::NttVector<BaseField, K>;
|
||||
pub(crate) type NttMatrix<K, L> = module_lattice::NttMatrix<BaseField, K, L>;
|
||||
|
||||
// We require modular reduction for three moduli: q, 2^d, and 2 * gamma2. All three of these are
|
||||
// greater than sqrt(q), which means that a number reduced mod q will always be less than M^2,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use hybrid_array::Array;
|
||||
use module_lattice::ArraySize;
|
||||
use sha3::{
|
||||
Shake128, Shake256,
|
||||
digest::{ExtendableOutput, XofReader},
|
||||
};
|
||||
|
||||
use module_lattice::encoding::ArraySize;
|
||||
|
||||
pub(crate) enum ShakeState<Shake: ExtendableOutput> {
|
||||
Absorbing(Shake),
|
||||
Squeezing(Shake::Reader),
|
||||
|
||||
@@ -3,7 +3,7 @@ use hybrid_array::{
|
||||
Array,
|
||||
typenum::{Len, Length, Sum, Unsigned},
|
||||
};
|
||||
use module_lattice::encoding::{ArraySize, Encode, EncodingSize, VectorEncodingSize};
|
||||
use module_lattice::{ArraySize, Encode, EncodingSize, VectorEncodingSize};
|
||||
|
||||
use crate::algebra::{Elem, Polynomial, Vector};
|
||||
|
||||
@@ -120,7 +120,7 @@ pub(crate) mod tests {
|
||||
marker_traits::Zero,
|
||||
operator_aliases::{Diff, Mod, Shleft},
|
||||
};
|
||||
use module_lattice::encoding::*;
|
||||
use module_lattice::{EncodedPolynomial, Field};
|
||||
|
||||
// A helper trait to construct larger arrays by repeating smaller ones
|
||||
trait Repeat<T: Clone, D: ArraySize> {
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
use crate::{
|
||||
algebra::{AlgebraExt, BaseField, Decompose, Elem, Polynomial, Vector},
|
||||
param::{EncodedHint, SignatureParams},
|
||||
};
|
||||
use hybrid_array::{
|
||||
Array,
|
||||
typenum::{U256, Unsigned},
|
||||
};
|
||||
use module_lattice::utils::Truncate;
|
||||
|
||||
use crate::algebra::{AlgebraExt, BaseField, Decompose, Elem, Field, Polynomial, Vector};
|
||||
use crate::param::{EncodedHint, SignatureParams};
|
||||
use module_lattice::{Field, Truncate};
|
||||
|
||||
/// Algorithm 39 `MakeHint`: computes hint bit indicating whether adding `z` to `r` alters the high
|
||||
/// bits of `r`.
|
||||
|
||||
+8
-8
@@ -48,7 +48,14 @@ mod sampling;
|
||||
pub use crate::param::{EncodedSignature, EncodedVerifyingKey, ExpandedSigningKey, MlDsaParams};
|
||||
pub use signature::{self, Error};
|
||||
|
||||
use crate::algebra::{AlgebraExt, Elem, NttMatrix, NttVector, Vector};
|
||||
use crate::crypto::H;
|
||||
use crate::hint::Hint;
|
||||
use crate::ntt::{Ntt, NttInverse};
|
||||
use crate::param::{ParameterSet, QMinus1, SamplingSize, SpecQ};
|
||||
use crate::sampling::{expand_a, expand_mask, expand_s, sample_in_ball};
|
||||
use core::convert::{AsRef, TryFrom, TryInto};
|
||||
use core::fmt;
|
||||
use hybrid_array::{
|
||||
Array,
|
||||
typenum::{
|
||||
@@ -56,17 +63,10 @@ use hybrid_array::{
|
||||
U75, U80, U88, Unsigned,
|
||||
},
|
||||
};
|
||||
use module_lattice::Truncate;
|
||||
use sha3::Shake256;
|
||||
use signature::{DigestSigner, DigestVerifier, MultipartSigner, MultipartVerifier, Signer};
|
||||
|
||||
use crate::algebra::{AlgebraExt, Elem, NttMatrix, NttVector, Truncate, Vector};
|
||||
use crate::crypto::H;
|
||||
use crate::hint::Hint;
|
||||
use crate::ntt::{Ntt, NttInverse};
|
||||
use crate::param::{ParameterSet, QMinus1, SamplingSize, SpecQ};
|
||||
use crate::sampling::{expand_a, expand_mask, expand_s, sample_in_ball};
|
||||
use core::fmt;
|
||||
|
||||
#[cfg(feature = "rand_core")]
|
||||
use {
|
||||
rand_core::{CryptoRng, TryCryptoRng},
|
||||
|
||||
+1
-5
@@ -1,9 +1,5 @@
|
||||
use module_lattice::{
|
||||
algebra::{Field, MultiplyNtt},
|
||||
encoding::ArraySize,
|
||||
};
|
||||
|
||||
use crate::algebra::{BaseField, Elem, NttPolynomial, NttVector, Polynomial, Vector};
|
||||
use module_lattice::{ArraySize, Field, MultiplyNtt};
|
||||
|
||||
// Since the powers of zeta used in the NTT and MultiplyNTTs are fixed, we use pre-computed tables
|
||||
// to avoid the need to compute the exponentiations at runtime.
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@ use hybrid_array::{
|
||||
Unsigned,
|
||||
},
|
||||
};
|
||||
use module_lattice::encoding::{
|
||||
ArraySize, Encode, EncodedPolynomialSize, EncodedVectorSize, EncodingSize,
|
||||
};
|
||||
use module_lattice::{ArraySize, Encode, EncodedPolynomialSize, EncodedVectorSize, EncodingSize};
|
||||
|
||||
/// Some useful compile-time constants
|
||||
pub(crate) type SpecQ = Sum<Diff<Shleft<U1, U23>, Shleft<U1, U13>>, U1>;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use crate::{
|
||||
algebra::{
|
||||
BaseField, Elem, Field, Int, NttMatrix, NttPolynomial, NttVector, Polynomial, Vector,
|
||||
},
|
||||
algebra::{BaseField, Elem, Int, NttMatrix, NttPolynomial, NttVector, Polynomial, Vector},
|
||||
crypto::{G, H},
|
||||
param::{Eta, MaskSamplingSize},
|
||||
};
|
||||
use hybrid_array::Array;
|
||||
use module_lattice::{encoding::ArraySize, utils::Truncate};
|
||||
use module_lattice::{ArraySize, Field, Truncate};
|
||||
|
||||
// Algorithm 13 BytesToBits
|
||||
fn bit_set(z: &[u8], i: usize) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user