Skip to content

Commit 4b21d5d

Browse files
committed
Finished massive refactor on mldsa.rs to remove duplicate code
1 parent c6db684 commit 4b21d5d

5 files changed

Lines changed: 99 additions & 96 deletions

File tree

crypto/core-test-framework/src/signature.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ impl TestFrameworkSignatureKeys {
173173
const SK_LEN: usize,
174174
>(&self) {
175175
self.test_boundary_conditions::<PK, SK, SigAlg, PK_LEN, SK_LEN>();
176-
self.debug_fmt_tests::<PK, SK, SigAlg, PK_LEN, SK_LEN>();
177176
}
178177

179178
/// Tests the correct behaviour on buffers too large / too small.
@@ -219,21 +218,6 @@ impl TestFrameworkSignatureKeys {
219218
_ => panic!("Should have failed"),
220219
}
221220
}
222-
223-
/// Tests that no private data is displayed
224-
// TODO: add the same tests to the core ML-DSA tests on vectors and polynomials
225-
fn debug_fmt_tests<
226-
PK: SignaturePublicKey,
227-
SK: SignaturePrivateKey,
228-
SigAlg: Signature<PK, SK>,
229-
const PK_LEN: usize,
230-
const SK_LEN: usize,
231-
>(&self) {
232-
let (pk, sk) = SigAlg::keygen().unwrap();
233-
234-
// let sk_str = format!("{:?}", sk);
235-
// println!("sk_str: {}", sk_str);
236-
}
237221
}
238222

239223
// TODO: tests for SignaturePublicKey

crypto/mldsa/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#![allow(unused_variables)] // todo - remove
55
#![allow(dead_code)] // todo - remove
6-
// #![allow(private_interfaces)] // todo debugging -- remove
76

87
#![forbid(unsafe_code)]
98
#![allow(incomplete_features)] // needed because currently generic_const_exprs is experimental
@@ -16,6 +15,10 @@
1615
#![allow(non_snake_case)]
1716
#![allow(non_upper_case_globals)]
1817

18+
// so I can use private traits to hide internal stuff that needs to be generic within the
19+
// MLDSA implentation, but I don't want accessed from outside, such FIPS-internal functions.
20+
#![allow(private_bounds)]
21+
1922
mod mldsa;
2023
mod hashmldsa;
2124
mod mldsa_keys;

crypto/mldsa/src/mldsa.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::marker::PhantomData;
22
use crate::aux_functions::{expand_mask, expandA, expandS, make_hint_vecs, ntt, power_2_round_vec, sample_in_ball, sig_encode, sig_decode, use_hint_vecs};
33
use crate::matrix::Vector;
4-
use crate::mldsa_keys::{MLDSAPrivateKey, MLDSAPrivateKeyTrait, MLDSAPublicKey, MLDSAPublicKeyTrait};
4+
use crate::mldsa_keys::{MLDSAPublicKeyTrait, MLDSAPublicKeyInternalTrait};
5+
use crate::mldsa_keys::{MLDSAPrivateKeyTrait, MLDSAPrivateKeyInternalTrait};
56
use crate::{MLDSA44PublicKey, MLDSA44PrivateKey, MLDSA65PublicKey, MLDSA65PrivateKey, MLDSA87PublicKey, MLDSA87PrivateKey};
67
use bouncycastle_core_interface::errors::SignatureError;
78
use bouncycastle_core_interface::key_material::{
89
KeyMaterial, KeyMaterial256, KeyMaterialSized, KeyType,
910
};
10-
use bouncycastle_core_interface::traits::{RNG, SecurityStrength, XOF, Signature, SignaturePublicKey, SignaturePrivateKey};
11+
use bouncycastle_core_interface::traits::{RNG, SecurityStrength, XOF, Signature};
1112
use bouncycastle_rng::{HashDRBG_SHA512};
1213
use bouncycastle_sha3::{SHAKE128, SHAKE256};
1314

