author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/gamma/tests/tests/Clipperz/Crypto/AES.html | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto/AES.html') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/tests/tests/Clipperz/Crypto/AES.html | 292 |
1 files changed, 292 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES.html b/frontend/gamma/tests/tests/Clipperz/Crypto/AES.html new file mode 100644 index 0000000..93089b7 --- a/dev/null +++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES.html | |||
@@ -0,0 +1,292 @@ | |||
1 | <!-- | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | --> | ||
28 | |||
29 | <html> | ||
30 | <head> | ||
31 | <title>Clipperz.Crypto.AES_v3 - TEST</title> | ||
32 | |||
33 | <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> | ||
34 | <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script> | ||
35 | <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> | ||
36 | <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> | ||
37 | |||
38 | <script type='text/javascript' src='../../../../js/JSON/json2.js'></script> | ||
39 | |||
40 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> | ||
41 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> | ||
42 | <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> | ||
43 | <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> | ||
44 | |||
45 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script> | ||
46 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script> | ||
47 | |||
48 | </head> | ||
49 | <body> | ||
50 | <pre id="test"> | ||
51 | <script type="text/javascript"> | ||
52 | |||
53 | try { | ||
54 | var block; | ||
55 | var keyValue; | ||
56 | varkey; | ||
57 | var encryptedBlock; | ||
58 | var startTime, endTime; | ||
59 | |||
60 | startTime = new Date(); | ||
61 | |||
62 | keyValue = new Clipperz.ByteArray("0x00010203050607080a0b0c0d0f10111214151617191a1b1c1e1f202123242526"); | ||
63 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
64 | block = new Clipperz.ByteArray("0x834eadfccac7e1b30664b1aba44815ab"); | ||
65 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
66 | is(encryptedBlock.toHexString(), "0x1946dabf6a03a2a2c3d0b05080aed6fc", "Test 1"); | ||
67 | |||
68 | keyValue = new Clipperz.ByteArray("0x28292a2b2d2e2f30323334353738393a3c3d3e3f41424344464748494b4c4d4e"); | ||
69 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
70 | block = new Clipperz.ByteArray("0xd9dc4dba3021b05d67c0518f72b62bf1"); | ||
71 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
72 | is(encryptedBlock.toHexString(), "0x5ed301d747d3cc715445ebdec62f2fb4", "Test 2"); | ||
73 | |||
74 | keyValue = new Clipperz.ByteArray("0x50515253555657585a5b5c5d5f60616264656667696a6b6c6e6f707173747576"); | ||
75 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
76 | block = new Clipperz.ByteArray("0xa291d86301a4a739f7392173aa3c604c"); | ||
77 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
78 | is(encryptedBlock.toHexString(), "0x6585c8f43d13a6beab6419fc5935b9d0", "Test 3"); | ||
79 | |||
80 | keyValue = new Clipperz.ByteArray("0x78797a7b7d7e7f80828384858788898a8c8d8e8f91929394969798999b9c9d9e"); | ||
81 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
82 | block = new Clipperz.ByteArray("0x4264b2696498de4df79788a9f83e9390"); | ||
83 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
84 | is(encryptedBlock.toHexString(), "0x2a5b56a596680fcc0e05f5e0f151ecae", "Test 4"); | ||
85 | |||
86 | keyValue = new Clipperz.ByteArray("0xa0a1a2a3a5a6a7a8aaabacadafb0b1b2b4b5b6b7b9babbbcbebfc0c1c3c4c5c6"); | ||
87 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
88 | block = new Clipperz.ByteArray("0xee9932b3721804d5a83ef5949245b6f6"); | ||
89 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
90 | is(encryptedBlock.toHexString(), "0xf5d6ff414fd2c6181494d20c37f2b8c4", "Test 5"); | ||
91 | |||
92 | keyValue = new Clipperz.ByteArray("0xc8c9cacbcdcecfd0d2d3d4d5d7d8d9dadcdddedfe1e2e3e4e6e7e8e9ebecedee"); | ||
93 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
94 | block = new Clipperz.ByteArray("0xe6248f55c5fdcbca9cbbb01c88a2ea77"); | ||
95 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
96 | is(encryptedBlock.toHexString(), "0x85399c01f59fffb5204f19f8482f00b8", "Test 6"); | ||
97 | |||
98 | keyValue = new Clipperz.ByteArray("0xf0f1f2f3f5f6f7f8fafbfcfdfe01000204050607090a0b0c0e0f101113141516"); | ||
99 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
100 | block = new Clipperz.ByteArray("0xb8358e41b9dff65fd461d55a99266247"); | ||
101 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
102 | is(encryptedBlock.toHexString(), "0x92097b4c88a041ddf98144bc8d22e8e7", "Test 7"); | ||
103 | |||
104 | keyValue = new Clipperz.ByteArray("0x18191a1b1d1e1f20222324252728292a2c2d2e2f31323334363738393b3c3d3e"); | ||
105 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
106 | block = new Clipperz.ByteArray("0xf0e2d72260af58e21e015ab3a4c0d906"); | ||
107 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
108 | is(encryptedBlock.toHexString(), "0x89bd5b73b356ab412aef9f76cea2d65c", "Test 8"); | ||
109 | |||
110 | keyValue = new Clipperz.ByteArray("0x40414243454647484a4b4c4d4f50515254555657595a5b5c5e5f606163646566"); | ||
111 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
112 | block = new Clipperz.ByteArray("0x475b8b823ce8893db3c44a9f2a379ff7"); | ||
113 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
114 | is(encryptedBlock.toHexString(), "0x2536969093c55ff9454692f2fac2f530", "Test 9"); | ||
115 | |||
116 | keyValue = new Clipperz.ByteArray("0x68696a6b6d6e6f70727374757778797a7c7d7e7f81828384868788898b8c8d8e"); | ||
117 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
118 | block = new Clipperz.ByteArray("0x688f5281945812862f5f3076cf80412f"); | ||
119 | encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues())); | ||
120 | is(encryptedBlock.toHexString(), "0x07fc76a872843f3f6e0081ee9396d637", "Test 10"); | ||
121 | |||
122 | //------------------------------------------------------------------------- | ||
123 | // | ||
124 | // Key expansion | ||
125 | // | ||
126 | //------------------------------------------------------------------------- | ||
127 | //test vector: http://en.wikipedia.org/wiki/Rijndael_key_schedule#Test_vectors | ||
128 | |||
129 | keyValue = new Clipperz.ByteArray("0x0000000000000000000000000000000012345678"); | ||
130 | try { | ||
131 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
132 | is(true, false, "Unsupported key size"); | ||
133 | } catch (exception) { | ||
134 | is(true, true, "Unsupported key size"); | ||
135 | } | ||
136 | |||
137 | keyValue = new Clipperz.ByteArray("0x00000000000000000000000000000000"); | ||
138 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
139 | is(key.stretchedKey().toHexString(), | ||
140 | "0x" +"00000000000000000000000000000000" + | ||
141 | "62636363626363636263636362636363" + | ||
142 | "9b9898c9f9fbfbaa9b9898c9f9fbfbaa" + | ||
143 | "90973450696ccffaf2f457330b0fac99" + | ||
144 | "ee06da7b876a1581759e42b27e91ee2b" + | ||
145 | "7f2e2b88f8443e098dda7cbbf34b9290" + | ||
146 | "ec614b851425758c99ff09376ab49ba7" + | ||
147 | "217517873550620bacaf6b3cc61bf09b" + | ||
148 | "0ef903333ba9613897060a04511dfa9f" + | ||
149 | "b1d4d8e28a7db9da1d7bb3de4c664941" + | ||
150 | "b4ef5bcb3e92e21123e951cf6f8f188e", | ||
151 | "Stretched empty key"); | ||
152 | |||
153 | |||
154 | keyValue = new Clipperz.ByteArray("0x0000000000000000000000000000000000000000000000000000000000000000"); | ||
155 | key = new Clipperz.Crypto.AES.Key({key:keyValue}); | ||
156 | is(key.stretchedKey().toHexString(), | ||
157 | "0x" +"00000000000000000000000000000000" + | ||
158 | "00000000000000000000000000000000" + | ||
159 | "62636363626363636263636362636363" + | ||
160 | "aafbfbfbaafbfbfbaafbfbfbaafbfbfb" + | ||
161 | "6f6c6ccf0d0f0fac6f6c6ccf0d0f0fac" + | ||
162 | "7d8d8d6ad77676917d8d8d6ad7767691" + | ||
163 | "5354edc15e5be26d31378ea23c38810e" + | ||
164 | "968a81c141fcf7503c717a3aeb070cab" + | ||
165 | "9eaa8f28c0f16d45f1c6e3e7cdfe62e9" + | ||
166 | "2b312bdf6acddc8f56bca6b5bdbbaa1e" + | ||
167 | "6406fd52a4f79017553173f098cf1119" + | ||
168 | "6dbba90b0776758451cad331ec71792f" + | ||
169 | "e7b0e89c4347788b16760b7b8eb91a62" + | ||
170 | "74ed0ba1739b7e252251ad14ce20d43b" + | ||
171 | "10f80a1753bf729c45c979e7cb706385", | ||
172 | "Stretched empty key"); | ||
173 | |||
174 | var roundIndex; | ||
175 | |||
176 | roundIndex = 0; | ||
177 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x00000000000000000000000000000000", "empty key, subKeyAtRound(0)"); | ||
178 | roundIndex = 1; | ||
179 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x00000000000000000000000000000000", "empty key, subKeyAtRound(1)"); | ||
180 | roundIndex = 2; | ||
181 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x62636363626363636263636362636363", "empty key, subKeyAtRound(2)"); | ||
182 | roundIndex = 3; | ||
183 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0xaafbfbfbaafbfbfbaafbfbfbaafbfbfb", "empty key, subKeyAtRound(3)"); | ||
184 | roundIndex = 4; | ||
185 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6f6c6ccf0d0f0fac6f6c6ccf0d0f0fac", "empty key, subKeyAtRound(4)"); | ||
186 | roundIndex = 5; | ||
187 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x7d8d8d6ad77676917d8d8d6ad7767691", "empty key, subKeyAtRound(5)"); | ||
188 | roundIndex = 6; | ||
189 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x5354edc15e5be26d31378ea23c38810e", "empty key, subKeyAtRound(6)"); | ||
190 | roundIndex = 7; | ||
191 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x968a81c141fcf7503c717a3aeb070cab", "empty key, subKeyAtRound(7)"); | ||
192 | roundIndex = 8; | ||
193 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x9eaa8f28c0f16d45f1c6e3e7cdfe62e9", "empty key, subKeyAtRound(8)"); | ||
194 | roundIndex = 9; | ||
195 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x2b312bdf6acddc8f56bca6b5bdbbaa1e", "empty key, subKeyAtRound(9)"); | ||
196 | roundIndex = 10; | ||
197 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6406fd52a4f79017553173f098cf1119", "empty key, subKeyAtRound(10)"); | ||
198 | roundIndex = 11; | ||
199 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6dbba90b0776758451cad331ec71792f", "empty key, subKeyAtRound(11)"); | ||
200 | roundIndex = 12; | ||
201 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0xe7b0e89c4347788b16760b7b8eb91a62", "empty key, subKeyAtRound(12)"); | ||
202 | roundIndex = 13; | ||
203 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x74ed0ba1739b7e252251ad14ce20d43b", "empty key, subKeyAtRound(13)"); | ||
204 | roundIndex = 14; | ||
205 | is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x10f80a1753bf729c45c979e7cb706385", "empty key, subKeyAtRound(14)"); | ||
206 | |||
207 | |||
208 | //------------------------------------------------------------------------- | ||
209 | // | ||
210 | // Encrypt / decrypt | ||
211 | // | ||
212 | //------------------------------------------------------------------------- | ||
213 | // Test vectors:http://www.zvon.org/tmRFC/RFC3686/Output/chapter6.html | ||
214 | // http://www.cs.utsa.edu/~wagner/laws/AEStestRuns.html | ||
215 | // http://www.ietf.org/rfc/rfc3686.txt | ||
216 | |||
217 | { | ||
218 | // | ||
219 | // http://www.cs.utsa.edu/~wagner/laws/AEStestRuns.html | ||
220 | // | ||
221 | var key; | ||
222 | var plainText; | ||
223 | var cipherText; | ||
224 | var result; | ||
225 | |||
226 | // | ||
227 | //256-bit key size | ||
228 | // | ||
229 | |||
230 | //Gladman's Test Data, 256-bit key - encrypt | ||
231 | key = new Clipperz.ByteArray("0x2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfe", 16); | ||
232 | plainText = new Clipperz.ByteArray("0x3243f6a8885a308d313198a2e0370734", 16); | ||
233 | cipherText = new Clipperz.ByteArray("0x1a6e6c2c662e7da6501ffb62bc9e93f3", 16); | ||
234 | |||
235 | result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues())); | ||
236 | is(result.toHexString(), cipherText.toHexString(), "Gladman's Test Data, 256-bit key - encrypt"); | ||
237 | |||
238 | //AES Specification Test Data, 256-bit key - encrypt | ||
239 | key = new Clipperz.ByteArray("0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 16); | ||
240 | plainText = new Clipperz.ByteArray("0x00112233445566778899aabbccddeeff", 16); | ||
241 | cipherText = new Clipperz.ByteArray("0x8ea2b7ca516745bfeafc49904b496089", 16); | ||
242 | |||
243 | result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues())); | ||
244 | is(result.toHexString(), cipherText.toHexString(), "AES Specification Test Data, 256-bit key - encrypt"); | ||
245 | |||
246 | // | ||
247 | //128-bit key size | ||
248 | // | ||
249 | |||
250 | //Gladman's Test Data, 128-bit key - encrypt | ||
251 | key = new Clipperz.ByteArray("0x2b7e151628aed2a6abf7158809cf4f3c", 16); | ||
252 | plainText = new Clipperz.ByteArray("0x3243f6a8885a308d313198a2e0370734", 16); | ||
253 | cipherText = new Clipperz.ByteArray("0x3925841d02dc09fbdc118597196a0b32", 16); | ||
254 | |||
255 | result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues())); | ||
256 | is(result.toHexString(), cipherText.toHexString(), "Gladman's Test Data, 128-bit key - encrypt"); | ||
257 | |||
258 | //AES Specification Test Data, 128-bit key - encrypt | ||
259 | key = new Clipperz.ByteArray("0x000102030405060708090a0b0c0d0e0f", 16); | ||
260 | plainText = new Clipperz.ByteArray("0x00112233445566778899aabbccddeeff", 16); | ||
261 | cipherText = new Clipperz.ByteArray("0x69c4e0d86a7b0430d8cdb78070b4c55a", 16); | ||
262 | |||
263 | result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues())); | ||
264 | is(result.toHexString(), cipherText.toHexString(), "AES Specification Test Data, 128-bit key - encrypt"); | ||
265 | |||
266 | } | ||
267 | |||
268 | |||
269 | endTime = new Date(); | ||
270 | MochiKit.Logging.logDebug("elapsed time: " + (endTime - startTime)); | ||
271 | |||
272 | //############################################################################# | ||
273 | |||
274 | } catch (err) { | ||
275 | |||
276 | var s = "test suite failure!\n"; | ||
277 | var o = {}; | ||
278 | var k = null; | ||
279 | for (k in err) { | ||
280 | // ensure unique keys?! | ||
281 | if (!o[k]) { | ||
282 | s += k + ": " + err[k] + "\n"; | ||
283 | o[k] = err[k]; | ||
284 | } | ||
285 | } | ||
286 | ok ( false, s ); | ||
287 | } | ||
288 | |||
289 | </script> | ||
290 | </pre> | ||
291 | </body> | ||
292 | </html> | ||