11package org .bouncycastle .pqc .crypto .test ;
22
3- import junit .framework .TestCase ;
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStream ;
6+ import java .io .InputStreamReader ;
7+ import java .security .SecureRandom ;
8+ import java .util .HashMap ;
9+ import java .util .Map ;
10+
411import org .bouncycastle .crypto .AsymmetricCipherKeyPair ;
512import org .bouncycastle .crypto .params .ParametersWithRandom ;
6- import org .bouncycastle .pqc .crypto .crystals .dilithium .*;
7- import org .bouncycastle .pqc .crypto .mldsa .*;
13+ import org .bouncycastle .pqc .crypto .mldsa .MLDSAKeyGenerationParameters ;
14+ import org .bouncycastle .pqc .crypto .mldsa .MLDSAKeyPairGenerator ;
15+ import org .bouncycastle .pqc .crypto .mldsa .MLDSAParameters ;
16+ import org .bouncycastle .pqc .crypto .mldsa .MLDSAPrivateKeyParameters ;
17+ import org .bouncycastle .pqc .crypto .mldsa .MLDSAPublicKeyParameters ;
18+ import org .bouncycastle .pqc .crypto .mldsa .MLDSASigner ;
819import org .bouncycastle .pqc .crypto .util .PrivateKeyFactory ;
920import org .bouncycastle .pqc .crypto .util .PrivateKeyInfoFactory ;
1021import org .bouncycastle .pqc .crypto .util .PublicKeyFactory ;
1122import org .bouncycastle .pqc .crypto .util .SubjectPublicKeyInfoFactory ;
1223import org .bouncycastle .test .TestResourceFinder ;
1324import org .bouncycastle .util .Arrays ;
14-
1525import org .bouncycastle .util .encoders .Hex ;
26+ import org .bouncycastle .util .test .FixedSecureRandom ;
1627
17- import java .io .BufferedReader ;
18- import java .io .IOException ;
19- import java .io .InputStream ;
20- import java .io .InputStreamReader ;
21- import java .security .SecureRandom ;
22- import java .util .HashMap ;
23- import java .util .Map ;
28+ import junit .framework .TestCase ;
2429
2530public class MLDSATest extends TestCase
2631{
@@ -38,7 +43,6 @@ public void testKeyGen() throws IOException
3843 MLDSAParameters .ml_dsa_87 ,
3944 };
4045
41- TestSampler sampler = new TestSampler ();
4246 for (int fileIndex = 0 ; fileIndex != files .length ; fileIndex ++)
4347 {
4448 String name = files [fileIndex ];
@@ -64,28 +68,26 @@ public void testKeyGen() throws IOException
6468 byte [] pk = Hex .decode ((String ) buf .get ("pk" ));
6569 byte [] sk = Hex .decode ((String ) buf .get ("sk" ));
6670
71+ FixedSecureRandom random = new FixedSecureRandom (seed );
6772 MLDSAParameters parameters = params [fileIndex ];
6873
6974 MLDSAKeyPairGenerator kpGen = new MLDSAKeyPairGenerator ();
70- MLDSAKeyGenerationParameters genParam = new MLDSAKeyGenerationParameters (new SecureRandom (), parameters );
75+ kpGen .init (new MLDSAKeyGenerationParameters (random , parameters ));
76+
7177 //
7278 // Generate keys and test.
7379 //
74- kpGen .init (genParam );
75- AsymmetricCipherKeyPair kp = kpGen .internalGenerateKeyPair (seed );
80+ AsymmetricCipherKeyPair kp = kpGen .generateKeyPair ();
7681
7782 MLDSAPublicKeyParameters pubParams = (MLDSAPublicKeyParameters ) PublicKeyFactory .createKey (
78- SubjectPublicKeyInfoFactory .createSubjectPublicKeyInfo (kp .getPublic ()));
83+ SubjectPublicKeyInfoFactory .createSubjectPublicKeyInfo (kp .getPublic ()));
7984 MLDSAPrivateKeyParameters privParams = (MLDSAPrivateKeyParameters ) PrivateKeyFactory .createKey (
80- PrivateKeyInfoFactory .createPrivateKeyInfo (kp .getPrivate ()));
81-
85+ PrivateKeyInfoFactory .createPrivateKeyInfo (kp .getPrivate ()));
8286
8387 assertTrue (name + ": public key" , Arrays .areEqual (pk , pubParams .getEncoded ()));
8488 assertTrue (name + ": secret key" , Arrays .areEqual (sk , privParams .getEncoded ()));
85-
8689 }
8790 buf .clear ();
88-
8991 continue ;
9092 }
9193
@@ -113,7 +115,6 @@ public void testSigGen() throws IOException
113115 MLDSAParameters .ml_dsa_87 ,
114116 };
115117
116- TestSampler sampler = new TestSampler ();
117118 for (int fileIndex = 0 ; fileIndex != files .length ; fileIndex ++)
118119 {
119120 String name = files [fileIndex ];
@@ -185,7 +186,6 @@ public void testSigVer() throws IOException
185186 MLDSAParameters .ml_dsa_87 ,
186187 };
187188
188- TestSampler sampler = new TestSampler ();
189189 for (int fileIndex = 0 ; fileIndex != files .length ; fileIndex ++)
190190 {
191191 String name = files [fileIndex ];
0 commit comments