1
1
package org .bouncycastle .pqc .crypto .test ;
2
2
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
+
4
11
import org .bouncycastle .crypto .AsymmetricCipherKeyPair ;
5
12
import 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 ;
8
19
import org .bouncycastle .pqc .crypto .util .PrivateKeyFactory ;
9
20
import org .bouncycastle .pqc .crypto .util .PrivateKeyInfoFactory ;
10
21
import org .bouncycastle .pqc .crypto .util .PublicKeyFactory ;
11
22
import org .bouncycastle .pqc .crypto .util .SubjectPublicKeyInfoFactory ;
12
23
import org .bouncycastle .test .TestResourceFinder ;
13
24
import org .bouncycastle .util .Arrays ;
14
-
15
25
import org .bouncycastle .util .encoders .Hex ;
26
+ import org .bouncycastle .util .test .FixedSecureRandom ;
16
27
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 ;
24
29
25
30
public class MLDSATest extends TestCase
26
31
{
@@ -38,7 +43,6 @@ public void testKeyGen() throws IOException
38
43
MLDSAParameters .ml_dsa_87 ,
39
44
};
40
45
41
- TestSampler sampler = new TestSampler ();
42
46
for (int fileIndex = 0 ; fileIndex != files .length ; fileIndex ++)
43
47
{
44
48
String name = files [fileIndex ];
@@ -64,28 +68,26 @@ public void testKeyGen() throws IOException
64
68
byte [] pk = Hex .decode ((String ) buf .get ("pk" ));
65
69
byte [] sk = Hex .decode ((String ) buf .get ("sk" ));
66
70
71
+ FixedSecureRandom random = new FixedSecureRandom (seed );
67
72
MLDSAParameters parameters = params [fileIndex ];
68
73
69
74
MLDSAKeyPairGenerator kpGen = new MLDSAKeyPairGenerator ();
70
- MLDSAKeyGenerationParameters genParam = new MLDSAKeyGenerationParameters (new SecureRandom (), parameters );
75
+ kpGen .init (new MLDSAKeyGenerationParameters (random , parameters ));
76
+
71
77
//
72
78
// Generate keys and test.
73
79
//
74
- kpGen .init (genParam );
75
- AsymmetricCipherKeyPair kp = kpGen .internalGenerateKeyPair (seed );
80
+ AsymmetricCipherKeyPair kp = kpGen .generateKeyPair ();
76
81
77
82
MLDSAPublicKeyParameters pubParams = (MLDSAPublicKeyParameters ) PublicKeyFactory .createKey (
78
- SubjectPublicKeyInfoFactory .createSubjectPublicKeyInfo (kp .getPublic ()));
83
+ SubjectPublicKeyInfoFactory .createSubjectPublicKeyInfo (kp .getPublic ()));
79
84
MLDSAPrivateKeyParameters privParams = (MLDSAPrivateKeyParameters ) PrivateKeyFactory .createKey (
80
- PrivateKeyInfoFactory .createPrivateKeyInfo (kp .getPrivate ()));
81
-
85
+ PrivateKeyInfoFactory .createPrivateKeyInfo (kp .getPrivate ()));
82
86
83
87
assertTrue (name + ": public key" , Arrays .areEqual (pk , pubParams .getEncoded ()));
84
88
assertTrue (name + ": secret key" , Arrays .areEqual (sk , privParams .getEncoded ()));
85
-
86
89
}
87
90
buf .clear ();
88
-
89
91
continue ;
90
92
}
91
93
@@ -113,7 +115,6 @@ public void testSigGen() throws IOException
113
115
MLDSAParameters .ml_dsa_87 ,
114
116
};
115
117
116
- TestSampler sampler = new TestSampler ();
117
118
for (int fileIndex = 0 ; fileIndex != files .length ; fileIndex ++)
118
119
{
119
120
String name = files [fileIndex ];
@@ -185,7 +186,6 @@ public void testSigVer() throws IOException
185
186
MLDSAParameters .ml_dsa_87 ,
186
187
};
187
188
188
- TestSampler sampler = new TestSampler ();
189
189
for (int fileIndex = 0 ; fileIndex != files .length ; fileIndex ++)
190
190
{
191
191
String name = files [fileIndex ];
0 commit comments