@@ -199,8 +200,8 @@ pub struct MLDSA<
199200
const PK_LEN: usize,
200201
const SK_LEN: usize,
201202
const SIG_LEN: usize,
202-
PK: MLDSAPublicKeyTrait<k, PK_LEN>,
203-
SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN>,
203+
PK: MLDSAPublicKeyTrait<k, PK_LEN> + MLDSAPublicKeyInternalTrait<k, PK_LEN>,
204+
SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN> + MLDSAPrivateKeyInternalTrait<k, l, ETA, SK_LEN, PK_LEN>,
204205
const TAU: i32,
205206
const LAMBDA: i32,
206207
const GAMMA1: i32,
@@ -236,8 +237,8 @@ impl<
236237
const PK_LEN: usize,
237238
const SK_LEN: usize,
238239
const SIG_LEN: usize,
239-
PK: MLDSAPublicKeyTrait<k, PK_LEN>,
240-
SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN>,
240+
PK: MLDSAPublicKeyTrait<k, PK_LEN> + MLDSAPublicKeyInternalTrait<k, PK_LEN>,
241+
SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN> + MLDSAPrivateKeyInternalTrait<k, l, ETA, SK_LEN, PK_LEN>,
241242
const TAU: i32,
242243
const LAMBDA: i32,
243244
const GAMMA1: i32,
@@ -786,8 +787,8 @@ impl<
786787
const PK_LEN: usize,
787788
const SK_LEN: usize,
788789
const SIG_LEN: usize,
789-
PK: MLDSAPublicKeyTrait<k, PK_LEN>,
790-
SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN>,
790+
PK: MLDSAPublicKeyTrait<k, PK_LEN> + MLDSAPublicKeyInternalTrait<k, PK_LEN>,
791+
SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN> + MLDSAPrivateKeyInternalTrait<k, l, ETA, SK_LEN, PK_LEN>,
791792
const TAU: i32,
792793
const LAMBDA: i32,
793794
const GAMMA1: i32,

crypto/mldsa/src/mldsa_keys.rs

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ pub struct MLDSAPublicKey<const k: usize, const PK_LEN: usize> {
3232
}
3333

3434
pub trait MLDSAPublicKeyTrait<const k: usize, const PK_LEN: usize> : SignaturePublicKey {
35-
/// Not exposing a constructor publicly because you should have to get an instance either by
36-
/// running a keygen, or by decoding an existing key.
37-
fn new(rho: &[u8; SEED_LEN], t1: &Vector<k>) -> Self;
38-
3935
/// Algorithm 22 pkEncode(𝜌, 𝐭1)
4036
/// Encodes a public key for ML-DSA into a byte string.
4137
/// Input:𝜌 ∈ 𝔹32, 𝐭1 ∈ 𝑅𝑘 with coefficients in [0, 2bitlen (𝑞−1)−𝑑 − 1].
@@ -55,6 +51,12 @@ pub trait MLDSAPublicKeyTrait<const k: usize, const PK_LEN: usize> : SignaturePu
5551
/// 2. `tr` is the canonical fingerprint of an ML-DSA public key, so would be an appropriate value
5652
/// to use, for example, to build a public key lookup or deny-listing table.
5753
fn compute_tr(&self) -> [u8; 64];
54+
}
55+
56+
pub(crate) trait MLDSAPublicKeyInternalTrait<const k: usize, const PK_LEN: usize> {
57+
/// Not exposing a constructor publicly because you should have to get an instance either by
58+
/// running a keygen, or by decoding an existing key.
59+
fn new(rho: &[u8; SEED_LEN], t1: &Vector<k>) -> Self;
5860

5961
/// Get a ref to rho
6062
fn rho(&self) -> &[u8; 32];
@@ -64,10 +66,6 @@ pub trait MLDSAPublicKeyTrait<const k: usize, const PK_LEN: usize> : SignaturePu
6466
}
6567

6668
impl<const k: usize, const PK_LEN: usize> MLDSAPublicKeyTrait<k, PK_LEN> for MLDSAPublicKey<k, PK_LEN> {
67-
fn new(rho: &[u8; SEED_LEN], t1: &Vector<k>) -> Self {
68-
Self { rho: rho.clone(), t1: t1.clone() }
69-
}
70-
7169
fn pk_encode(&self) -> [u8; PK_LEN] {
7270
let mut pk = [0u8; PK_LEN];
7371

@@ -115,6 +113,12 @@ impl<const k: usize, const PK_LEN: usize> MLDSAPublicKeyTrait<k, PK_LEN> for MLD
115113

116114
tr
117115
}
116+
}
117+
118+
impl<const k: usize, const PK_LEN: usize> MLDSAPublicKeyInternalTrait<k, PK_LEN> for MLDSAPublicKey<k, PK_LEN> {
119+
fn new(rho: &[u8; SEED_LEN], t1: &Vector<k>) -> Self {
120+
Self { rho: rho.clone(), t1: t1.clone() }
121+
}
118122

119123
fn rho(&self) -> &[u8; 32] { &self.rho }
120124

@@ -197,36 +201,6 @@ pub struct MLDSAPrivateKey<
197201
}
198202

