Source Code Cross Referenced for HCFamilyTest.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.StreamCipher;
004:        import org.bouncycastle.crypto.engines.HC128Engine;
005:        import org.bouncycastle.crypto.engines.HC256Engine;
006:        import org.bouncycastle.crypto.params.KeyParameter;
007:        import org.bouncycastle.crypto.params.ParametersWithIV;
008:        import org.bouncycastle.util.encoders.Hex;
009:        import org.bouncycastle.util.test.SimpleTest;
010:
011:        /**
012:         * HC-128 and HC-256 Tests. Based on the test vectors in the official reference
013:         * papers, respectively:
014:         * 
015:         * http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc128_p3.pdf
016:         * http://www.ecrypt.eu.org/stream/p3ciphers/hc/hc256_p3.pdf
017:         */
018:        public class HCFamilyTest extends SimpleTest {
019:            private static final byte[] MSG = new byte[64];
020:
021:            private static final byte[] K256A = new byte[32];
022:            private static final byte[] K256B = Hex
023:                    .decode("55000000000000000000000000000000"
024:                            + "00000000000000000000000000000000");
025:
026:            private static final byte[] IVA = new byte[32];
027:            private static final byte[] IVB = new byte[] { 0x1 };
028:
029:            private static final byte[] HC256A = Hex
030:                    .decode("8589075b0df3f6d82fc0c5425179b6a6"
031:                            + "3465f053f2891f808b24744e18480b72"
032:                            + "ec2792cdbf4dcfeb7769bf8dfa14aee4"
033:                            + "7b4c50e8eaf3a9c8f506016c81697e32");
034:            private static final byte[] HC256B = Hex
035:                    .decode("bfa2e2afe9ce174f8b05c2feb18bb1d1"
036:                            + "ee42c05f01312b71c61f50dd502a080b"
037:                            + "edfec706633d9241a6dac448af8561ff"
038:                            + "5e04135a9448c4342de7e9f337520bdf");
039:            private static final byte[] HC256C = Hex
040:                    .decode("fe4a401ced5fe24fd19a8f956fc036ae"
041:                            + "3c5aa68823e2abc02f90b3aea8d30e42"
042:                            + "59f03a6c6e39eb448f7579fb70137a5e"
043:                            + "6d10b7d8add0f7cd723423daf575dde6");
044:            private static final byte[] HC256D = Hex
045:                    .decode("c6b6fb99f2ae1440a7d4ca342011694e"
046:                            + "6f36b4be420db05d4745fd907c630695"
047:                            + "5f1d7bda13ae7e36aebc5399733b7f37"
048:                            + "95f34066b601d21f2d8cf830a9c08937");
049:
050:            private static final byte[] K128A = new byte[16];
051:            private static final byte[] K128B = Hex
052:                    .decode("55000000000000000000000000000000");
053:
054:            private static final byte[] HC128A = Hex
055:                    .decode("731500823bfd03a0fb2fd77faa63af0e"
056:                            + "de122fc6a7dc29b662a685278b75ec68"
057:                            + "9036db1e8189600500ade078491fbf9a"
058:                            + "1cdc30136c3d6e2490f664b29cd57102");
059:            private static final byte[] HC128B = Hex
060:                    .decode("c01893d5b7dbe9588f65ec9864176604"
061:                            + "36fc6724c82c6eec1b1c38a7c9b42a95"
062:                            + "323ef1230a6a908bce757b689f14f7bb"
063:                            + "e4cde011aeb5173f89608c94b5cf46ca");
064:            private static final byte[] HC128C = Hex
065:                    .decode("518251a404b4930ab02af9310639f032"
066:                            + "bcb4a47a5722480b2bf99f72cdc0e566"
067:                            + "310f0c56d3cc83e8663db8ef62dfe07f"
068:                            + "593e1790c5ceaa9cab03806fc9a6e5a0");
069:            private static final byte[] HC128D = Hex
070:                    .decode("a4eac0267e4911266a2a384f5c4e1329"
071:                            + "da407fa155e6b1ae05c6fdf3bbdc8a86"
072:                            + "7a699aa01a4dc11763658cccd3e62474"
073:                            + "9cf8236f0131be21c3a51de9d12290de");
074:
075:            public String getName() {
076:                return "HC-128 and HC-256";
077:            }
078:
079:            public void performTest() {
080:                StreamCipher hc = new HC256Engine();
081:                HCTest(hc, "HC-256 - A", K256A, IVA, HC256A);
082:                HCTest(hc, "HC-256 - B", K256A, IVB, HC256B);
083:                HCTest(hc, "HC-256 - C", K256B, IVA, HC256C);
084:                HCTest2(hc, "HC-256 - D", K256A, IVA, HC256D, 0x10000);
085:
086:                hc = new HC128Engine();
087:                HCTest(hc, "HC-128 - A", K128A, IVA, HC128A);
088:                HCTest(hc, "HC-128 - B", K128A, IVB, HC128B);
089:                HCTest(hc, "HC-128 - C", K128B, IVA, HC128C);
090:                HCTest2(hc, "HC-128 - D", K128A, IVA, HC128D, 0x100000);
091:            }
092:
093:            private void HCTest(StreamCipher hc, String test, byte[] key,
094:                    byte[] IV, byte[] expected) {
095:                KeyParameter kp = new KeyParameter(key);
096:                ParametersWithIV ivp = new ParametersWithIV(kp, IV);
097:                hc.init(true, ivp);
098:                for (int i = 0; i < 64; i++) {
099:                    if (hc.returnByte(MSG[i]) != expected[i]) {
100:                        fail(test + " failure");
101:                    }
102:                }
103:            }
104:
105:            private void HCTest2(StreamCipher hc, String test, byte[] key,
106:                    byte[] IV, byte[] expected, int times) {
107:                KeyParameter kp = new KeyParameter(key);
108:                ParametersWithIV ivp = new ParametersWithIV(kp, IV);
109:                hc.init(true, ivp);
110:                byte[] result = new byte[64];
111:                for (int j = 0; j < times; j++) {
112:                    for (int i = 0; i < 64; i++) {
113:                        result[i] = hc.returnByte(result[i]);
114:                    }
115:                }
116:
117:                for (int i = 0; i < 64; i++) {
118:                    if (result[i] != expected[i]) {
119:                        fail(test + " failure at byte " + i);
120:                    }
121:                }
122:            }
123:
124:            public static void main(String[] args) {
125:                runTest(new HCFamilyTest());
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.