diff --git a/Cargo.lock b/Cargo.lock index 27b6f2e..54b4062 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -725,7 +725,7 @@ dependencies = [ [[package]] name = "module-lattice" version = "0.1.0-pre.0" -source = "git+https://github.com/RustCrypto/KEMs#5a2b2ae2003bd6c6f5ff5944ef07b3cd84a4d252" +source = "git+https://github.com/RustCrypto/KEMs#c3b485d4a6e4ea70b60b18bccca038772ef1981b" dependencies = [ "hybrid-array", "num-traits", diff --git a/ml-dsa/src/algebra.rs b/ml-dsa/src/algebra.rs index 06f31ca..dc5e7c7 100644 --- a/ml-dsa/src/algebra.rs +++ b/ml-dsa/src/algebra.rs @@ -2,7 +2,7 @@ use hybrid_array::{ ArraySize, typenum::{Shleft, U1, U13, Unsigned}, }; -pub(crate) use module_lattice::{algebra::Field, util::Truncate}; +pub(crate) use module_lattice::{algebra::Field, utils::Truncate}; use module_lattice::{algebra, define_field}; diff --git a/ml-dsa/src/crypto.rs b/ml-dsa/src/crypto.rs index c46e3c5..c3f8285 100644 --- a/ml-dsa/src/crypto.rs +++ b/ml-dsa/src/crypto.rs @@ -4,7 +4,7 @@ use sha3::{ digest::{ExtendableOutput, XofReader}, }; -use module_lattice::encode::ArraySize; +use module_lattice::encoding::ArraySize; pub(crate) enum ShakeState { Absorbing(Shake), @@ -63,7 +63,7 @@ pub(crate) type H = ShakeState; #[cfg(test)] mod test { use super::*; - use crate::util::B32; + use crate::B32; use hex_literal::hex; #[test] diff --git a/ml-dsa/src/encode.rs b/ml-dsa/src/encode.rs index 1431328..7099108 100644 --- a/ml-dsa/src/encode.rs +++ b/ml-dsa/src/encode.rs @@ -3,7 +3,7 @@ use hybrid_array::{ Array, typenum::{Len, Length, Sum, Unsigned}, }; -use module_lattice::encode::{ArraySize, Encode, EncodingSize, VectorEncodingSize}; +use module_lattice::encoding::{ArraySize, Encode, EncodingSize, VectorEncodingSize}; use crate::algebra::{Elem, Polynomial, Vector}; @@ -119,7 +119,7 @@ pub(crate) mod test { marker_traits::Zero, operator_aliases::{Diff, Mod, Shleft}, }; - use module_lattice::encode::*; + use module_lattice::encoding::*; // A helper trait to construct larger arrays by repeating smaller ones trait Repeat { diff --git a/ml-dsa/src/hint.rs b/ml-dsa/src/hint.rs index f080284..45750a7 100644 --- a/ml-dsa/src/hint.rs +++ b/ml-dsa/src/hint.rs @@ -2,7 +2,7 @@ use hybrid_array::{ Array, typenum::{U256, Unsigned}, }; -use module_lattice::util::Truncate; +use module_lattice::utils::Truncate; use crate::algebra::{AlgebraExt, BaseField, Decompose, Elem, Field, Polynomial, Vector}; use crate::param::{EncodedHint, SignatureParams}; diff --git a/ml-dsa/src/lib.rs b/ml-dsa/src/lib.rs index 5ef1d88..6604163 100644 --- a/ml-dsa/src/lib.rs +++ b/ml-dsa/src/lib.rs @@ -44,7 +44,9 @@ mod ntt; mod param; mod pkcs8; mod sampling; -mod util; + +pub use crate::param::{EncodedSignature, EncodedVerifyingKey, ExpandedSigningKey, MlDsaParams}; +pub use signature::{self, Error}; use core::convert::{AsRef, TryFrom, TryInto}; use hybrid_array::{ @@ -57,6 +59,14 @@ use hybrid_array::{ 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}, @@ -66,18 +76,11 @@ use { #[cfg(feature = "zeroize")] use zeroize::{Zeroize, ZeroizeOnDrop}; -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 crate::util::B64; -use core::fmt; +/// A 32-byte array, defined here for brevity because it is used several times +pub type B32 = Array; -pub use crate::param::{EncodedSignature, EncodedVerifyingKey, ExpandedSigningKey, MlDsaParams}; -pub use crate::util::B32; -pub use signature::{self, Error}; +/// A 64-byte array, defined here for brevity because it is used several times +pub(crate) type B64 = Array; /// ML-DSA seeds are signing (private) keys, which are consistently 32-bytes across all security /// levels, and are the preferred serialization for representing such keys. diff --git a/ml-dsa/src/ntt.rs b/ml-dsa/src/ntt.rs index 3edeaba..08b45b8 100644 --- a/ml-dsa/src/ntt.rs +++ b/ml-dsa/src/ntt.rs @@ -1,12 +1,12 @@ use module_lattice::{ algebra::{Field, MultiplyNtt}, - encode::ArraySize, + encoding::ArraySize, }; use crate::algebra::{BaseField, Elem, NttPolynomial, NttVector, Polynomial, Vector}; // 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 exponetiations at runtime. +// to avoid the need to compute the exponentiations at runtime. // // ZETA_POW_BITREV[i] = zeta^{BitRev_8(i)} // diff --git a/ml-dsa/src/param.rs b/ml-dsa/src/param.rs index ce72b94..6509d3e 100644 --- a/ml-dsa/src/param.rs +++ b/ml-dsa/src/param.rs @@ -9,9 +9,9 @@ //! that the size of an encoded vector is `K` times the size of an encoded polynomial. use crate::{ + B32, B64, algebra::{Polynomial, Vector}, encode::{BitPack, RangeEncodedPolynomialSize, RangeEncodedVectorSize, RangeEncodingSize}, - util::{B32, B64}, }; use core::{ fmt::Debug, @@ -24,7 +24,7 @@ use hybrid_array::{ Unsigned, }, }; -use module_lattice::encode::{ +use module_lattice::encoding::{ ArraySize, Encode, EncodedPolynomialSize, EncodedVectorSize, EncodingSize, }; diff --git a/ml-dsa/src/sampling.rs b/ml-dsa/src/sampling.rs index e77c40f..f69b841 100644 --- a/ml-dsa/src/sampling.rs +++ b/ml-dsa/src/sampling.rs @@ -6,7 +6,7 @@ use crate::{ param::{Eta, MaskSamplingSize}, }; use hybrid_array::Array; -use module_lattice::{encode::ArraySize, util::Truncate}; +use module_lattice::{encoding::ArraySize, utils::Truncate}; // Algorithm 13 BytesToBits fn bit_set(z: &[u8], i: usize) -> bool { diff --git a/ml-dsa/src/util.rs b/ml-dsa/src/util.rs deleted file mode 100644 index 48ea9c4..0000000 --- a/ml-dsa/src/util.rs +++ /dev/null @@ -1,10 +0,0 @@ -use hybrid_array::{ - Array, - typenum::{U32, U64}, -}; - -/// A 32-byte array, defined here for brevity because it is used several times -pub type B32 = Array; - -/// A 64-byte array, defined here for brevity because it is used several times -pub(crate) type B64 = Array; diff --git a/ml-dsa/tests/wycheproof.rs b/ml-dsa/tests/wycheproof.rs index e983f0a..23e57e6 100644 --- a/ml-dsa/tests/wycheproof.rs +++ b/ml-dsa/tests/wycheproof.rs @@ -87,7 +87,10 @@ macro_rules! mldsa_sign_seed_test { match test.result { ExpectedResult::Valid => { - assert_eq!(&*result.unwrap().to_bytes(), test.sig.as_slice()) + assert_eq!( + &*result.expect("should be valid").to_bytes(), + test.sig.as_slice() + ) } ExpectedResult::Invalid => { assert!(result.is_err())