|
1 |
| -//package org.bouncycastle.jce.provider.test; |
| 1 | +/* Adds tests to check for FPs related to RSA/DSA versus EC */ |
2 | 2 |
|
3 | 3 | import java.security.KeyPair;
|
4 | 4 | import java.security.KeyPairGenerator;
|
5 | 5 | import java.security.SecureRandom;
|
6 | 6 | import java.security.Security;
|
7 | 7 | import java.security.Signature;
|
8 | 8 |
|
9 |
| -// import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; |
10 |
| -// import org.bouncycastle.jce.provider.BouncyCastleProvider; |
11 |
| -// import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec; |
12 |
| -// import org.bouncycastle.jce.spec.GOST3410ParameterSpec; |
13 |
| -// import org.bouncycastle.util.encoders.Hex; |
14 |
| -// import org.bouncycastle.util.test.SimpleTest; |
15 |
| - |
16 | 9 | public class SignatureTest
|
17 |
| - //extends SimpleTest |
18 | 10 | {
|
19 |
| - // private static final byte[] DATA = Hex.decode("00000000deadbeefbeefdeadffffffff00000000"); |
20 |
| - |
21 |
| - private void checkSig(KeyPair kp, String name) |
22 |
| - throws Exception |
23 |
| - { |
24 |
| - // Signature sig = Signature.getInstance(name, "BC"); |
25 |
| - |
26 |
| - // sig.initSign(kp.getPrivate()); |
27 |
| - // sig.update(DATA); |
28 |
| - |
29 |
| - // byte[] signature1 = sig.sign(); |
30 |
| - |
31 |
| - // sig.update(DATA); |
32 |
| - |
33 |
| - // byte[] signature2 = sig.sign(); |
34 |
| - |
35 |
| - // sig.initVerify(kp.getPublic()); |
36 |
| - |
37 |
| - // sig.update(DATA); |
38 |
| - // if (!sig.verify(signature1)) |
39 |
| - // { |
40 |
| - // fail("did not verify: " + name); |
41 |
| - // } |
42 |
| - |
43 |
| - // // After verify, should be reusable as if we are after initVerify |
44 |
| - // sig.update(DATA); |
45 |
| - // if (!sig.verify(signature1)) |
46 |
| - // { |
47 |
| - // fail("second verify failed: " + name); |
48 |
| - // } |
49 |
| - |
50 |
| - // sig.update(DATA); |
51 |
| - // if (!sig.verify(signature2)) |
52 |
| - // { |
53 |
| - // fail("second verify failed (2): " + name); |
54 |
| - // } |
55 |
| - } |
56 | 11 |
|
57 | 12 | public void performTest()
|
58 | 13 | throws Exception
|
59 | 14 | {
|
60 | 15 | KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
|
61 |
| - |
62 | 16 | kpGen.initialize(2048); // Safe
|
63 |
| - |
64 | 17 | KeyPair kp = kpGen.generateKeyPair();
|
65 | 18 |
|
66 |
| - checkSig(kp, "SHA1withRSA"); |
67 |
| - checkSig(kp, "SHA224withRSA"); |
68 |
| - checkSig(kp, "SHA256withRSA"); |
69 |
| - checkSig(kp, "SHA384withRSA"); |
70 |
| - checkSig(kp, "SHA512withRSA"); |
71 |
| - |
72 |
| - checkSig(kp, "SHA3-224withRSA"); |
73 |
| - checkSig(kp, "SHA3-256withRSA"); |
74 |
| - checkSig(kp, "SHA3-384withRSA"); |
75 |
| - checkSig(kp, "SHA3-512withRSA"); |
76 |
| - |
77 |
| - checkSig(kp, "MD2withRSA"); |
78 |
| - checkSig(kp, "MD4withRSA"); |
79 |
| - checkSig(kp, "MD5withRSA"); |
80 |
| - checkSig(kp, "RIPEMD160withRSA"); |
81 |
| - checkSig(kp, "RIPEMD128withRSA"); |
82 |
| - checkSig(kp, "RIPEMD256withRSA"); |
83 |
| - |
84 |
| - checkSig(kp, "SHA1withRSAandMGF1"); |
85 |
| - checkSig(kp, "SHA1withRSAandMGF1"); |
86 |
| - checkSig(kp, "SHA224withRSAandMGF1"); |
87 |
| - checkSig(kp, "SHA256withRSAandMGF1"); |
88 |
| - checkSig(kp, "SHA384withRSAandMGF1"); |
89 |
| - checkSig(kp, "SHA512withRSAandMGF1"); |
90 |
| - |
91 |
| - checkSig(kp, "SHA1withRSAandSHAKE128"); |
92 |
| - checkSig(kp, "SHA1withRSAandSHAKE128"); |
93 |
| - checkSig(kp, "SHA224withRSAandSHAKE128"); |
94 |
| - checkSig(kp, "SHA256withRSAandSHAKE128"); |
95 |
| - checkSig(kp, "SHA384withRSAandSHAKE128"); |
96 |
| - checkSig(kp, "SHA512withRSAandSHAKE128"); |
97 |
| - |
98 |
| - checkSig(kp, "SHA1withRSAandSHAKE256"); |
99 |
| - checkSig(kp, "SHA1withRSAandSHAKE256"); |
100 |
| - checkSig(kp, "SHA224withRSAandSHAKE256"); |
101 |
| - checkSig(kp, "SHA256withRSAandSHAKE256"); |
102 |
| - checkSig(kp, "SHA384withRSAandSHAKE256"); |
103 |
| - checkSig(kp, "SHA512withRSAandSHAKE256"); |
104 |
| - |
105 |
| - checkSig(kp, "SHAKE128withRSAPSS"); |
106 |
| - checkSig(kp, "SHAKE256withRSAPSS"); |
107 |
| - |
108 |
| - checkSig(kp, "SHA1withRSA/ISO9796-2"); |
109 |
| - checkSig(kp, "MD5withRSA/ISO9796-2"); |
110 |
| - checkSig(kp, "RIPEMD160withRSA/ISO9796-2"); |
111 |
| - |
112 |
| -// checkSig(kp, "SHA1withRSA/ISO9796-2PSS"); |
113 |
| -// checkSig(kp, "MD5withRSA/ISO9796-2PSS"); |
114 |
| -// checkSig(kp, "RIPEMD160withRSA/ISO9796-2PSS"); |
115 |
| - |
116 |
| - checkSig(kp, "RIPEMD128withRSA/X9.31"); |
117 |
| - checkSig(kp, "RIPEMD160withRSA/X9.31"); |
118 |
| - checkSig(kp, "SHA1withRSA/X9.31"); |
119 |
| - checkSig(kp, "SHA224withRSA/X9.31"); |
120 |
| - checkSig(kp, "SHA256withRSA/X9.31"); |
121 |
| - checkSig(kp, "SHA384withRSA/X9.31"); |
122 |
| - checkSig(kp, "SHA512withRSA/X9.31"); |
123 |
| - checkSig(kp, "WhirlpoolwithRSA/X9.31"); |
124 |
| - |
125 | 19 | kpGen = KeyPairGenerator.getInstance("DSA", "BC");
|
126 |
| - |
127 | 20 | kpGen.initialize(2048); // Safe
|
128 |
| - |
129 | 21 | kp = kpGen.generateKeyPair();
|
130 | 22 |
|
131 |
| - checkSig(kp, "SHA1withDSA"); |
132 |
| - checkSig(kp, "SHA224withDSA"); |
133 |
| - checkSig(kp, "SHA256withDSA"); |
134 |
| - checkSig(kp, "SHA384withDSA"); |
135 |
| - checkSig(kp, "SHA512withDSA"); |
136 |
| - checkSig(kp, "NONEwithDSA"); |
137 |
| - |
138 | 23 | kpGen = KeyPairGenerator.getInstance("EC", "BC");
|
139 |
| - |
140 | 24 | kpGen.initialize(256); // Safe
|
141 |
| - |
142 | 25 | kp = kpGen.generateKeyPair();
|
143 | 26 |
|
144 |
| - checkSig(kp, "SHA1withECDSA"); |
145 |
| - checkSig(kp, "SHA224withECDSA"); |
146 |
| - checkSig(kp, "SHA256withECDSA"); |
147 |
| - checkSig(kp, "SHA384withECDSA"); |
148 |
| - checkSig(kp, "SHA512withECDSA"); |
149 |
| - checkSig(kp, "RIPEMD160withECDSA"); |
150 |
| - checkSig(kp, "SHAKE128withECDSA"); |
151 |
| - checkSig(kp, "SHAKE256withECDSA"); |
152 |
| - |
153 | 27 | kpGen = KeyPairGenerator.getInstance("EC", "BC");
|
154 |
| - |
155 | 28 | kpGen.initialize(521); // Safe
|
156 |
| - |
157 | 29 | kp = kpGen.generateKeyPair();
|
158 |
| - |
159 |
| - checkSig(kp, "SHA1withECNR"); |
160 |
| - checkSig(kp, "SHA224withECNR"); |
161 |
| - checkSig(kp, "SHA256withECNR"); |
162 |
| - checkSig(kp, "SHA384withECNR"); |
163 |
| - checkSig(kp, "SHA512withECNR"); |
164 |
| - |
165 |
| - // kpGen = KeyPairGenerator.getInstance("ECGOST3410", "BC"); |
166 |
| - |
167 |
| - // kpGen.initialize(new ECNamedCurveGenParameterSpec("GostR3410-2001-CryptoPro-A"), new SecureRandom()); |
168 |
| - |
169 |
| - // kp = kpGen.generateKeyPair(); |
170 |
| - |
171 |
| - // checkSig(kp, "GOST3411withECGOST3410"); |
172 |
| - |
173 |
| - // kpGen = KeyPairGenerator.getInstance("GOST3410", "BC"); |
174 |
| - |
175 |
| - // GOST3410ParameterSpec gost3410P = new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()); |
176 |
| - |
177 |
| - // kpGen.initialize(gost3410P); |
178 |
| - |
179 |
| - // kp = kpGen.generateKeyPair(); |
180 |
| - |
181 |
| - // checkSig(kp, "GOST3411withGOST3410"); |
182 |
| - } |
183 |
| - |
184 |
| - public String getName() |
185 |
| - { |
186 |
| - return "SigNameTest"; |
187 | 30 | }
|
188 |
| - |
189 |
| - // public static void main( |
190 |
| - // String[] args) |
191 |
| - // { |
192 |
| - // //Security.addProvider(new BouncyCastleProvider()); |
193 |
| - |
194 |
| - // //runTest(new SignatureTest()); |
195 |
| - // } |
196 | 31 | }
|
0 commit comments