199203
pub trait MLDSAPrivateKeyTrait<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, const PK_LEN: usize> : SignaturePrivateKey {
200-
/// Not exposing a constructor publicly because you should have to get an instance either by
201-
/// running a keygen, or by decoding an existing key.
202-
fn new(
203-
rho: &[u8; 32],
204-
K: &[u8; 32],
205-
tr: &[u8; 64],
206-
s1: &Vector<l>,
207-
s2: &Vector<k>,
208-
t0: &Vector<k>,
209-
seed: Option<KeyMaterialSized<32>>,
210-
) -> Self;
211-
212-
/// Get a ref to rho
213-
fn rho(&self) -> &[u8; 32];
214-
215-
/// Get a ref to K
216-
fn K(&self) -> &[u8; 32];
217-
218-
/// Get a ref to tr
219-
fn tr(&self) -> &[u8; 64];
220-
221-
/// Get a ref to s1
222-
fn s1(&self) -> &Vector<l>;
223-
224-
/// Get a ref to s2
225-
fn s2(&self) -> &Vector<k>;
226-
227-
/// Get a ref to t0
228-
fn t0(&self) -> &Vector<k>;
229-
230204
/// Get a ref to the seed, if there is one stored with this private key
231205
fn seed(&self) -> &Option<KeyMaterialSized<32>>;
232206

@@ -249,9 +223,9 @@ pub trait MLDSAPrivateKeyTrait<const k: usize, const l: usize, const eta: usize,
249223
fn sk_decode(sk: &[u8; SK_LEN]) -> Self;
250224
}
251225

252-
253-
impl<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, const PK_LEN: usize>
254-
MLDSAPrivateKeyTrait<k, l, eta, SK_LEN, PK_LEN> for MLDSAPrivateKey<k, l, eta, SK_LEN, PK_LEN> {
226+
pub(crate) trait MLDSAPrivateKeyInternalTrait<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, const PK_LEN: usize> {
227+
/// Not exposing a constructor publicly because you should have to get an instance either by
228+
/// running a keygen, or by decoding an existing key.
255229
fn new(
256230
rho: &[u8; 32],
257231
K: &[u8; 32],
@@ -260,30 +234,29 @@ impl<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, cons
260234
s2: &Vector<k>,
261235
t0: &Vector<k>,
262236
seed: Option<KeyMaterialSized<32>>,
263-
) -> Self {
264-
Self {
265-
rho: rho.clone(),
266-
K: K.clone(),
267-
tr: tr.clone(),
268-
s1: s1.clone(),
269-
s2: s2.clone(),
270-
t0: t0.clone(),
271-
seed: seed.clone(),
272-
}
273-
}
237+
) -> Self;
238+
/// Get a ref to rho
239+
fn rho(&self) -> &[u8; 32];
274240

275-
fn rho(&self) -> &[u8; 32] { &self.rho }
241+
/// Get a ref to K
242+
fn K(&self) -> &[u8; 32];
276243

277-
fn K(&self) -> &[u8; 32] { &self.K }
244+
/// Get a ref to tr
245+
fn tr(&self) -> &[u8; 64];
278246

279-
fn tr(&self) -> &[u8; 64] { &self.tr }
247+
/// Get a ref to s1
248+
fn s1(&self) -> &Vector<l>;
280249

281-
fn s1(&self) -> &Vector<l> { &self.s1 }
250+
/// Get a ref to s2
251+
fn s2(&self) -> &Vector<k>;
282252

283-
fn s2(&self) -> &Vector<k> { &self.s2 }
253+
/// Get a ref to t0
254+
fn t0(&self) -> &Vector<k>;
255+
}
284256

285-
fn t0(&self) -> &Vector<k> { &self.t0 }
286257

258+
impl<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, const PK_LEN: usize>
259+
MLDSAPrivateKeyTrait<k, l, eta, SK_LEN, PK_LEN> for MLDSAPrivateKey<k, l, eta, SK_LEN, PK_LEN> {
287260
fn seed(&self) -> &Option<KeyMaterialSized<32>> { &self.seed }
288261

289262
fn derive_public_key(&self) -> MLDSAPublicKey<k, PK_LEN> {
@@ -390,6 +363,41 @@ impl<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, cons
390363
}
391364
}
392365

