Source Code Cross Referenced for ISO9796Test.java in  » Security » Bouncy-Castle » org » bouncycastle » crypto » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » Bouncy Castle » org.bouncycastle.crypto.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.crypto.test;
002:
003:        import org.bouncycastle.crypto.Digest;
004:        import org.bouncycastle.crypto.digests.RIPEMD128Digest;
005:        import org.bouncycastle.crypto.digests.RIPEMD160Digest;
006:        import org.bouncycastle.crypto.digests.SHA1Digest;
007:        import org.bouncycastle.crypto.encodings.ISO9796d1Encoding;
008:        import org.bouncycastle.crypto.engines.RSAEngine;
009:        import org.bouncycastle.crypto.params.ParametersWithSalt;
010:        import org.bouncycastle.crypto.params.RSAKeyParameters;
011:        import org.bouncycastle.crypto.signers.ISO9796d2PSSSigner;
012:        import org.bouncycastle.crypto.signers.ISO9796d2Signer;
013:        import org.bouncycastle.util.encoders.Hex;
014:        import org.bouncycastle.util.test.SimpleTest;
015:
016:        import java.math.BigInteger;
017:
018:        /**
019:         * test vectors from ISO 9796-1 and ISO 9796-2 edition 1.
020:         */
021:        public class ISO9796Test extends SimpleTest {
022:            static BigInteger mod1 = new BigInteger(
023:                    "0100000000000000000000000000000000bba2d15dbb303c8a21c5ebbcbae52b7125087920dd7cdf358ea119fd66fb064012ec8ce692f0a0b8e8321b041acd40b7",
024:                    16);
025:
026:            static BigInteger pub1 = new BigInteger("03", 16);
027:
028:            static BigInteger pri1 = new BigInteger(
029:                    "2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac9f0783a49dd5f6c5af651f4c9d0dc9281c96a3f16a85f9572d7cc3f2d0f25a9dbf1149e4cdc32273faadd3fda5dcda7",
030:                    16);
031:
032:            static BigInteger mod2 = new BigInteger(
033:                    "ffffff7fa27087c35ebead78412d2bdffe0301edd494df13458974ea89b364708f7d0f5a00a50779ddf9f7d4cb80b8891324da251a860c4ec9ef288104b3858d",
034:                    16);
035:
036:            static BigInteger pub2 = new BigInteger("03", 16);
037:
038:            static BigInteger pri2 = new BigInteger(
039:                    "2aaaaa9545bd6bf5e51fc7940adcdca5550080524e18cfd88b96e8d1c19de6121b13fac0eb0495d47928e047724d91d1740f6968457ce53ec8e24c9362ce84b5",
040:                    16);
041:
042:            static byte msg1[] = Hex.decode("0cbbaa99887766554433221100");
043:
044:            //
045:            // you'll need to see the ISO 9796 to make sense of this
046:            //
047:            static byte sig1[] = mod1
048:                    .subtract(
049:                            new BigInteger(
050:                                    "309f873d8ded8379490f6097eaafdabc137d3ebfd8f25ab5f138d56a719cdc526bdd022ea65dabab920a81013a85d092e04d3e421caab717c90d89ea45a8d23a",
051:                                    16)).toByteArray();
052:
053:            static byte msg2[] = Hex
054:                    .decode("fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210");
055:
056:            static byte sig2[] = new BigInteger(
057:                    "319bb9becb49f3ed1bca26d0fcf09b0b0a508e4d0bd43b350f959b72cd25b3af47d608fdcd248eada74fbe19990dbeb9bf0da4b4e1200243a14e5cab3f7e610c",
058:                    16).toByteArray();
059:
060:            static byte msg3[] = Hex.decode("0112233445566778899aabbccd");
061:
062:            static byte sig3[] = mod2
063:                    .subtract(
064:                            new BigInteger(
065:                                    "58e59ffb4b1fb1bcdbf8d1fe9afa3730c78a318a1134f5791b7313d480ff07ac319b068edf8f212945cb09cf33df30ace54f4a063fcca0b732f4b662dc4e2454",
066:                                    16)).toByteArray();
067:
068:            //
069:            // ISO 9796-2
070:            //
071:            static BigInteger mod3 = new BigInteger(
072:                    "ffffffff78f6c55506c59785e871211ee120b0b5dd644aa796d82413a47b24573f1be5745b5cd9950f6b389b52350d4e01e90009669a8720bf265a2865994190a661dea3c7828e2e7ca1b19651adc2d5",
073:                    16);
074:
075:            static BigInteger pub3 = new BigInteger("03", 16);
076:
077:            static BigInteger pri3 = new BigInteger(
078:                    "2aaaaaaa942920e38120ee965168302fd0301d73a4e60c7143ceb0adf0bf30b9352f50e8b9e4ceedd65343b2179005b2f099915e4b0c37e41314bb0821ad8330d23cba7f589e0f129b04c46b67dfce9d",
079:                    16);
080:
081:            static BigInteger mod4 = new BigInteger(
082:                    "FFFFFFFF45f1903ebb83d4d363f70dc647b839f2a84e119b8830b2dec424a1ce0c9fd667966b81407e89278283f27ca8857d40979407fc6da4cc8a20ecb4b8913b5813332409bc1f391a94c9c328dfe46695daf922259174544e2bfbe45cc5cd",
083:                    16);
084:            static BigInteger pub4 = new BigInteger("02", 16);
085:            static BigInteger pri4 = new BigInteger(
086:                    "1fffffffe8be3207d7707a9a6c7ee1b8c8f7073e5509c2337106165bd8849439c193faccf2cd70280fd124f0507e4f94cb66447680c6b87b6599d1b61c8f3600854a618262e9c1cb1438e485e47437be036d94b906087a61ee74ab0d9a1accd8",
087:                    16);
088:
089:            static byte msg4[] = Hex
090:                    .decode("6162636462636465636465666465666765666768666768696768696a68696a6b696a6b6c6a6b6c6d6b6c6d6e6c6d6e6f6d6e6f706e6f7071");
091:            static byte sig4[] = Hex
092:                    .decode("374695b7ee8b273925b4656cc2e008d41463996534aa5aa5afe72a52ffd84e118085f8558f36631471d043ad342de268b94b080bee18a068c10965f581e7f32899ad378835477064abed8ef3bd530fce");
093:
094:            static byte msg5[] = Hex
095:                    .decode("fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210");
096:            static byte sig5[] = Hex
097:                    .decode("5cf9a01854dbacaec83aae8efc563d74538192e95466babacd361d7c86000fe42dcb4581e48e4feb862d04698da9203b1803b262105104d510b365ee9c660857ba1c001aa57abfd1c8de92e47c275cae");
098:
099:            //
100:            // scheme 2 data
101:            //
102:            static BigInteger mod6 = new BigInteger(
103:                    "b259d2d6e627a768c94be36164c2d9fc79d97aab9253140e5bf17751197731d6f7540d2509e7b9ffee0a70a6e26d56e92d2edd7f85aba85600b69089f35f6bdbf3c298e05842535d9f064e6b0391cb7d306e0a2d20c4dfb4e7b49a9640bdea26c10ad69c3f05007ce2513cee44cfe01998e62b6c3637d3fc0391079b26ee36d5",
104:                    16);
105:            static BigInteger pub6 = new BigInteger("11", 16);
106:            static BigInteger pri6 = new BigInteger(
107:                    "92e08f83cc9920746989ca5034dcb384a094fb9c5a6288fcc4304424ab8f56388f72652d8fafc65a4b9020896f2cde297080f2a540e7b7ce5af0b3446e1258d1dd7f245cf54124b4c6e17da21b90a0ebd22605e6f45c9f136d7a13eaac1c0f7487de8bd6d924972408ebb58af71e76fd7b012a8d0e165f3ae2e5077a8648e619",
108:                    16);
109:
110:            static byte sig6[] = new BigInteger(
111:                    "0073FEAF13EB12914A43FE635022BB4AB8188A8F3ABD8D8A9E4AD6C355EE920359C7F237AE36B1212FE947F676C68FE362247D27D1F298CA9302EB21F4A64C26CE44471EF8C0DFE1A54606F0BA8E63E87CDACA993BFA62973B567473B4D38FAE73AB228600934A9CC1D3263E632E21FD52D2B95C5F7023DA63DE9509C01F6C7BBC",
112:                    16).modPow(pri6, mod6).toByteArray();
113:
114:            static byte msg7[] = Hex
115:                    .decode("6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F70716F70717270717273");
116:            static byte sig7[] = new BigInteger(
117:                    "296B06224010E1EC230D4560A5F88F03550AAFCE31C805CE81E811E5E53E5F71AE64FC2A2A486B193E87972D90C54B807A862F21A21919A43ECF067240A8C8C641DE8DCDF1942CF790D136728FFC0D98FB906E7939C1EC0E64C0E067F0A7443D6170E411DF91F797D1FFD74009C4638462E69D5923E7433AEC028B9A90E633CC",
118:                    16).modPow(pri6, mod6).toByteArray();
119:
120:            static byte msg8[] = Hex
121:                    .decode("FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA98");
122:            static byte sig8[] = new BigInteger(
123:                    "01402B29ABA104079677CE7FC3D5A84DB24494D6F9508B4596484F5B3CC7E8AFCC4DDE7081F21CAE9D4F94D6D2CCCB43FCEDA0988FFD4EF2EAE72CFDEB4A2638F0A34A0C49664CD9DB723315759D758836C8BA26AC4348B66958AC94AE0B5A75195B57ABFB9971E21337A4B517F2E820B81F26BCE7C66F48A2DB12A8F3D731CC",
124:                    16).modPow(pri6, mod6).toByteArray();
125:
126:            static byte msg9[] = Hex
127:                    .decode("6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F70716F707172707172737172737472737475737475767475767775767778767778797778797A78797A61797A61627A6162636162636462636465");
128:            static byte sig9[] = new BigInteger(
129:                    "6F2BB97571FE2EF205B66000E9DD06656655C1977F374E8666D636556A5FEEEEAF645555B25F45567C4EE5341F96FED86508C90A9E3F11B26E8D496139ED3E55ECE42860A6FB3A0817DAFBF13019D93E1D382DA07264FE99D9797D2F0B7779357CA7E74EE440D8855B7DDF15F000AC58EE3FFF144845E771907C0C83324A6FBC",
130:                    16).modPow(pri6, mod6).toByteArray();
131:
132:            public String getName() {
133:                return "ISO9796";
134:            }
135:
136:            private boolean isSameAs(byte[] a, int off, byte[] b) {
137:                if ((a.length - off) != b.length) {
138:                    return false;
139:                }
140:
141:                for (int i = 0; i != b.length; i++) {
142:                    if (a[i + off] != b[i]) {
143:                        return false;
144:                    }
145:                }
146:
147:                return true;
148:            }
149:
150:            private void doTest1() throws Exception {
151:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
152:                        mod1, pub1);
153:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
154:                        mod1, pri1);
155:                RSAEngine rsa = new RSAEngine();
156:                byte[] data;
157:
158:                //
159:                // ISO 9796-1 - public encrypt, private decrypt
160:                //
161:                ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa);
162:
163:                eng.init(true, privParameters);
164:
165:                eng.setPadBits(4);
166:
167:                data = eng.processBlock(msg1, 0, msg1.length);
168:
169:                eng.init(false, pubParameters);
170:
171:                if (!areEqual(sig1, data)) {
172:                    fail("failed ISO9796-1 generation Test 1");
173:                }
174:
175:                data = eng.processBlock(data, 0, data.length);
176:
177:                if (!areEqual(msg1, data)) {
178:                    fail("failed ISO9796-1 retrieve Test 1");
179:                }
180:            }
181:
182:            private void doTest2() throws Exception {
183:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
184:                        mod1, pub1);
185:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
186:                        mod1, pri1);
187:                RSAEngine rsa = new RSAEngine();
188:                byte[] data;
189:
190:                //
191:                // ISO 9796-1 - public encrypt, private decrypt
192:                //
193:                ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa);
194:
195:                eng.init(true, privParameters);
196:
197:                data = eng.processBlock(msg2, 0, msg2.length);
198:
199:                eng.init(false, pubParameters);
200:
201:                if (!isSameAs(data, 1, sig2)) {
202:                    fail("failed ISO9796-1 generation Test 2");
203:                }
204:
205:                data = eng.processBlock(data, 0, data.length);
206:
207:                if (!areEqual(msg2, data)) {
208:                    fail("failed ISO9796-1 retrieve Test 2");
209:                }
210:            }
211:
212:            public void doTest3() throws Exception {
213:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
214:                        mod2, pub2);
215:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
216:                        mod2, pri2);
217:                RSAEngine rsa = new RSAEngine();
218:                byte[] data;
219:
220:                //
221:                // ISO 9796-1 - public encrypt, private decrypt
222:                //
223:                ISO9796d1Encoding eng = new ISO9796d1Encoding(rsa);
224:
225:                eng.init(true, privParameters);
226:
227:                eng.setPadBits(4);
228:
229:                data = eng.processBlock(msg3, 0, msg3.length);
230:
231:                eng.init(false, pubParameters);
232:
233:                if (!isSameAs(sig3, 1, data)) {
234:                    fail("failed ISO9796-1 generation Test 3");
235:                }
236:
237:                data = eng.processBlock(data, 0, data.length);
238:
239:                if (!isSameAs(msg3, 0, data)) {
240:                    fail("failed ISO9796-1 retrieve Test 3");
241:                }
242:            }
243:
244:            public void doTest4() throws Exception {
245:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
246:                        mod3, pub3);
247:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
248:                        mod3, pri3);
249:                RSAEngine rsa = new RSAEngine();
250:                byte[] data;
251:
252:                //
253:                // ISO 9796-2 - Signing
254:                //
255:                ISO9796d2Signer eng = new ISO9796d2Signer(rsa,
256:                        new RIPEMD128Digest());
257:
258:                eng.init(true, privParameters);
259:
260:                eng.update(msg4[0]);
261:                eng.update(msg4, 1, msg4.length - 1);
262:
263:                data = eng.generateSignature();
264:
265:                eng.init(false, pubParameters);
266:
267:                if (!isSameAs(sig4, 0, data)) {
268:                    fail("failed ISO9796-2 generation Test 4");
269:                }
270:
271:                eng.update(msg4[0]);
272:                eng.update(msg4, 1, msg4.length - 1);
273:
274:                if (!eng.verifySignature(sig4)) {
275:                    fail("failed ISO9796-2 verify Test 4");
276:                }
277:            }
278:
279:            public void doTest5() throws Exception {
280:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
281:                        mod3, pub3);
282:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
283:                        mod3, pri3);
284:                RSAEngine rsa = new RSAEngine();
285:                byte[] data;
286:
287:                //
288:                // ISO 9796-2 - Signing
289:                //
290:                ISO9796d2Signer eng = new ISO9796d2Signer(rsa,
291:                        new RIPEMD160Digest(), true);
292:
293:                eng.init(true, privParameters);
294:
295:                eng.update(msg5[0]);
296:                eng.update(msg5, 1, msg5.length - 1);
297:
298:                data = eng.generateSignature();
299:
300:                eng.init(false, pubParameters);
301:
302:                if (!isSameAs(sig5, 0, data)) {
303:                    fail("failed ISO9796-2 generation Test 5");
304:                }
305:
306:                eng.update(msg5[0]);
307:                eng.update(msg5, 1, msg5.length - 1);
308:
309:                if (!eng.verifySignature(sig5)) {
310:                    fail("failed ISO9796-2 verify Test 5");
311:                }
312:            }
313:
314:            //
315:            // against a zero length string
316:            //
317:            public void doTest6() throws Exception {
318:                byte[] salt = Hex
319:                        .decode("61DF870C4890FE85D6E3DD87C3DCE3723F91DB49");
320:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
321:                        mod6, pub6);
322:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
323:                        mod6, pri6);
324:                ParametersWithSalt sigParameters = new ParametersWithSalt(
325:                        privParameters, salt);
326:                RSAEngine rsa = new RSAEngine();
327:                byte[] data;
328:
329:                //
330:                // ISO 9796-2 - PSS Signing
331:                //
332:                ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa,
333:                        new RIPEMD160Digest(), 20, true);
334:
335:                eng.init(true, sigParameters);
336:
337:                data = eng.generateSignature();
338:
339:                eng.init(false, pubParameters);
340:
341:                if (!isSameAs(sig6, 1, data)) {
342:                    fail("failed ISO9796-2 generation Test 6");
343:                }
344:
345:                if (!eng.verifySignature(data)) {
346:                    fail("failed ISO9796-2 verify Test 6");
347:                }
348:            }
349:
350:            public void doTest7() throws Exception {
351:                byte[] salt = new byte[0];
352:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
353:                        mod6, pub6);
354:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
355:                        mod6, pri6);
356:                ParametersWithSalt sigParameters = new ParametersWithSalt(
357:                        privParameters, salt);
358:                RSAEngine rsa = new RSAEngine();
359:                byte[] data;
360:
361:                //
362:                // ISO 9796-2 - PSS Signing
363:                //
364:                ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa,
365:                        new SHA1Digest(), 0, false);
366:
367:                eng.init(true, sigParameters);
368:
369:                eng.update(msg7[0]);
370:                eng.update(msg7, 1, msg7.length - 1);
371:
372:                data = eng.generateSignature();
373:
374:                eng.init(false, pubParameters);
375:
376:                if (!isSameAs(sig7, 0, data)) {
377:                    fail("failed ISO9796-2 generation Test 7");
378:                }
379:
380:                eng.update(msg7[0]);
381:                eng.update(msg7, 1, msg7.length - 1);
382:
383:                if (!eng.verifySignature(sig7)) {
384:                    fail("failed ISO9796-2 verify Test 7");
385:                }
386:
387:                if (!isSameAs(msg7, 0, eng.getRecoveredMessage())) {
388:                    fail("failed ISO9796-2 recovery Test 7");
389:                }
390:            }
391:
392:            public void doTest8() throws Exception {
393:                byte[] salt = Hex
394:                        .decode("78E293203CBA1B7F92F05F4D171FF8CA3E738FF8");
395:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
396:                        mod6, pub6);
397:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
398:                        mod6, pri6);
399:                ParametersWithSalt sigParameters = new ParametersWithSalt(
400:                        privParameters, salt);
401:                RSAEngine rsa = new RSAEngine();
402:                byte[] data;
403:
404:                //
405:                // ISO 9796-2 - PSS Signing
406:                //
407:                ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa,
408:                        new RIPEMD160Digest(), 20, false);
409:
410:                eng.init(true, sigParameters);
411:
412:                eng.update(msg8[0]);
413:                eng.update(msg8, 1, msg8.length - 1);
414:
415:                data = eng.generateSignature();
416:
417:                eng.init(false, pubParameters);
418:
419:                if (!isSameAs(sig8, 0, data)) {
420:                    fail("failed ISO9796-2 generation Test 8");
421:                }
422:
423:                eng.update(msg8[0]);
424:                eng.update(msg8, 1, msg8.length - 1);
425:
426:                if (!eng.verifySignature(sig8)) {
427:                    fail("failed ISO9796-2 verify Test 8");
428:                }
429:            }
430:
431:            public void doTest9() throws Exception {
432:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
433:                        mod6, pub6);
434:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
435:                        mod6, pri6);
436:                RSAEngine rsa = new RSAEngine();
437:                byte[] data;
438:
439:                //
440:                // ISO 9796-2 - PSS Signing
441:                //
442:                ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa,
443:                        new RIPEMD160Digest(), 0, true);
444:
445:                eng.init(true, privParameters);
446:
447:                eng.update(msg9[0]);
448:                eng.update(msg9, 1, msg9.length - 1);
449:
450:                data = eng.generateSignature();
451:
452:                eng.init(false, pubParameters);
453:
454:                if (!isSameAs(sig9, 0, data)) {
455:                    fail("failed ISO9796-2 generation Test 9");
456:                }
457:
458:                eng.update(msg9[0]);
459:                eng.update(msg9, 1, msg9.length - 1);
460:
461:                if (!eng.verifySignature(sig9)) {
462:                    fail("failed ISO9796-2 verify Test 9");
463:                }
464:            }
465:
466:            public void doTest10() throws Exception {
467:                BigInteger mod = new BigInteger(
468:                        "B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D",
469:                        16);
470:                BigInteger pubExp = new BigInteger("65537", 10);
471:                BigInteger priExp = new BigInteger(
472:                        "AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41",
473:                        16);
474:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
475:                        mod, pubExp);
476:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
477:                        mod, priExp);
478:                RSAEngine rsa = new RSAEngine();
479:                byte[] data;
480:
481:                //
482:                // ISO 9796-2 - PSS Signing
483:                //
484:                Digest dig = new SHA1Digest();
485:                ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, dig, dig
486:                        .getDigestSize());
487:
488:                //
489:                // as the padding is random this test needs to repeat a few times to
490:                // make sure
491:                //
492:                for (int i = 0; i != 500; i++) {
493:                    eng.init(true, privParameters);
494:
495:                    eng.update(msg9[0]);
496:                    eng.update(msg9, 1, msg9.length - 1);
497:
498:                    data = eng.generateSignature();
499:
500:                    eng.init(false, pubParameters);
501:
502:                    eng.update(msg9[0]);
503:                    eng.update(msg9, 1, msg9.length - 1);
504:
505:                    if (!eng.verifySignature(data)) {
506:                        fail("failed ISO9796-2 verify Test 10");
507:                    }
508:                }
509:            }
510:
511:            public void doTest11() throws Exception {
512:                BigInteger mod = new BigInteger(
513:                        "B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D",
514:                        16);
515:                BigInteger pubExp = new BigInteger("65537", 10);
516:                BigInteger priExp = new BigInteger(
517:                        "AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41",
518:                        16);
519:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
520:                        mod, pubExp);
521:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
522:                        mod, priExp);
523:                RSAEngine rsa = new RSAEngine();
524:                byte[] data;
525:                byte[] m1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
526:                byte[] m2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
527:                byte[] m3 = { 1, 2, 3, 4, 5, 6, 7, 8 };
528:
529:                //
530:                // ISO 9796-2 - PSS Signing
531:                //
532:                Digest dig = new SHA1Digest();
533:                ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, dig, dig
534:                        .getDigestSize());
535:
536:                //
537:                // check message bounds
538:                //
539:                eng.init(true, privParameters);
540:
541:                eng.update(m1, 0, m1.length);
542:
543:                data = eng.generateSignature();
544:
545:                eng.init(false, pubParameters);
546:
547:                eng.update(m2, 0, m2.length);
548:
549:                if (eng.verifySignature(data)) {
550:                    fail("failed ISO9796-2 m2 verify Test 11");
551:                }
552:
553:                eng.init(false, pubParameters);
554:
555:                eng.update(m3, 0, m3.length);
556:
557:                if (eng.verifySignature(data)) {
558:                    fail("failed ISO9796-2 m3 verify Test 11");
559:                }
560:
561:                eng.init(false, pubParameters);
562:
563:                eng.update(m1, 0, m1.length);
564:
565:                if (!eng.verifySignature(data)) {
566:                    fail("failed ISO9796-2 verify Test 11");
567:                }
568:            }
569:
570:            public void doTest12() throws Exception {
571:                BigInteger mod = new BigInteger(
572:                        "B3ABE6D91A4020920F8B3847764ECB34C4EB64151A96FDE7B614DC986C810FF2FD73575BDF8532C06004C8B4C8B64F700A50AEC68C0701ED10E8D211A4EA554D",
573:                        16);
574:                BigInteger pubExp = new BigInteger("65537", 10);
575:                BigInteger priExp = new BigInteger(
576:                        "AEE76AE4716F77C5782838F328327012C097BD67E5E892E75C1356E372CCF8EE1AA2D2CBDFB4DA19F703743F7C0BA42B2D69202BA7338C294D1F8B6A5771FF41",
577:                        16);
578:                RSAKeyParameters pubParameters = new RSAKeyParameters(false,
579:                        mod, pubExp);
580:                RSAKeyParameters privParameters = new RSAKeyParameters(true,
581:                        mod, priExp);
582:                RSAEngine rsa = new RSAEngine();
583:                byte[] data;
584:                byte[] m1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
585:                byte[] m2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
586:                byte[] m3 = { 1, 2, 3, 4, 5, 6, 7, 8 };
587:
588:                //
589:                // ISO 9796-2 - PSS Signing
590:                //
591:                Digest dig = new SHA1Digest();
592:                ISO9796d2Signer eng = new ISO9796d2Signer(rsa, dig);
593:
594:                //
595:                // check message bounds
596:                //
597:                eng.init(true, privParameters);
598:
599:                eng.update(m1, 0, m1.length);
600:
601:                data = eng.generateSignature();
602:
603:                eng.init(false, pubParameters);
604:
605:                eng.update(m2, 0, m2.length);
606:
607:                if (eng.verifySignature(data)) {
608:                    fail("failed ISO9796-2 m2 verify Test 12");
609:                }
610:
611:                eng.init(false, pubParameters);
612:
613:                eng.update(m3, 0, m3.length);
614:
615:                if (eng.verifySignature(data)) {
616:                    fail("failed ISO9796-2 m3 verify Test 12");
617:                }
618:
619:                eng.init(false, pubParameters);
620:
621:                eng.update(m1, 0, m1.length);
622:
623:                if (!eng.verifySignature(data)) {
624:                    fail("failed ISO9796-2 verify Test 12");
625:                }
626:            }
627:
628:            public void performTest() throws Exception {
629:                doTest1();
630:                doTest2();
631:                doTest3();
632:                doTest4();
633:                doTest5();
634:                doTest6();
635:                doTest7();
636:                doTest8();
637:                doTest9();
638:                doTest10();
639:                doTest11();
640:                doTest12();
641:            }
642:
643:            public static void main(String[] args) {
644:                runTest(new ISO9796Test());
645:            }
646:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.