001: package org.bouncycastle.crypto.test;
002:
003: import org.bouncycastle.crypto.BlockCipher;
004: import org.bouncycastle.crypto.engines.AESFastEngine;
005: import org.bouncycastle.crypto.params.KeyParameter;
006: import org.bouncycastle.crypto.params.ParametersWithIV;
007: import org.bouncycastle.util.encoders.Hex;
008: import org.bouncycastle.util.test.SimpleTest;
009:
010: /**
011: * Test vectors from the NIST standard tests and Brian Gladman's vector set
012: * <a href="http://fp.gladman.plus.com/cryptography_technology/rijndael/">
013: * http://fp.gladman.plus.com/cryptography_technology/rijndael/</a>
014: */
015: public class AESFastTest extends CipherTest {
016: static SimpleTest[] tests = {
017: new BlockCipherVectorTest(
018: 0,
019: new AESFastEngine(),
020: new KeyParameter(Hex
021: .decode("80000000000000000000000000000000")),
022: "00000000000000000000000000000000",
023: "0EDD33D3C621E546455BD8BA1418BEC8"),
024: new BlockCipherVectorTest(
025: 1,
026: new AESFastEngine(),
027: new KeyParameter(Hex
028: .decode("00000000000000000000000000000080")),
029: "00000000000000000000000000000000",
030: "172AEAB3D507678ECAF455C12587ADB7"),
031: new BlockCipherMonteCarloTest(
032: 2,
033: 10000,
034: new AESFastEngine(),
035: new KeyParameter(Hex
036: .decode("00000000000000000000000000000000")),
037: "00000000000000000000000000000000",
038: "C34C052CC0DA8D73451AFE5F03BE297F"),
039: new BlockCipherMonteCarloTest(
040: 3,
041: 10000,
042: new AESFastEngine(),
043: new KeyParameter(Hex
044: .decode("5F060D3716B345C253F6749ABAC10917")),
045: "355F697E8B868B65B25A04E18D782AFA",
046: "ACC863637868E3E068D2FD6E3508454A"),
047: new BlockCipherVectorTest(
048: 4,
049: new AESFastEngine(),
050: new KeyParameter(
051: Hex
052: .decode("000000000000000000000000000000000000000000000000")),
053: "80000000000000000000000000000000",
054: "6CD02513E8D4DC986B4AFE087A60BD0C"),
055: new BlockCipherMonteCarloTest(
056: 5,
057: 10000,
058: new AESFastEngine(),
059: new KeyParameter(
060: Hex
061: .decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")),
062: "F3F6752AE8D7831138F041560631B114",
063: "77BA00ED5412DFF27C8ED91F3C376172"),
064: new BlockCipherVectorTest(
065: 6,
066: new AESFastEngine(),
067: new KeyParameter(
068: Hex
069: .decode("0000000000000000000000000000000000000000000000000000000000000000")),
070: "80000000000000000000000000000000",
071: "DDC6BF790C15760D8D9AEB6F9A75FD4E"),
072: new BlockCipherMonteCarloTest(
073: 7,
074: 10000,
075: new AESFastEngine(),
076: new KeyParameter(
077: Hex
078: .decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")),
079: "C737317FE0846F132B23C8C2A672CE22",
080: "E58B82BFBA53C0040DC610C642121168"),
081: new BlockCipherVectorTest(
082: 8,
083: new AESFastEngine(),
084: new KeyParameter(Hex
085: .decode("80000000000000000000000000000000")),
086: "00000000000000000000000000000000",
087: "0EDD33D3C621E546455BD8BA1418BEC8"),
088: new BlockCipherVectorTest(
089: 9,
090: new AESFastEngine(),
091: new KeyParameter(Hex
092: .decode("00000000000000000000000000000080")),
093: "00000000000000000000000000000000",
094: "172AEAB3D507678ECAF455C12587ADB7"),
095: new BlockCipherMonteCarloTest(
096: 10,
097: 10000,
098: new AESFastEngine(),
099: new KeyParameter(Hex
100: .decode("00000000000000000000000000000000")),
101: "00000000000000000000000000000000",
102: "C34C052CC0DA8D73451AFE5F03BE297F"),
103: new BlockCipherMonteCarloTest(
104: 11,
105: 10000,
106: new AESFastEngine(),
107: new KeyParameter(Hex
108: .decode("5F060D3716B345C253F6749ABAC10917")),
109: "355F697E8B868B65B25A04E18D782AFA",
110: "ACC863637868E3E068D2FD6E3508454A"),
111: new BlockCipherVectorTest(
112: 12,
113: new AESFastEngine(),
114: new KeyParameter(
115: Hex
116: .decode("000000000000000000000000000000000000000000000000")),
117: "80000000000000000000000000000000",
118: "6CD02513E8D4DC986B4AFE087A60BD0C"),
119: new BlockCipherMonteCarloTest(
120: 13,
121: 10000,
122: new AESFastEngine(),
123: new KeyParameter(
124: Hex
125: .decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")),
126: "F3F6752AE8D7831138F041560631B114",
127: "77BA00ED5412DFF27C8ED91F3C376172"),
128: new BlockCipherVectorTest(
129: 14,
130: new AESFastEngine(),
131: new KeyParameter(
132: Hex
133: .decode("0000000000000000000000000000000000000000000000000000000000000000")),
134: "80000000000000000000000000000000",
135: "DDC6BF790C15760D8D9AEB6F9A75FD4E"),
136: new BlockCipherMonteCarloTest(
137: 15,
138: 10000,
139: new AESFastEngine(),
140: new KeyParameter(
141: Hex
142: .decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")),
143: "C737317FE0846F132B23C8C2A672CE22",
144: "E58B82BFBA53C0040DC610C642121168"),
145: new BlockCipherVectorTest(
146: 16,
147: new AESFastEngine(),
148: new KeyParameter(Hex
149: .decode("80000000000000000000000000000000")),
150: "00000000000000000000000000000000",
151: "0EDD33D3C621E546455BD8BA1418BEC8"),
152: new BlockCipherVectorTest(
153: 17,
154: new AESFastEngine(),
155: new KeyParameter(Hex
156: .decode("00000000000000000000000000000080")),
157: "00000000000000000000000000000000",
158: "172AEAB3D507678ECAF455C12587ADB7"),
159: new BlockCipherMonteCarloTest(
160: 18,
161: 10000,
162: new AESFastEngine(),
163: new KeyParameter(Hex
164: .decode("00000000000000000000000000000000")),
165: "00000000000000000000000000000000",
166: "C34C052CC0DA8D73451AFE5F03BE297F"),
167: new BlockCipherMonteCarloTest(
168: 19,
169: 10000,
170: new AESFastEngine(),
171: new KeyParameter(Hex
172: .decode("5F060D3716B345C253F6749ABAC10917")),
173: "355F697E8B868B65B25A04E18D782AFA",
174: "ACC863637868E3E068D2FD6E3508454A"),
175: new BlockCipherVectorTest(
176: 20,
177: new AESFastEngine(),
178: new KeyParameter(
179: Hex
180: .decode("000000000000000000000000000000000000000000000000")),
181: "80000000000000000000000000000000",
182: "6CD02513E8D4DC986B4AFE087A60BD0C"),
183: new BlockCipherMonteCarloTest(
184: 21,
185: 10000,
186: new AESFastEngine(),
187: new KeyParameter(
188: Hex
189: .decode("AAFE47EE82411A2BF3F6752AE8D7831138F041560631B114")),
190: "F3F6752AE8D7831138F041560631B114",
191: "77BA00ED5412DFF27C8ED91F3C376172"),
192: new BlockCipherVectorTest(
193: 22,
194: new AESFastEngine(),
195: new KeyParameter(
196: Hex
197: .decode("0000000000000000000000000000000000000000000000000000000000000000")),
198: "80000000000000000000000000000000",
199: "DDC6BF790C15760D8D9AEB6F9A75FD4E"),
200: new BlockCipherMonteCarloTest(
201: 23,
202: 10000,
203: new AESFastEngine(),
204: new KeyParameter(
205: Hex
206: .decode("28E79E2AFC5F7745FCCABE2F6257C2EF4C4EDFB37324814ED4137C288711A386")),
207: "C737317FE0846F132B23C8C2A672CE22",
208: "E58B82BFBA53C0040DC610C642121168") };
209:
210: private BlockCipher _engine = new AESFastEngine();
211:
212: AESFastTest() {
213: super (tests, new AESFastEngine(),
214: new KeyParameter(new byte[16]));
215: }
216:
217: public String getName() {
218: return "AESFast";
219: }
220:
221: public void performTest() throws Exception {
222: super .performTest();
223:
224: byte[] keyBytes = new byte[16];
225:
226: _engine.init(true, new KeyParameter(keyBytes));
227:
228: //
229: // init tests
230: //
231: try {
232: byte[] dudKey = new byte[6];
233:
234: _engine.init(true, new KeyParameter(dudKey));
235:
236: fail("failed key length check");
237: } catch (IllegalArgumentException e) {
238: // expected
239: }
240:
241: try {
242: byte[] iv = new byte[16];
243:
244: _engine.init(true, new ParametersWithIV(null, iv));
245:
246: fail("failed parameter check");
247: } catch (IllegalArgumentException e) {
248: // expected
249: }
250: }
251:
252: public static void main(String[] args) {
253: runTest(new AESFastTest());
254: }
255: }
|