366+
impl<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, const PK_LEN: usize>
367+
MLDSAPrivateKeyInternalTrait<k, l, eta, SK_LEN, PK_LEN> for MLDSAPrivateKey<k, l, eta, SK_LEN, PK_LEN> {
368+
fn new(
369+
rho: &[u8; 32],
370+
K: &[u8; 32],
371+
tr: &[u8; 64],
372+
s1: &Vector<l>,
373+
s2: &Vector<k>,
374+
t0: &Vector<k>,
375+
seed: Option<KeyMaterialSized<32>>,
376+
) -> Self {
377+
Self {
378+
rho: rho.clone(),
379+
K: K.clone(),
380+
tr: tr.clone(),
381+
s1: s1.clone(),
382+
s2: s2.clone(),
383+
t0: t0.clone(),
384+
seed: seed.clone(),
385+
}
386+
}
387+
388+
fn rho(&self) -> &[u8; 32] { &self.rho }
389+
390+
fn K(&self) -> &[u8; 32] { &self.K }
391+
392+
fn tr(&self) -> &[u8; 64] { &self.tr }
393+
394+
fn s1(&self) -> &Vector<l> { &self.s1 }
395+
396+
fn s2(&self) -> &Vector<k> { &self.s2 }
397+
398+
fn t0(&self) -> &Vector<k> { &self.t0 }
399+
}
400+
393401
impl<const k: usize, const l: usize, const eta: usize, const SK_LEN: usize, const PK_LEN: usize>
394402
SignaturePrivateKey for MLDSAPrivateKey<k, l, eta, SK_LEN, PK_LEN> {
395403
fn encode(&self) -> Vec<u8> {

crypto/mldsa/tests/ml_dsa_key_tests.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#[cfg(test)]
22
mod mldsa_tests {
3-
use bouncycastle_core_interface::key_material::{KeyMaterial256, KeyType};
43
use bouncycastle_core_interface::traits::{Signature, SignaturePrivateKey, SignaturePublicKey};
5-
use bouncycastle_core_test_framework::signature::{TestFrameworkSignature, TestFrameworkSignatureKeys};
4+
use bouncycastle_core_test_framework::signature::{TestFrameworkSignatureKeys};
65
use bouncycastle_mldsa::{MLDSA44PrivateKey, MLDSA44PublicKey, MLDSA65PrivateKey, MLDSA65PublicKey, MLDSA87PrivateKey, MLDSA87PublicKey, MLDSAPrivateKeyTrait, MLDSAPublicKeyTrait, MLDSA44, MLDSA65, MLDSA87};
76
use bouncycastle_mldsa::{MLDSA44_PK_LEN, MLDSA44_SK_LEN, MLDSA65_PK_LEN, MLDSA65_SK_LEN, MLDSA87_PK_LEN, MLDSA87_SK_LEN};
87
use bouncycastle_hex as hex;
98

9+
1010
#[test]
11-
fn pk_from_sk() {
12-
let seed = KeyMaterial256::from_bytes_as_type(
13-
&hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap(),
14-
KeyType::Seed,
15-
).unwrap();
11+
fn core_framework_tests() {
12+
let tf = TestFrameworkSignatureKeys::new();
1613

14+
tf.test_public_keys::<MLDSA44PublicKey, MLDSA44PrivateKey, MLDSA44, MLDSA44_PK_LEN, MLDSA44_SK_LEN>();
15+
tf.test_public_keys::<MLDSA65PublicKey, MLDSA65PrivateKey, MLDSA65, MLDSA65_PK_LEN, MLDSA65_SK_LEN>();
16+
tf.test_public_keys::<MLDSA87PublicKey, MLDSA87PrivateKey, MLDSA87, MLDSA87_PK_LEN, MLDSA87_SK_LEN>();
17+
}
18+
19+
#[test]
20+
fn pk_from_sk() {
1721

1822
/* MLDSA44 */
1923
let expected_sk_bytes: [u8; MLDSA44_SK_LEN] = hex::decode("d7b2b47254aae0db45e7930d4a98d2c97d8f1397d1789dafa17024b316e9bec939ce0f7f77f8db5644dcda366bfe4734bd95f435ff9a613aa54aa41c2c694c04329a07b1fabb48f52a309f11a1898f848e2322ffe623ec810db3bee33685854a88269da320d5120bfcfe89a18e30f7114d83aa404a646b6c997389860d12522ee0006e2384819186619b260d118664d4a62822184482402898146148a6614c4248a19208c2382951244808a125c2083108c47120140914836c18a78084106ec9c07022b56408b0610c070498124451886959004622932041062e42b64c01164914284c41a85180460a5116515a0820022244dc9849d13251e13065d3c08592a85112a1640039220946621cc70cd9086dd0062652408580443091062c50c80924c5841a966d4a982c99066da4443220a7645a326e11b57020926124138e04852c0a4872c8a051d3082a99208058242024074e59148810a46460c06de0b28d1b1909203422c024410943710a212061a2015222521b80809a340013934dd3322922170a9892691a14512027219cc02062a2814818691a854d8344695b2041031242cb184601a90d0c023183b0215a224ac89205d9906904306a4b064ad2b2011c404081423252327254a6405a18100c321292c2805212625c82280bb46c03428d53100c14010ee1365288842491020a63462620062911c228d0204802b36ca236095a8648cbb4618b4662c440821a890910024d24b24520122524c90588288cc9c04d5948220a276ec134644c90605b445082864943880443b28c603080a2882d84a46d8ca629d0c68442064689885100a98d01498de4380da4068dd3947142b26c1a84611ba32842b42808a0711ac531e0a04c013765242862142890091061d940221b3360090292d02481200408491844a3222d5c8844149808a446610195640b390a0c9450ca406ad2b220c0380182308e13b908918084148829c0189112350da02422e20406d9c2850428121cc989180272d24029c20812d8062a9994719bb8682384291a2289144511dc82445096450c4484c0b2049aa60543862c44326e88442120a84c9a3070e3b82d63268803254903438c48a809ca147253344e1243081ba704593022d99480e234228142129c302a9434266104452426281346094a326d11280918b82562281113410d41b21190844c8b1212a2c688c9c030220606d2188e848630904452128831d9207113c52843060e033060cca6845826524c88011ef72562c85ffa43acfa49217f2b172d7bbc14620e6d980a71aabbdf0c45e9a206ecb1423fee15decc17601300149d9223cd6e6c6e1fa8e41fc7c64938ab68905fd3dcda50d87082e7d0d71d1bc9b2b84c85523ca8fe6cad294adf83be15b108ff721d0cc87bc3dd3a7590184b0e845663a91fc9e1c3c53a61d867420b04f092355753bc65a06368fd41295fd09924132c6f91f67964c142674a725c343914c4cecf58c074bcaf4558c97bf7911e07aa6d0938f2ee2bb3c1a8c595d635e84342fdea01dc24b211ad2fc281cf77e59110c7abc54bf0c86d480b9be276471dc9d603cee98cfdab3e9fcfb703793560549ea4450fa7b33fb9169c44b4d25fb9c457f49791cd3da03eac96095813c105132ccda4e63e49228cd23d8a1f37856f142d93b90db09f82af89258c63aab8047a80c036c9357ea2046f8dc6354f0c5295f342bb417d3cfeb0b1fd33622c29e14cbbd92e1363c65ebd4504b7512329b9670e32e1b2c67a54e7f1a55f8b9f9ea04e8ca3a705e62a3c5e637374afb7aeb6ddea612cde28f01a202d7aa4e34722d27dd3f9b89894d019fd5d4d7119efe3723bba104cb8bb0981e074de3afe200daaaead826cc45f244dbf431afab34efbdf782474d2fd57118f646214934ed99cba3b003e8d67a3836f6f19fc41910ce5163ee3ae99eb84d514eb761e63684ea56f9791d2dd4aac6e6168b948c817f75a222acb0e8cdc03cc4afe8f67157e1a363b7faeff9f172b98913677c5a1dd085e9ee4c22052c1af58193116673dcd3bfc5f34b855dcc6c77885649e9e71f43d4aea0f4b72ca7eda0578ba13d31a658d2d060a9a66ff69ed1be7997a2fb1d2723d38f9bfabe18f8e7b3cda906e4e9b5e942c8eaeb296070ebfd364947a940cc978bed66b37749e6d5dcd7be8c494440e2b84cecfefb98c0bedfb3c41e3359d2cd7197fbe720c48aa6c6b6465c1ee63e3569c2adc744491370b7f7826fe0b77a1d19d64101d032b918106b42d2ef73747e5601fe4ba50f23ede521f031a817d15294a43722e8378784b6db0cf1ba9e8ae911d9201b9ce9cc3019c6f5c27cb98da26144b64225a7c932b30f761e78a2d59a1d8b83ec6344a2f6dd47e765706d00bf4a79a6a926c3ba91d812c8f2c797ab1796709e5d16856778293529f0286d015c3b5399619642a333e9e593d6e3f5353994208e9e6a332851d7f652522a928b917e27e2d6d42137dfe2ebfa6fb1c67b26c0254528685f7ebdbe315a68eaa2da769e8a9f42d3e60007c71330926b2c0012d83ead4e4fd1ed872ccd1972201d2b027f3545ac2d30cd78bc1d740feccbc6fc2a0446c6e30eac51f5a69098aa2d447f2085b4e4e4b92ccc26921d2de478518cd090ce267aea2d27ada57fd88b4976d89fb843cdccf49a76ca2679e6801bfa7fb031896fb50629704b9923936bb5dd385311121cadfb11995e59b73034cf67ed03ab813867648d025828087e949a9afd16b95d72d99b1edca257aac132ffb7a0709aed5a9c0ff05fb0f2bbf28409eed7b5f5801be964ced019e1cb7851d3851f10290674e19ffb008b301c4acf641a2bb14216e1d69cabf52b5ef227496b0f30799a855d117fad3744a6fa33503ea798b52ddd7ee5426609dbfcd3f0c13b164d6c051f7ed4a119719a712e388d328402081ff1354b554d2c237afed3b151c4ba8e9f4bdeb8499a3066e26bbc69e8af089dec71731d1dc529eab17ef7374734c0fe475494c83836bdd34a03b9bc89914716061bfb98ec6e61c3ed4438edcaf25243c647086b9ea7018b0d9a8a0b00cecb00abde2498d69c2336101a772cbe4f571523f51bd05882cdf358b849cc140aa1faf22423a12851ce0e33fd48975a4959fa5c5fe418c93908191ab6e741b77bfe02cbd698ee795c466d615619e6441382c6eac01834ee9ab73cea80bbe235c78da91bd79b6f82f899785d68700d393e675c2224d6b7a1ad21320495679adaed70167b50866713a53109db7b6f7d81304ecdfd83b319b1ef248306b45ad29e7ddcc863dac56048b5d69ea175011f7614c00a86a863cde1872a8932878b9ac7e1ac5bda4997b72064f0cd75f4c814e034de11acb9013cf7ea926b4e7eaace070c7ba2188efad2e431e1223d45dd05c4d8403c2e45cee6413ecbe7527e873e455c4e610a61839aacc0bd56d2483e78f298b66a478eb2f558cbafca86be847baeb02c5b216c8cd88fea4df249b09e670a20703abac24b0a91abc4a5646601442ba10becfd30993880051d07f56a05a9379e7a8e6befee3f22faa106398f7706006e42e9be1ef89d25c272f11a95095c587d713732284de9dbd3c7217b0689e21d8eb0ff69668").unwrap()
@@ -111,14 +115,17 @@ mod mldsa_tests {
111115
assert_ne!(sk, MLDSA87PrivateKey::from_bytes(&bytes).unwrap());
112116
}
113117

114-
118+
/// Tests that no private data is displayed
119+
// TODO: add the same tests to the core ML-DSA tests on vectors and polynomials
115120
#[test]
116-
fn core_framework_tests() {
117-
let tf = TestFrameworkSignatureKeys::new();
121+
fn debug_fmt_tests() {
122+
let (pk, sk) = MLDSA44::keygen().unwrap();
118123

119-
tf.test_public_keys::<MLDSA44PublicKey, MLDSA44PrivateKey, MLDSA44, MLDSA44_PK_LEN, MLDSA44_SK_LEN>();
120-
tf.test_public_keys::<MLDSA65PublicKey, MLDSA65PrivateKey, MLDSA65, MLDSA65_PK_LEN, MLDSA65_SK_LEN>();
121-
tf.test_public_keys::<MLDSA87PublicKey, MLDSA87PrivateKey, MLDSA87, MLDSA87_PK_LEN, MLDSA87_SK_LEN>();
124+
let pk_str = format!("{:?}", pk);
125+
assert!(pk_str.contains("MLDSAPublicKey { alg: ML-DSA-44, pub_key_hash (tr):"));
126+
127+
let sk_str = format!("{:?}", sk);
128+
assert!(sk_str.contains("MLDSAPrivateKey { alg: ML-DSA-44, pub_key_hash (tr):"));
122129
}
123130

124131
}

0 commit comments

Comments
 (0)