summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Crypto
Unidiff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/AES.html292
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/AES.performance.html344
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/Base.html428
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html478
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/ECC.B283.deferred.html155
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.B283.html209
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.html183
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.Value.html496
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/ECC.K283.deferred.html160
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.html70
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.test.js418
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/PRNG.html117
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/RSA.html90
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/SHA.html175
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/SHA.test.js84
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/SRP.html161
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html122
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/index.html58
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/jscrypto.js1577
19 files changed, 5617 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
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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
53try {
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>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES.performance.html b/frontend/gamma/tests/tests/Clipperz/Crypto/AES.performance.html
new file mode 100644
index 0000000..0d1cf07
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES.performance.html
@@ -0,0 +1,344 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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_performance - TEST</title>
32
33 <script>
34 jslog_config_enabled = true;
35 </script>
36
37 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
38 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
39 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
40 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
41
42 <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
43
44 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
45 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
46 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
47 <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
48 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
49
50 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
51 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
52 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
53
54 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
55 <script type='text/javascript' src='../../../../js/Clipperz/PM/Proxy.js'></script>
56 <script type='text/javascript' src='../../../../js/Clipperz/PM/Connection.js'></script>
57 <script type='text/javascript' src='../../../../js/Clipperz/PM/Crypto.js'></script>
58
59</head>
60<body>
61<pre id="test">
62<script type="text/javascript">
63Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
64
65try {
66
67 var password;
68 varplainText;
69 varencryptedText;
70 var decryptedText;
71 /*
72 password = "trustno1";
73 plainText = "The quick brown fox jumps over the lazy dog";
74//console.profile("encrypt");
75 encryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].encrypt(password, plainText);
76//console.profileEnd();
77//console.profile("decrypt");
78 decryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].decrypt(password, encryptedText);
79//console.profileEnd();
80 is(decryptedText, plainText, "simple string encrypted/decrypted");
81*/
82
83 password = "L7bd9fQMhborMbYcHtlr";
84 plainText = {"records":{"f1aac97154a0e52c5e33508afa82df5a9d6dcde24883a240b8c072a3238da0b6":{"label":"imap4all [no]", "key":"f54b5033d1152456acb67974c45ee6771f8411e300c9533359dfacacf60dcbbd", "notes":""}, "c9dae2b7a60b300008306f5ec731b60050250df8f8ff34f7d9cce92762121b99":{"label":"Il manifesto", "key":"6e0ef134503110e72f444e7d102a4b1cc6ae28f2e0b1287c2b1875ff052fc16c", "notes":""}, "70d536c89a86b1aa9e077d6f9c717306a5d6c8d5549789e42dfb4f981484f116":{"label":"OmniGroup applications", "key":"7b432b7dae39ff5951db31947fa721dc012af0da4055760c6df3b02e776ef22c", "notes":"url: http://www.omnigroup.com\n\nLicence owner: Giulio Cesare Solaroli\n\nOmniWeb: EQGP-EMKH-LKWP-MUHQ-OUHL-LDF\nOmniGraffle:\nOmniOutliner:\nOmniDiskSweeper:"}, "111855cedd650dfcbbce597d764583c6b040df4b71f5fa0161fb8d10514ee48f":{"label":"R@cine", "key":"57295772c84669b0a224f435e9b75c797ae5999a2d9473ab50f9384ae54f49d6", "notes":""}, "378a790452de46e1079a99eba2e15094a096b418cccd0262b8b20244eb94d2df":{"label":"NewsGator", "key":"6ee16f6932ee02000c49dbcc685c84074b40d7956e5f4bc1100030a0f9a41f1a", "notes":""}, "30c4f575799fc6908765fc8b54f4a9a483cb32e12aa89feae545976870a9102e":{"label":"GMail - giulio.cesare", "key":"0395efd852b00700bcf78b65350ec15932430df71201d2c53a11b0269b557d1a", "notes":""}, "b2836a864ff081b6f053c3f5f13dfb29c81af33d25a316cdd82af747ea71bea0":{"label":"GMail - clipperz.com", "key":"90d6ae70d89c8211404b6f9d6c70b6b9c113fff74f474a67b34acd9c1c048d1f", "notes":""}, "6ad2cda35f97743cfddf2133cdf3142fe6419e683484531f1ef1e67431f44284":{"label":"Aruba - hosting", "key":"5c7472d24d57391c63ea99ed1fc9de179d225abd335fa65702018cfea6083d47", "notes":""}, "741ce1d21839c69db754309b04ce02fbb4104f6cb87572c056ae4af918420700":{"label":"Aruba - sql hosting", "key":"f6bd942ac3b0b7065771e5197c7499b345a10f7a4843d00c3ba3809d0ea059dc", "notes":""}, "1cef440eecea59f47554aa04b94e18c1d9fc761246b911f89a7da72d544cac48":{"label":"Amazon", "key":"1ae022b4d14b642f113703b2a98931bd892dec2da785ab5ff6fc1d0aac7537f1", "notes":""}, "d34c13773b5d8154355c2605024a1dfaf66279ba0fbe3ac19fc1cbc642278fe4":{"label":"YouTube [no]", "key":"4c6593d4f6448137939b364b84c81501fadb60f7871fe5fa63c93e97bb5c4648", "notes":""}, "5054f0b94cd97610a1bc0ed8671b6fb5b25bf7a5582677059fcaaea75fac27bc":{"label":"DynDns - gcsolaroli", "key":"f8ed9e7a3630deed046eda37ebc63ecb4d63668a2f97224d7628fdc53b242467", "notes":""}, "73fb52ed51533657d6ebb020d5026fb4deb601dadce802de58f7fff4b56e1495":{"label":"DynDns - clipperz", "key":"d8bc295177383a523e67b61b166e0ca956ab4c2ee86800559a009d2716064f6d", "notes":""}, "48d4c0546c032be26ecce4da41e020129afa7fc34cfe164ea72e1c9953d2e6bb":{"label":"Bol.it", "key":"cada5dadeebd8d12190954d21f1a944c8799d034f028be195b448935fcf970c7", "notes":""}, "d62d420db34720ccc054df06b88725ea79020ffa9389ca15e70137fb4dfd0883":{"label":"Freenigma - clipperz.com", "key":"f09cb3790c1110794b834702b8c487c1a42b2508fbe6450a8468477d93790b2e", "notes":""}, "ccd44ae294e7694ea53009c7198506cc0fe3121ad5d9fe2635d247e2afdab2ae":{"label":"Freenigma", "key":"4b05738f6faebc147eac5e425054a91d3cc59dd63844e82d1f0864c0ac8efec7", "notes":""}, "bd5a587bb977a2c728fcd0fa6093dd63a4e62138cf89721115fe45e0396ba5d2":{"label":"clipperz.com - blog", "key":"9cc24328bbce18e8713962428d8123e309a12f7e1d9537bc252e134501734003", "notes":""}, "c2b99939e40d100218baa3ed1cb2a25a5cf726485b0336a0989b104a94157b5f":{"label":"Apple", "key":"75f2651af400629c4e5dd8bcdc3a6c691150d23d6e1a4eb263ff810926d1228f", "notes":""}, "b5bd38d8eb5e23b1354884cc519e05580864fadf74d0a19d2c691cd0c7054d77":{"label":".mac", "key":"5934ae96d2e01282effb368d9086c2ba5d1d856ad91dd6f04f5bace26a1c0cbe", "notes":""}, "ff79a2282cf246add520a3c06e835cf6ffaaae95067d45e8e2e8f44da2501380":{"label":"3nity", "key":"33d84c4a91ab053cbf8115c689ede7e504b81199884de449acc257bea534f57f", "notes":""}, "7b2f2a59ebb34b5a49f20b99b546f08b9f4f62cbefdce9699f8ef7e74aeb0552":{"label":"ACM", "key":"b4976bb0892baba81d628513d191de100d89acd58efbb07c823a5bb4abe48a7a", "notes":""}, "b83a6bac0da3a27eb909d34cbad183e77088952f01d8d5321613b7b01635a020":{"label":"Adobe", "key":"d162bc404994a79ec97e0106c3a4edf2f83aca25def130242e11e95e74bd0aaa", "notes":""}, "befc571e9cda1a7dfb1d15200240ca5170386280ee7be6a12716904cb6d0ea44":{"label":"Adobe Photoshop Elements 3", "key":"18a62c3c2065399819707322f467ff4be030d7939acbe5182c8194599845c428", "notes":"Photoshop Elements 2:\n1057-4312-5223-2206-9509-6837"}, "0424f72608fedc969d64a6d5b4a16dd3ce860a230cd6d87d936439f4dd2aafc7":{"label":"Agatra", "key":"c35158a21b2af75d414232b742ab738d042314e00209f8fca94c8c704c891f23", "notes":""}, "e5e17c29fd598acb4f4c7d621dbdcb045d4d0cabf7d8a19e24420c440cdc3935":{"label":"AIM", "key":"8561ac421d845921978387b5e6b362750b57ed08feda8ec12b9378b69f67ceff", "notes":""}, "de890eb76a4b0cabd4ffd490adad1ff1b73238c7b5ee6dde1a2aeab2d03ebe93":{"label":"Anna Vespignani", "key":"79a970af0d2d30643dc2db4d16757395c1f22c311919036c2a22b7581982144a", "notes":""}, "0dc8d3989d0b35d672c012057d3eb7b111f16e79329e08a9ffb31ac7accbab21":{"label":"Bloglines", "key":"fe81f4df8c42fd81c830f9af408e9b074e77fd430e26d0ee285844fe3b092aec", "notes":""}, "85a40a322a59c80cb46519900269dcc7cf6947213d03dfc9371dd1930373a65b":{"label":"Bow.it", "key":"64a1a9fec99c9238dc8180a01484a1ccf5f50fcd6e9a95a52b8b49fb9ca00bdc", "notes":""}, "60308062a1848a301641a74712d220eef191a280ba0a8355992f0e61ed793811":{"label":"GMail - feedback", "key":"fad310cb2e6152c3faf78b7183c99f3044f5d31ee364068b80580c271a7784ef", "notes":""}, "257ac2da79ee1cd46dfa214d91f5ece213b6bbade28d1ee71495c81a3d7e033a":{"label":"Fineco", "key":"8f99de2635b5dad7987180bc0bff49947eb37cc75d6a5d1ee1f13ed7567465a3", "notes":""}, "78261622810232b6da5efcd52b1c9b0bd87c62517bf4df25323ca6a0b49d84ec":{"label":"mon.itor.us", "key":"d2aa7164007c5deac8bb73580a6ab0d051f747e801ecd30284eff725d0ffaba2", "notes":""}, "4b78dc0376d07e57d77b4c7318d2f222956adb6ff7360b73e60b8bb8b85f3d11":{"label":"Lamba Probe - forum", "key":"f73906817fddba4d8f816334cb2fd0cd5ae91bc29bce6a69fdd5cf98fc96911f", "notes":""}, "78ca2c85908275d788c2f7dd0306ca5e03b83637bb3812272b697e12e9dbf941":{"label":"MeasureMap", "key":"2385ce9536ebb7863b6a4c8b1f5c428587e4d6420a4bbcd31b935cb00bbd768e", "notes":""}, "4c2c7f0d733b647e6f388c9a4590a2a864cd2de259b66aba9b3cf92bdc3cf9bc":{"label":"NGI - Squillo", "key":"96f20c212be02fb38c8b2dfc83d8e864dd84dcb95297a7fecf9280e1e4dcffe3", "notes":""}, "eaeadf6d36f8ee6916c33b9e5bf480b663dc90c0c7f370ff5a1f2fd998cf1143":{"label":"NGI - F5", "key":"00347769244b208647c24e6a64f8fa4213e97eb2135ecfcb277b341c28616a59", "notes":""}, "19654392222206d60547073209672dde1c743ea371ddc20a2bd8254e561a4ec0":{"label":"CVSdude", "key":"ed0ab5080a29eb1b20927142d21ab8f67b61c2c7b19623bb610af030dfd42c02", "notes":""}, "6b10514d50e745f1dab5a40e8629ecf1a8c78a5d6e3895f3637fb67d2d3f9993":{"label":"Yahoo", "key":"6380a7655cd790d1f1e6f482e92ae04201568ff0cab887e65102e9396df1b86e", "notes":"note"}}, "directLogins":{"eac496e0b1ec75ea403f821fedc7f51f98dac639713ebe577f969f607a8943f5":{"record":"111855cedd650dfcbbce597d764583c6b040df4b71f5fa0161fb8d10514ee48f", "label":"R@cine - WebMail", "favicon":"http://www.racine.ra.it/favicon.ico"}, "ef564a022630d4395a9ecac854f3b127b3518cec362323ccc605079c0749c152":{"record":"1cef440eecea59f47554aa04b94e18c1d9fc761246b911f89a7da72d544cac48", "label":"Amazon sign in", "favicon":"http://www.amazon.com/favicon.ico"}, "4f14b88a4055ff23a00d625382650888ce9284fe869304775e43e3e33ee5bbb6":{"record":"6ad2cda35f97743cfddf2133cdf3142fe6419e683484531f1ef1e67431f44284", "label":"Aruba - hosting", "favicon":"http://hosting.aruba.it/favicon.ico"}, "e94c0d12d1db0badc31a8bbbbc4b08d2065a39f458462bbff9756f7b5eb7fedf":{"record":"741ce1d21839c69db754309b04ce02fbb4104f6cb87572c056ae4af918420700", "label":"Aruba - sql hosting", "favicon":"http://mysql.aruba.it/favicon.ico"}, "7299249153ef93a44e2f248ca3a73badde56e71d70919bb5637093c2abbe2c9a":{"record":"bd5a587bb977a2c728fcd0fa6093dd63a4e62138cf89721115fe45e0396ba5d2", "label":"clipperz.com - blog", "favicon":"http://www.clipperz.com/favicon.ico"}, "66876dbae68778d4c104bc12f01adcb21d47d9eace8db30ef95f74f461afcb59":{"record":"73fb52ed51533657d6ebb020d5026fb4deb601dadce802de58f7fff4b56e1495", "label":"DynDns - clipperz", "favicon":"http://www.dyndns.com/favicon.ico"}, "a60c65030a1797abde3e2089c3e5de9648f66bf71cebf0b58c26e729ad8d6a45":{"record":"5054f0b94cd97610a1bc0ed8671b6fb5b25bf7a5582677059fcaaea75fac27bc", "label":"DynDns - gcsolaroli", "favicon":"http://www.dyndns.com/favicon.ico"}, "08d6c5dff9fed4a2f237c32dd0a93ac46b2c45370d07f56fa76064be3b8fecbf":{"record":"30c4f575799fc6908765fc8b54f4a9a483cb32e12aa89feae545976870a9102e", "label":"GMail - giulio.cesare", "favicon":"http://www.google.com/favicon.ico"}, "9e75e12f0f52f248cc7ae517869dd7b02303037d32d9fb4fa0ab0e013923c304":{"record":"c9dae2b7a60b300008306f5ec731b60050250df8f8ff34f7d9cce92762121b99", "label":"Il manifesto", "favicon":"http://abbonati.ilmanifesto.it/favicon.ico"}, "935bf9553fbcb85b8bd5b98c6901d7cccb2566b395f192cbea71e7822979aaf2":{"record":"f1aac97154a0e52c5e33508afa82df5a9d6dcde24883a240b8c072a3238da0b6", "label":"Imap4All.com - account", "favicon":"http://www.imap4all.com/favicon.ico"}, "9504205ec29b89e6ccd0f3afc7a447d8891da0c71a0222f1860f98a8f8bc6677":{"record":"f1aac97154a0e52c5e33508afa82df5a9d6dcde24883a240b8c072a3238da0b6", "label":"Imap4all.com - WebMail", "favicon":"http://webmail.imap4all.com/favicon.ico"}, "3d8dd32d2290ca98789c914580ac2436ece97234217a07d752726d2ac48a4ebf":{"record":"d34c13773b5d8154355c2605024a1dfaf66279ba0fbe3ac19fc1cbc642278fe4", "label":"YouTube [no]", "favicon":"http://www.youtube.com/favicon.ico"}, "7c4b6b5a16984c43ed6d99b04ddfa7e00b624de729ec8aaa3d0f539fb67587e2":{"record":"c2b99939e40d100218baa3ed1cb2a25a5cf726485b0336a0989b104a94157b5f", "label":"Apple Store - Italia", "favicon":"http://store.apple.com/favicon.ico"}, "0b9a98262b50f0ebae5af077467bc627619738873690238fd61093ce9922c9f9":{"record":"ff79a2282cf246add520a3c06e835cf6ffaaae95067d45e8e2e8f44da2501380", "label":"3nity", "favicon":"http://www.3nity.de/favicon.ico"}, "aadeb3388629cfc3b15954f26cf284f52e084191dcdf75752dc4c53d2006c5be":{"record":"7b2f2a59ebb34b5a49f20b99b546f08b9f4f62cbefdce9699f8ef7e74aeb0552", "label":"ACM Web Account", "favicon":"http://portal.acm.org/favicon.ico"}, "3d21c71f2e284ec76f1ae0bb990b683979918f758635bb7d008150f4d7b1447d":{"record":"b83a6bac0da3a27eb909d34cbad183e77088952f01d8d5321613b7b01635a020", "label":"Adobe - Sign In", "favicon":"http://www.adobe.com/favicon.ico"}, "e61a331c998804d46044d4c2acaf96c2fce806f6549e1e16c7d2334872a70953":{"record":"0424f72608fedc969d64a6d5b4a16dd3ce860a230cd6d87d936439f4dd2aafc7", "label":"Agatra [no]", "favicon":"http://www.agatra.com/favicon.ico"}, "9bcd99564fda778061246439fa098dcc79de75b16c542f61e6de7d36dbaf97dc":{"record":"e5e17c29fd598acb4f4c7d621dbdcb045d4d0cabf7d8a19e24420c440cdc3935", "label":"AIM [no]", "favicon":"http://my.screenname.aol.com/favicon.ico"}, "c7093f4663c6e0eba941c557cb86da83fc68cbea36c922e168d0867e6cabe9fe":{"record":"0dc8d3989d0b35d672c012057d3eb7b111f16e79329e08a9ffb31ac7accbab21", "label":"Bloglines", "favicon":"http://www.bloglines.com/favicon.ico"}, "915f2e9460f6e54c6137f3876f9179fc8d2162c59f26e12899c2db6b0e70a68f":{"record":"85a40a322a59c80cb46519900269dcc7cf6947213d03dfc9371dd1930373a65b", "label":"Bow.it", "favicon":"http://www.bow.it/favicon.ico"}, "779701af1beb2a91735ba1a2e471b948f0d985bb0df256f5e089291ce3405bd2":{"record":"b2836a864ff081b6f053c3f5f13dfb29c81af33d25a316cdd82af747ea71bea0", "label":"GMail - Clipperz", "favicon":"http://www.google.com/favicon.ico"}, "1c300539a98c874d52134b6b5a591172acc00c0947692f3da284447f7d511eaf":{"record":"60308062a1848a301641a74712d220eef191a280ba0a8355992f0e61ed793811", "label":"GMail - feedback", "favicon":"http://www.google.com/favicon.ico"}, "f9dccdf7a98735fd7a6b5d04c09177005c0de14f8f92b04007f06a281ecdf31e":{"record":"30c4f575799fc6908765fc8b54f4a9a483cb32e12aa89feae545976870a9102e", "label":"Blogger", "favicon":"http://www.google.com/favicon.ico"}, "48497a89f3bfd567758977e1c32b4497d28c843880667ee52fa4cfcb53c5f9e4":{"record":"378a790452de46e1079a99eba2e15094a096b418cccd0262b8b20244eb94d2df", "label":"NewsGator", "favicon":"http://www.newsgator.com/favicon.ico"}, "134cd28f150df4f2a089f4807bb7a35fb7ece22ec41244f72e63f8b43637a4cd":{"record":"4b78dc0376d07e57d77b4c7318d2f222956adb6ff7360b73e60b8bb8b85f3d11", "label":"Lambda Probe - forum", "favicon":"http://www.lambdaprobe.org/favicon.ico"}, "2ab6106a81513b70f1ba0d7c5c3ef54fa6f4bcadf01d2eeaa2b31b9299551398":{"record":"78ca2c85908275d788c2f7dd0306ca5e03b83637bb3812272b697e12e9dbf941", "label":"Measure Map", "favicon":"http://alpha.measuremap.com/favicon.ico"}, "53ccdc41b43da9b018847f9faa8effb35e7a6c6e78a54e9ee7816fc02f0ea63b":{"record":"4c2c7f0d733b647e6f388c9a4590a2a864cd2de259b66aba9b3cf92bdc3cf9bc", "label":"NGI - Squillo", "favicon":"http://www.ngi.it/favicon.ico"}, "ca520e7081fba1df3ef79c3d00266cffc8e4567def29d67ae812b7ed6283fb12":{"record":"eaeadf6d36f8ee6916c33b9e5bf480b663dc90c0c7f370ff5a1f2fd998cf1143", "label":"NGI - F5", "favicon":"http://www.ngi.it/favicon.ico"}, "80e63e135d7abd2b2990f42af4f8d1f8e8b1146aed44dc36975061fbf360a983":{"record":"6b10514d50e745f1dab5a40e8629ecf1a8c78a5d6e3895f3637fb67d2d3f9993", "label":"Yahoo! Mail", "favicon":"http://login.yahoo.com/favicon.ico"}}, "preferences":{"preferredLanguage":"en-US"}};
85/* */
86 plainText = {
87 "records": {
88 "1": {
89 "label":"imap4all [no]",
90 "key":"f54b5033d1152456acb67974c45ee6771f8411e300c9533359dfacacf60dcbbd",
91 "notes":""
92 },
93 "2": {
94 "label":"Il manifesto",
95 "key":"6e0ef134503110e72f444e7d102a4b1cc6ae28f2e0b1287c2b1875ff052fc16c",
96 "notes":""
97 },
98 "3": {
99 "label": "OmniGroup applications",
100 "key": "7b432b7dae39ff5951db31947fa721dc012af0da4055760c6df3b02e776ef22c",
101 "notes": "url: http://www.omnigroup.com\n\nLicence owner: Giulio Cesare Solaroli\n\nOmniWeb: EQGP-EMKH-LKWP-MUHQ-OUHL-LDF\nOmniGraffle:\nOmniOutliner:\nOmniDiskSweeper:"
102 },
103 "4": {
104 "label": "R@cine",
105 "key": "57295772c84669b0a224f435e9b75c797ae5999a2d9473ab50f9384ae54f49d6",
106 "notes": ""
107 },
108 "5": {
109 "label": "NewsGator",
110 "key": "6ee16f6932ee02000c49dbcc685c84074b40d7956e5f4bc1100030a0f9a41f1a",
111 "notes": ""
112 },
113 "6": {
114 "label": "GMail - giulio.cesare",
115 "key": "0395efd852b00700bcf78b65350ec15932430df71201d2c53a11b0269b557d1a",
116 "notes": ""
117 },
118 "7": {
119 "label": "GMail - clipperz.com",
120 "key": "90d6ae70d89c8211404b6f9d6c70b6b9c113fff74f474a67b34acd9c1c048d1f",
121 "notes": ""
122 },
123 "8": {
124 "label": "Aruba - hosting",
125 "key": "5c7472d24d57391c63ea99ed1fc9de179d225abd335fa65702018cfea6083d47",
126 "notes": ""
127 },
128 "9": {
129 "label": "Aruba - sql hosting",
130 "key": "f6bd942ac3b0b7065771e5197c7499b345a10f7a4843d00c3ba3809d0ea059dc",
131 "notes": ""
132 },
133 "10": {
134 "label": "Amazon",
135 "key": "1ae022b4d14b642f113703b2a98931bd892dec2da785ab5ff6fc1d0aac7537f1",
136 "notes": ""
137 },
138 "11": {
139 "label": "YouTube [no]",
140 "key": "4c6593d4f6448137939b364b84c81501fadb60f7871fe5fa63c93e97bb5c4648",
141 "notes": ""
142 },
143 "12": {
144 "label": "DynDns - gcsolaroli",
145 "key": "f8ed9e7a3630deed046eda37ebc63ecb4d63668a2f97224d7628fdc53b242467",
146 "notes": ""
147 },
148 "13": {
149 "label": "DynDns - clipperz",
150 "key": "d8bc295177383a523e67b61b166e0ca956ab4c2ee86800559a009d2716064f6d",
151 "notes": ""
152 },
153 "14": {
154 "label": "Bol.it",
155 "key": "cada5dadeebd8d12190954d21f1a944c8799d034f028be195b448935fcf970c7",
156 "notes": ""
157 },
158 "15": {
159 "label": "Freenigma - clipperz.com",
160 "key": "f09cb3790c1110794b834702b8c487c1a42b2508fbe6450a8468477d93790b2e",
161 "notes": ""
162 },
163 "16": {
164 "label": "Freenigma",
165 "key": "4b05738f6faebc147eac5e425054a91d3cc59dd63844e82d1f0864c0ac8efec7",
166 "notes": ""
167 },
168 "17": {
169 "label": "clipperz.com - blog",
170 "key": "9cc24328bbce18e8713962428d8123e309a12f7e1d9537bc252e134501734003",
171 "notes": ""
172 },
173 "18": {
174 "label": "Apple",
175 "key": "75f2651af400629c4e5dd8bcdc3a6c691150d23d6e1a4eb263ff810926d1228f",
176 "notes": ""
177 },
178 "19": {
179 "label": ".mac",
180 "key": "5934ae96d2e01282effb368d9086c2ba5d1d856ad91dd6f04f5bace26a1c0cbe",
181 "notes": ""
182 },
183 "20": {
184 "label": "3nity",
185 "key": "33d84c4a91ab053cbf8115c689ede7e504b81199884de449acc257bea534f57f",
186 "notes": ""
187 },
188 "21": {
189 "label": "ACM",
190 "key": "b4976bb0892baba81d628513d191de100d89acd58efbb07c823a5bb4abe48a7a",
191 "notes": ""
192 },
193 "22": {
194 "label": "Adobe",
195 "key": "d162bc404994a79ec97e0106c3a4edf2f83aca25def130242e11e95e74bd0aaa",
196 "notes": ""
197 },
198 "23": {
199 "label": "Adobe Photoshop Elements 3",
200 "key": "18a62c3c2065399819707322f467ff4be030d7939acbe5182c8194599845c428",
201 "notes": "Photoshop Elements 2:\n1057-4312-5223-2206-9509-6837"
202 },
203 "24": {
204 "label": "Agatra",
205 "key": "c35158a21b2af75d414232b742ab738d042314e00209f8fca94c8c704c891f23",
206 "notes": ""
207 },
208 "25": {
209 "label": "AIM",
210 "key": "8561ac421d845921978387b5e6b362750b57ed08feda8ec12b9378b69f67ceff",
211 "notes": ""
212 },
213 "26": {
214 "label": "Anna Vespignani",
215 "key": "79a970af0d2d30643dc2db4d16757395c1f22c311919036c2a22b7581982144a",
216 "notes": ""
217 },
218 "27": {
219 "label": "Bloglines",
220 "key": "fe81f4df8c42fd81c830f9af408e9b074e77fd430e26d0ee285844fe3b092aec",
221 "notes": ""
222 },
223 "28": {
224 "label": "Bow.it",
225 "key": "64a1a9fec99c9238dc8180a01484a1ccf5f50fcd6e9a95a52b8b49fb9ca00bdc",
226 "notes": ""
227 },
228 "29": {
229 "label": "GMail - feedback",
230 "key": "fad310cb2e6152c3faf78b7183c99f3044f5d31ee364068b80580c271a7784ef",
231 "notes": ""
232 },
233 "30": {
234 "label": "Fineco",
235 "key": "8f99de2635b5dad7987180bc0bff49947eb37cc75d6a5d1ee1f13ed7567465a3",
236 "notes": ""
237 },
238 "31": {
239 "label": "mon.itor.us",
240 "key": "d2aa7164007c5deac8bb73580a6ab0d051f747e801ecd30284eff725d0ffaba2",
241 "notes": ""
242 },
243 "32": {
244 "label": "Lamba Probe - forum",
245 "key": "f73906817fddba4d8f816334cb2fd0cd5ae91bc29bce6a69fdd5cf98fc96911f",
246 "notes": ""
247 },
248 "33": {
249 "label": "MeasureMap",
250 "key": "2385ce9536ebb7863b6a4c8b1f5c428587e4d6420a4bbcd31b935cb00bbd768e",
251 "notes": ""
252 },
253 "34": {
254 "label": "NGI - Squillo",
255 "key": "96f20c212be02fb38c8b2dfc83d8e864dd84dcb95297a7fecf9280e1e4dcffe3",
256 "notes": ""
257 },
258 "35": {
259 "label": "NGI - F5",
260 "key": "00347769244b208647c24e6a64f8fa4213e97eb2135ecfcb277b341c28616a59",
261 "notes": ""
262 },
263 "36": {
264 "label": "CVSdude",
265 "key": "ed0ab5080a29eb1b20927142d21ab8f67b61c2c7b19623bb610af030dfd42c02",
266 "notes": ""
267 },
268 "37": {
269 "label": "Yahoo",
270 "key": "6380a7655cd790d1f1e6f482e92ae04201568ff0cab887e65102e9396df1b86e",
271 "notes": "note"
272 }
273 },
274 "directLogins": {
275 "1": { "record": "1", "label": "R@cine - WebMail", "favicon": "http://www.racine.ra.it/favicon.ico" },
276 "2": { "record": "2", "label": "Amazon sign in", "favicon": "http://www.amazon.com/favicon.ico" },
277 "3": { "record": "3", "label": "Aruba - hosting", "favicon": "http://hosting.aruba.it/favicon.ico" },
278 "4": { "record": "4", "label": "Aruba - sql hosting", "favicon":"http://mysql.aruba.it/favicon.ico" },
279 "5": { "record": "5", "label":"clipperz.com - blog", "favicon":"http://www.clipperz.com/favicon.ico" },
280 "6": { "record":"6", "label":"DynDns - clipperz", "favicon":"http://www.dyndns.com/favicon.ico" },
281 "7": { "record":"7", "label":"DynDns - gcsolaroli", "favicon":"http://www.dyndns.com/favicon.ico" },
282 "8":{"record":"8", "label":"GMail - giulio.cesare", "favicon":"http://www.google.com/favicon.ico" },
283 "9":{"record":"9", "label":"Il manifesto", "favicon":"http://abbonati.ilmanifesto.it/favicon.ico" },
284 "10":{"record":"10", "label":"Imap4All.com - account", "favicon":"http://www.imap4all.com/favicon.ico" },
285 "11":{"record":"12", "label":"Imap4all.com - WebMail", "favicon":"http://webmail.imap4all.com/favicon.ico" },
286 "13":{"record":"13", "label":"YouTube [no]", "favicon":"http://www.youtube.com/favicon.ico" },
287 "14":{"record":"14", "label":"Apple Store - Italia", "favicon":"http://store.apple.com/favicon.ico" },
288 "15":{"record":"15", "label":"3nity", "favicon":"http://www.3nity.de/favicon.ico" },
289 "16":{"record":"16", "label":"ACM Web Account", "favicon":"http://portal.acm.org/favicon.ico" },
290 "17":{"record":"17", "label":"Adobe - Sign In", "favicon":"http://www.adobe.com/favicon.ico" },
291 "18":{"record":"18", "label":"Agatra [no]", "favicon":"http://www.agatra.com/favicon.ico" },
292 "19":{"record":"19", "label":"AIM [no]", "favicon":"http://my.screenname.aol.com/favicon.ico" },
293 "20":{"record":"20", "label":"Bloglines", "favicon":"http://www.bloglines.com/favicon.ico" },
294 "21":{"record":"21", "label":"Bow.it", "favicon":"http://www.bow.it/favicon.ico" },
295 "22":{"record":"22", "label":"GMail - Clipperz", "favicon":"http://www.google.com/favicon.ico" },
296 "23":{"record":"23", "label":"GMail - feedback", "favicon":"http://www.google.com/favicon.ico" },
297 "24":{"record":"24", "label":"Blogger", "favicon":"http://www.google.com/favicon.ico" },
298 "25":{"record":"25", "label":"NewsGator", "favicon":"http://www.newsgator.com/favicon.ico" },
299 "26":{"record":"26", "label":"Lambda Probe - forum", "favicon":"http://www.lambdaprobe.org/favicon.ico" },
300 "27":{"record":"27", "label":"Measure Map", "favicon":"http://alpha.measuremap.com/favicon.ico" },
301 "28":{"record":"28", "label":"NGI - Squillo", "favicon":"http://www.ngi.it/favicon.ico" },
302 "29":{"record":"29", "label":"NGI - F5", "favicon":"http://www.ngi.it/favicon.ico" },
303 "30":{"record":"30", "label":"Yahoo! Mail", "favicon":"http://login.yahoo.com/favicon.ico"}
304 },
305 "preferences":{"preferredLanguage":"en-US"}
306 }
307/* */
308
309//console.profile("encrypt 0.2");
310 encryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].encrypt(password, plainText);
311//console.profileEnd();
312//console.profile("decrypt");
313 //decryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].decrypt(password, encryptedText);
314//console.profileEnd();
315 //is(MochiKit.Base.serializeJSON(decryptedText), MochiKit.Base.serializeJSON(plainText), "complex structure encrypted/decrypted");
316
317//console.profile("encrypt 0.3");
318 encryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].encrypt(password, plainText);
319//console.profileEnd();
320 decryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].decrypt(password, encryptedText);
321 is(MochiKit.Base.serializeJSON(decryptedText), MochiKit.Base.serializeJSON(plainText), "complex structure encrypted/decrypted");
322
323
324//#############################################################################
325
326} catch (err) {
327
328 var s = "test suite failure!\n";
329 var o = {};
330 var k = null;
331 for (k in err) {
332 // ensure unique keys?!
333 if (!o[k]) {
334 s += k + ": " + err[k] + "\n";
335 o[k] = err[k];
336 }
337 }
338 ok ( false, s );
339}
340
341</script>
342</pre>
343</body>
344</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html b/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
new file mode 100644
index 0000000..86fc49a
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/Base.html
@@ -0,0 +1,428 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
38 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
39
40 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
41 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
44
45</head>
46<body>
47<pre id="test">
48<script type="text/javascript">
49try {
50 var secretKey;
51 varpublicKey;
52 varplainString;
53 varencryptedString;
54
55
56 secretKey = "s3cr37k39";
57 plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
58 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
59
60 //-------------------------------------------------------------------------
61 //
62 //Secret key encryption / decryption
63 //
64 is (isUndefinedOrNull(encryptedString), false, "An encrypted string should not be empty");
65 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
66
67 try {
68 vardecryptedText;
69
70 decryptedText = Clipperz.Crypto.Base.decryptUsingSecretKey("anotherKey", encryptedString);
71 ok( false, "It should not be possible to decrypt a text with a different passphrase (decrypted text: " + decryptedText + ")" );
72 } catch (e) {
73 ok( e instanceof Error, "Trying to decrypt a message with the wrong passphrase raised an error" );
74 }
75
76 is (encryptedString == Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString), false, "Two consecutive encryption of the same text should return different values");
77
78 secretKey = "trustno1";
79 plainString = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1";
80 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
81 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
82
83 secretKey = "trustno1";
84 plainString = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed pede. Curabitur a mi id nisi euismod rutrum. Phasellus gravida. Ut luctus. Praesent quis leo sit amet orci imperdiet malesuada. Aenean molestie mauris euismod odio. Suspendisse ullamcorper facilisis nisl. Fusce vestibulum consectetuer risus. Curabitur ut turpis eget arcu facilisis ultricies. Morbi elementum, erat vitae dictum imperdiet, nisi purus rutrum odio, eget ornare ipsum nisl in tortor. Duis vestibulum, nulla et bibendum volutpat, mauris metus facilisis elit, vel gravida tortor leo at enim. Vivamus pulvinar lorem vitae tortor. Morbi rhoncus suscipit urna. Praesent placerat tempus augue. Fusce varius dui a nisi consequat ultricies. Curabitur at nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.";
85 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
86 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
87
88 secretKey = "trustno1";
89 plainString = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed pede. Curabitur a mi id nisi euismod rutrum. Phasellus gravida. Ut luctus. Praesent quis leo sit amet orci imperdiet malesuada. Aenean molestie mauris euismod odio. Suspendisse ullamcorper facilisis nisl. Fusce vestibulum consectetuer risus. Curabitur ut turpis eget arcu facilisis ultricies. Morbi elementum, erat vitae dictum imperdiet, nisi purus rutrum odio, eget ornare ipsum nisl in tortor. Duis vestibulum, nulla et bibendum volutpat, mauris metus facilisis elit, vel gravida tortor leo at enim. Vivamus pulvinar lorem vitae tortor. Morbi rhoncus suscipit urna. Praesent placerat tempus augue. Fusce varius dui a nisi consequat ultricies. Curabitur at nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas./n/n/nMorbi vel leo non justo condimentum convallis. Vestibulum posuere aliquam nunc. Donec magna magna, euismod nec, pharetra fringilla, tristique mattis, turpis. Duis condimentum lacus eu felis. Sed ultricies. Nullam lacinia ante id diam. Ut quis enim. Fusce at felis quis neque vehicula tempor. Sed feugiat sodales sem. Duis cursus massa in ligula. Vestibulum volutpat, risus in ornare porta, tortor orci vestibulum felis, et eleifend risus odio nec eros. Integer lorem turpis, imperdiet eu, tempor eu, ultricies nec, est. Ut congue. Morbi lacinia vehicula pede. Cras neque sapien, feugiat ac, eleifend eget, mattis et, nisl. Morbi at augue vitae massa laoreet gravida./n/n/nSuspendisse vehicula convallis sem. Sed vel urna. Proin dolor diam, malesuada in, aliquet a, sagittis et, magna. Cras at dui eu mi porta fermentum. Donec pharetra purus sed velit. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque euismod ornare neque. In odio nisi, bibendum non, vulputate ut, tincidunt a, ante. Sed risus arcu, tempus laoreet, euismod id, laoreet mollis, arcu. Ut tempor orci in nibh. Suspendisse potenti. Maecenas accumsan augue at nisl. Donec elementum diam nec metus. Sed vitae lacus sed libero varius semper. Aenean hendrerit tristique arcu. Praesent adipiscing ornare purus. Vestibulum quis eros nec risus accumsan laoreet. Duis consequat ante ut turpis. Curabitur aliquam suscipit ligula. Vivamus adipiscing./n/n/nCurabitur facilisis neque sit amet erat. Aliquam odio augue, vulputate lobortis, rutrum ut, tristique id, leo. Vivamus eu magna. Maecenas et libero. Integer porta, lorem at mollis ullamcorper, purus metus vestibulum erat, ut fringilla dui ante id mi. Morbi vitae ligula. Praesent ornare sapien sed massa. Mauris rhoncus fermentum dolor. Mauris gravida, justo et mollis malesuada, dolor erat fermentum nulla, vel suscipit leo ligula vel augue. Praesent magna enim, dignissim sed, aliquet quis, fermentum viverra, nisi. Vivamus condimentum, nisi quis posuere viverra, enim nunc faucibus lectus, mollis aliquam ipsum enim vel lacus. Suspendisse eget ligula. Aliquam ut metus et justo consectetuer ornare. Donec dapibus tristique pede. Vestibulum interdum ultricies tortor./n/n/nNunc nonummy dictum tortor. Quisque at elit a arcu nonummy elementum. Quisque auctor, risus et sodales euismod, turpis tellus consectetuer ante, quis egestas justo enim quis mi. Nunc fermentum sodales felis. Vivamus odio mi, dignissim vitae, auctor nec, tempus eget, lacus. Ut sapien massa, hendrerit eget, sagittis at, eleifend condimentum, arcu. Curabitur purus orci, facilisis vel, dapibus id, varius rutrum, tortor. Fusce accumsan viverra sem. Quisque tincidunt venenatis risus. Sed tortor justo, volutpat malesuada, sodales ut, vehicula id, magna. Nunc placerat, nibh et imperdiet ultricies, urna nulla luctus sapien, et porta mi odio ac neque. Morbi dignissim. Sed risus pede, adipiscing gravida, pharetra sit amet, convallis non, orci. Morbi adipiscing mauris id massa. Nullam fermentum. Suspendisse eget est";
90 encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
91 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
92
93 //secretKey = "trustno1";
94 //plainString = "{}";
95 // plainString = "{'tags': {'personal': ['ref_1', 'ref_3'], 'business': ['ref_2', 'ref_3']}, 'records': {'ref_1': {'label': 'record_1', 'key': 'key_1'}, 'ref_2': {'label': 'record_2', 'key': 'key_2'}, 'ref_3': {'label': 'record_3', 'key': 'key_3'}}}";
96 //plainString = "{'tags': {}, 'records': {'07a5a92fcb334f757998ba14f3251f126d038318b3ac5e584bd712804c548084': {'label': 'Un bel record', 'key': '2a3f261c20a6a98dcc82b13fba013130b759f20602b4b13c5760879e087482a4'}}}";
97 //encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
98 //is(encryptedString, "{}", "encrypted value");
99
100
101 //secretKey = "trustno1";
102 //encryptedString = "0d43a4544424ffa519f2e43b7a46f703884fd94ff9879479563f6f252a573b253d3e77bc4f5f30f17bd11d2907718921ab8c9e1faccbe4314793fa323eb85eaf1bfbce5f7deea601e15b781782181cbff3c649dafef39abb70e8573e4f9be220f2286b01c3bd51d5c4a79b9d44a27be3b0994667302e301ca3dc074fb1bc7abc03d12b9e58ba0249435a120858c96e8ae99570718541499ab958a8fb92b63390be070ff61fc6ef107061693ab14c1915118cc6671ab7cf99b9cca553d6b5a7c314bffcd933e0a59f056d842a47cfe8571110b4764c5225443210d99b43b80a23c20fe953de3e1329d72cfb20139fe1ca";
103 //plainString = Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString);
104 //is(plainString, "{}", "decrypted value");
105
106 //-------------------------------------------------------------------------
107 //
108 //Java secret key encryption / JavaScript decryption
109 //
110 secretKey = "s3cr37k39";
111 plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
112 encryptedString = "9be538c3dde4dfab9384c0ef71dc624299fbbe71be8d1fe8991fd6cae88a883cf459d7cd56913a2b69815782cf74d7ce5c2c08034661f7f8aa59cf420e913086896840ebb45102d44d733d32de2a7dc8";
113 is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
114
115 //-------------------------------------------------------------------------
116 //
117 //Public key encryption -> Private key decryption
118 //
119 {
120 varcleanKey;
121 vart1, t2;
122/*
123 //
124 // 128
125 //
126 cleanKey = "248d6a61d20638b8e5c026930c3e6039"; //a33ce45964ff2167f6ecedd419db06c1";
127 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
128 "10001",
129 "202700adbd85e2d7182720c3a0ee19c1",
130 "30db31542ace0f7d37a629ee5eba28cb"
131 );
132 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
133
134 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 128");
135 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 128");
136 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 128");
137*/
138/*
139 //
140 // 256
141 //
142 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
143 cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
144 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
145 "10001",
146 "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
147 "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
148 );
149 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
150
151 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 256");
152 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 256");
153 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 256");
154*/
155/*
156 //
157 //512
158 //
159 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
160 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
161 "10001",
162 "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
163 "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
164 );
165t1 = new Date().getTime();
166 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
167t2 = new Date().getTime();
168//is("Encrypting with public key (512)", (t2 - t1));
169
170 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 512");
171t1 = new Date().getTime();
172 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 512");
173t2 = new Date().getTime();
174//is("Decrypting with private key (512)", (t2 - t1));
175 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 512");
176*/
177/*
178 //
179 //1024
180 //
181 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
182 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
183 "10001",
184 "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
185 "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
186 );
187t1 = new Date().getTime();
188 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
189t2 = new Date().getTime();
190is("Encrypting with public key (1024)", (t2 - t1));
191
192 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 1024");
193t1 = new Date().getTime();
194 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 1024");
195t2 = new Date().getTime();
196is("Decrypting with private key (1024)", (t2 - t1));
197 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 1024");
198*/
199/*
200 //
201 //2048
202 //
203 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
204 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
205 "10001",
206 "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
207 "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
208 );
209t1 = new Date().getTime();
210 encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
211t2 = new Date().getTime();
212is("Encrypting with public key (2048)", (t2 - t1));
213
214 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 2048");
215t1 = new Date().getTime();
216 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 2048");
217t2 = new Date().getTime();
218is("Decrypting with private key (2048)", (t2 - t1));
219 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 2048");
220*/
221 }
222
223 //-------------------------------------------------------------------------
224 //
225 //Private key encryption -> Public key decryption
226 //
227 {
228 varcleanKey;
229 vart1, t2;
230/*
231 //
232 // 128
233 //
234 cleanKey = "248d6a61d20638b8e5c026930c3e6039"; //a33ce45964ff2167f6ecedd419db06c1";
235 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
236 "10001",
237 "202700adbd85e2d7182720c3a0ee19c1",
238 "30db31542ace0f7d37a629ee5eba28cb"
239 );
240 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
241
242 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 128");
243 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 128");
244 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 128");
245*/
246/*
247 //
248 // 256
249 //
250 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
251 cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
252 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
253 "10001",
254 "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
255 "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
256 );
257 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
258
259 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 256");
260 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 256");
261 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 256");
262*/
263/*
264 //
265 //512
266 //
267 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
268 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
269 "10001",
270 "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
271 "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
272 );
273t1 = new Date().getTime();
274 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
275t2 = new Date().getTime();
276//is("Encrypting with private key (512)", (t2 - t1));
277
278 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 512");
279t1 = new Date().getTime();
280 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 512");
281t2 = new Date().getTime();
282//is("Decrypting with public key (512)", (t2 - t1));
283 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 512");
284*/
285/*
286 //
287 //1024
288 //
289 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
290 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
291 "10001",
292 "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
293 "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
294 );
295t1 = new Date().getTime();
296 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
297t2 = new Date().getTime();
298is("Encrypting with private key (1024)", (t2 - t1));
299
300 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 1024");
301t1 = new Date().getTime();
302 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 1024");
303t2 = new Date().getTime();
304is("Decrypting with public key (1024)", (t2 - t1));
305 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 1024");
306*/
307/*
308 //
309 //2048
310 //
311 cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
312 publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
313 "10001",
314 "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
315 "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
316 );
317t1 = new Date().getTime();
318 encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
319t2 = new Date().getTime();
320is("Encrypting with private key (2048)", (t2 - t1));
321
322 is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 2048");
323t1 = new Date().getTime();
324 is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 2048");
325t2 = new Date().getTime();
326is("Decrypting with public key (2048)", (t2 - t1));
327 isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 2048");
328*/
329 }
330
331 varoriginalMessage;
332 varprocessedMessage;
333 var expectedResult;
334
335 //-------------------------------------------------------------------------
336 //
337 // HashSHA-256
338 //
339
340 originalMessage = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
341 expectedResult = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
342 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
343 is(processedMessage, expectedResult, "");
344
345 originalMessage = "";
346 expectedResult = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
347 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
348 is(processedMessage, expectedResult, "");
349
350 originalMessage = "abc";
351 expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
352 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
353 is(processedMessage, expectedResult, "");
354
355 originalMessage = "message digest";
356 expectedResult = "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650";
357 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
358 is(processedMessage, expectedResult, "");
359
360 originalMessage = "secure hash algorithm";
361 expectedResult = "f30ceb2bb2829e79e4ca9753d35a8ecc00262d164cc077080295381cbd643f0d";
362 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
363 is(processedMessage, expectedResult, "");
364
365 originalMessage = "SHA256 is considered to be safe";
366 expectedResult = "6819d915c73f4d1e77e4e1b52d1fa0f9cf9beaead3939f15874bd988e2a23630";
367 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
368 is(processedMessage, expectedResult, "");
369
370 originalMessage = "For this sample, this 63-byte string will be used as input data";
371 expectedResult = "f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342";
372 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
373 is(processedMessage, expectedResult, "");
374
375 originalMessage = "This is exactly 64 bytes long, not counting the terminating byte";
376 expectedResult = "ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8";
377 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
378 is(processedMessage, expectedResult, "");
379
380 originalMessage = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut urna diam, vulputate quis, tempus vel, pretium in, mauris. Mauris aliquet sem a elit. Nunc molestie rutrum sem.";
381 expectedResult = "528059709af4087fb8cd4427e291d89f24d8c0429b2a3b6fd152c32ce5b4680f";
382 processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
383 is(processedMessage, expectedResult, "");
384
385 //-------------------------------------------------------------------------
386 //
387 // HashMD5
388 //
389 originalMessage = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da9";
390 expectedResult = "fde790d7da7d0d54a8db4ac500f1bbdb";
391 processedMessage = Clipperz.Crypto.Base.computeMD5HashValue(originalMessage);
392 is(processedMessage, expectedResult, "");
393
394
395
396
397 //-------------------------------------------------------------------------
398 //
399 //Random seed
400 //
401 varrandomSeed;
402
403 randomSeed = Clipperz.Crypto.Base.generateRandomSeed();
404 is(randomSeed.length, 64, "");
405
406 ok(randomSeed != Clipperz.Crypto.Base.generateRandomSeed(), "");
407
408//#############################################################################
409
410} catch (err) {
411
412 var s = "test suite failure!\n";
413 var o = {};
414 var k = null;
415 for (k in err) {
416 // ensure unique keys?!
417 if (!o[k]) {
418 s += k + ": " + err[k] + "\n";
419 o[k] = err[k];
420 }
421 }
422 ok ( false, s );
423}
424
425</script>
426</pre>
427</body>
428</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html b/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html
new file mode 100644
index 0000000..bdb0cbc
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html
@@ -0,0 +1,478 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
38 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
39 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
40
41 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
44</head>
45<body>
46<pre id="test">
47<script type="text/javascript">
48try {
49 varbigInt_1;
50 varbigInt_2;
51 varresult;
52 varexpectedResult;
53
54 //
55 //Constructur and equality test
56 //
57 bigInt_1 = new Clipperz.Crypto.BigInt("110");
58 is (bigInt_1.equals(bigInt_1), true, "");
59
60 bigInt_1 = new Clipperz.Crypto.BigInt("110");
61 bigInt_2 = new Clipperz.Crypto.BigInt("110", 10);
62 is (bigInt_1.equals(bigInt_2), true, "");
63
64 bigInt_1 = new Clipperz.Crypto.BigInt("110");
65 bigInt_2 = new Clipperz.Crypto.BigInt(110);
66 is (bigInt_1.equals(bigInt_2), true, "");
67
68 bigInt_1 = new Clipperz.Crypto.BigInt(6);
69 bigInt_2 = new Clipperz.Crypto.BigInt("110", 2);
70 is (bigInt_1.equals(bigInt_2), true, "");
71
72 bigInt_1 = new Clipperz.Crypto.BigInt(6);
73 bigInt_2 = new Clipperz.Crypto.BigInt("110", 3);
74 is (bigInt_1.equals(bigInt_2), false, "");
75
76
77 //
78 //Addition test
79 //
80 bigInt_1 = new Clipperz.Crypto.BigInt(6);
81 bigInt_2 = new Clipperz.Crypto.BigInt(110);
82 result = bigInt_1.add(bigInt_2);
83 expectedResult = new Clipperz.Crypto.BigInt(116);
84 is (result.equals(expectedResult), true, "");
85 is (result.equals(Clipperz.Crypto.BigInt.add(bigInt_1, bigInt_2)), true, "instance method === static function");
86
87 bigInt_1 = new Clipperz.Crypto.BigInt(6);
88 result = bigInt_1.add(6);
89 expectedResult = new Clipperz.Crypto.BigInt(12);
90 is (result.equals(expectedResult), true, "");
91
92 bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
93 bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
94 result = bigInt_1.add(bigInt_2);
95 expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585858585858585858585858585858585");
96 is (result.equals(expectedResult), true, "");
97
98 bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
99 bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
100 result = bigInt_1.add(bigInt_2);
101 expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585851585858585858585858585858585");
102 is (result.equals(expectedResult), false, "");
103
104 bigInt_1 = new Clipperz.Crypto.BigInt("86161616161616161616161616161616161616161616161616161");
105 bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
106 result = bigInt_1.add(bigInt_2);
107 expectedResult = new Clipperz.Crypto.BigInt("128585858585858585858585858585858585858585858585858585");
108 is (result.equals(expectedResult), true, "");
109
110 bigInt_1 = new Clipperz.Crypto.BigInt("6541652165410321654063516540621063540654" +
111 "0654065106540654165416521654103216540635" +
112 "1654062106354065406540651065406541");
113 bigInt_2 = new Clipperz.Crypto.BigInt("3046540351035403510354035103510351351351" +
114 "0351350435103213540634132135401351035403" +
115 "5403540354103540");
116 result = bigInt_1.add(bigInt_2);
117 expectedResult = new Clipperz.Crypto.BigInt("6541652165410321657110056891656467051008" +
118 "1005100210054167675767872089206430081269" +
119 "2975416119864419441944191419510081");
120 is (result.equals(expectedResult), true, "");
121
122
123 //
124 //Moltiplication test
125 //
126 bigInt_1 = new Clipperz.Crypto.BigInt(6);
127 bigInt_2 = new Clipperz.Crypto.BigInt(110);
128 result = bigInt_1.multiply(bigInt_2);
129 expectedResult = new Clipperz.Crypto.BigInt(660);
130 is (result.equals(expectedResult), true, "");
131
132 bigInt_1 = new Clipperz.Crypto.BigInt(6);
133 result = bigInt_1.multiply(5);
134 expectedResult = new Clipperz.Crypto.BigInt(30);
135 is (result.equals(expectedResult), true, "");
136
137 bigInt_1 = new Clipperz.Crypto.BigInt("5465465165465465132743540354354032135463" +
138 "5435135403513516843052413543054035");
139 bigInt_2 = new Clipperz.Crypto.BigInt("3543513543543213543032135435413054365430" +
140 "5130513540351354354305435403");
141 result = bigInt_1.multiply(bigInt_2);
142 expectedResult = new Clipperz.Crypto.BigInt("1936694983559052629352223965314822970014" +
143 "6364423657014976098029153153101751605574" +
144 "5077086464435601381095664357540911830059" +
145 "9503335163757031001105");
146 is (result.equals(expectedResult), true, "");
147
148 //
149 //Module test
150 //
151 bigInt_1 = new Clipperz.Crypto.BigInt(106);
152 bigInt_2 = new Clipperz.Crypto.BigInt(10);
153 result = bigInt_1.module(bigInt_2);
154 expectedResult = new Clipperz.Crypto.BigInt(6);
155 is (result.equals(expectedResult), true, "");
156
157 bigInt_1 = new Clipperz.Crypto.BigInt(106);
158 result = bigInt_1.module(10);
159 expectedResult = new Clipperz.Crypto.BigInt(6);
160 is (result.equals(expectedResult), true, "");
161
162 bigInt_1 = new Clipperz.Crypto.BigInt("5465465465468468465468463541358438543513" +
163 "8543135435135423545624354235123512531235" +
164 "1356463543840351351305135435121354305413" +
165 "543");
166
167
168 bigInt_2 = new Clipperz.Crypto.BigInt("3543543213543213540543545463542354385768" +
169 "512584354354215");
170 result = bigInt_1.module(bigInt_2);
171 expectedResult = new Clipperz.Crypto.BigInt("52689987206612998786765715819079250963638640081836513");
172 is (result.equals(expectedResult), true, "");
173
174 //
175 //Power (Module) test
176 //
177 bigInt_1 = new Clipperz.Crypto.BigInt(6);
178 bigInt_2 = new Clipperz.Crypto.BigInt(3);
179 result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt(1000));
180 expectedResult = new Clipperz.Crypto.BigInt(216);
181 is (result.equals(expectedResult), true, "");
182
183 bigInt_1 = new Clipperz.Crypto.BigInt(6);
184 result = bigInt_1.powerModule(3, 1000);
185 expectedResult = new Clipperz.Crypto.BigInt(216);
186 is (result.equals(expectedResult), true, "");
187
188 bigInt_1 = new Clipperz.Crypto.BigInt("354354354354687638546846846846846576876468746846846846");
189 bigInt_2 = new Clipperz.Crypto.BigInt("354");
190 result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt("3543541354354354354354351354354351354354354354354354"));
191 expectedResult = new Clipperz.Crypto.BigInt("1957028940698171231089373321334263118681605242465644");
192 is (result.equals(expectedResult), true, "");
193
194 bigInt_1 = new Clipperz.Crypto.BigInt("e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", 16);
195 //is(bigInt_1.toString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "IE bug");
196 is(bigInt_1.asString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "fix for IE bug");
197
198
199 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
200 is(bigInt_1.asString(16, 64), "000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "fix to ensure the string representation has a minimum fixed length");
201
202/*
203 //
204 //Comparison
205 //
206 bigInt_1 = new Clipperz.Crypto.BigInt("0", 10);
207 bigInt_2 = new Clipperz.Crypto.BigInt("0", 10);
208 is (bigInt_1.equals(bigInt_2), true, "bigInt(0) = bigInt(0)");
209 is (bigInt_1.equals(0), true, "bigInt(0) = 0");
210
211 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
212 is (bigInt_1.equals(bigInt_2), false, "bigInt(xxxxxx) != bigInt(0)");
213 is (bigInt_1.equals(0), false, "bigInt(xxxxx) != 0");
214
215 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
216 bigInt_2 = new Clipperz.Crypto.BigInt("0", 16);
217 is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(0)");
218 is(bigInt_2.compare(bigInt_1), -1, "bigInt(0) < bigInt(xxxx)");
219
220 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
221 bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
222 is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(05)");
223 is(bigInt_2.compare(bigInt_1), -1, "bigInt(05) < bigInt(xxxx)");
224
225 bigInt_1 = new Clipperz.Crypto.BigInt("-10", 10);
226 bigInt_2 = new Clipperz.Crypto.BigInt("10", 10);
227 is(bigInt_1.equals(bigInt_2), true, "bigInt(-10) - bigInt(10). No negative number are managed");
228
229 //
230 //XOR
231 //
232 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
233 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
234 result = bigInt_1.xor(bigInt_2);
235 expectedResult = new Clipperz.Crypto.BigInt(0);
236 is(result.asString(16), expectedResult.asString(16), "a xor a = 0");
237
238 //
239 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
240 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
241 result = bigInt_1.xor(bigInt_2);
242 expectedResult = new Clipperz.Crypto.BigInt('295147905179352825856');
243 is(result.asString(16), expectedResult.asString(16), "single bit difference");
244
245 //
246 bigInt_1 = new Clipperz.Crypto.BigInt("01", 16);
247 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
248 result = bigInt_1.xor(bigInt_2);
249 expectedResult = new Clipperz.Crypto.BigInt('102987336249554097029535212322581322789799900648198034993674544906295017912404');
250 is(result.asString(16), expectedResult.asString(16), "01 xor value");
251
252 //
253 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
254 bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
255 result = bigInt_1.xor(bigInt_2);
256 expectedResult = new Clipperz.Crypto.BigInt('7237005577332262213973186563042994240829374041602535252466099000494570602496');
257 is(result.asString(16), expectedResult.asString(16), "first bit difference xor");
258
259
260 //
261 //isBitSet
262 //
263 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
264 result = bigInt_1.isBitSet(1);
265 expectedResult = true;
266 is(result, expectedResult, "'ff'.isBitSet(1)");
267
268 bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
269 result = bigInt_1.isBitSet(1);
270 expectedResult = false;
271 is(result, expectedResult, "'f0'.isBitSet(1)");
272
273 bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
274 result = bigInt_1.isBitSet(3);
275 expectedResult = false;
276 is(result, expectedResult, "'f0'.isBitSet(3)");
277
278 bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
279 result = bigInt_1.isBitSet(4);
280 expectedResult = true;
281 is(result, expectedResult, "'f0'.isBitSet(4)");
282
283 bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
284 result = bigInt_1.isBitSet(7);
285 expectedResult = false;
286 is(result, expectedResult, "'ff00'.isBitSet(7)");
287
288 bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
289 result = bigInt_1.isBitSet(8);
290 expectedResult = true;
291 is(result, expectedResult, "'ff00'.isBitSet(8)");
292
293 //
294 bigInt_1 = new Clipperz.Crypto.BigInt("05000000000000", 16);
295 result = bigInt_1.isBitSet(47);
296 expectedResult = false;
297 is(result, expectedResult, "'05000000000000'.isBitSet(47)");
298
299 result = bigInt_1.isBitSet(48);
300 expectedResult = true;
301 is(result, expectedResult, "'05000000000000'.isBitSet(48)");
302
303 result = bigInt_1.isBitSet(49);
304 expectedResult = false;
305 is(result, expectedResult, "'05000000000000'.isBitSet(49)");
306
307 result = bigInt_1.isBitSet(50);
308 expectedResult = true;
309 is(result, expectedResult, "'05000000000000'.isBitSet(50)");
310
311 result = bigInt_1.isBitSet(51);
312 expectedResult = false;
313 is(result, expectedResult, "'05000000000000'.isBitSet(51)");
314
315 //
316 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
317
318 result = bigInt_1.isBitSet(52);
319 expectedResult = true;
320 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)");
321
322 result = bigInt_1.isBitSet(53);
323 expectedResult = false;
324 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)");
325
326 result = bigInt_1.isBitSet(54);
327 expectedResult = false;
328 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)");
329
330 result = bigInt_1.isBitSet(55);
331 expectedResult = true;
332 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)");
333
334 result = bigInt_1.isBitSet(56);
335 expectedResult = false;
336 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)");
337
338 result = bigInt_1.isBitSet(57);
339 expectedResult = false;
340 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)");
341
342 result = bigInt_1.isBitSet(58);
343 expectedResult = true;
344 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)");
345
346 result = bigInt_1.isBitSet(59);
347 expectedResult = false;
348 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)");
349
350 result = bigInt_1.isBitSet(60);
351 expectedResult = false;
352 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)");
353
354 //
355 //shiftLeft
356 //
357 bigInt_1 = new Clipperz.Crypto.BigInt("7f", 16);
358 result = bigInt_1.shiftLeft(1);
359 expectedResult = new Clipperz.Crypto.BigInt('fe', 16);
360 is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)");
361
362 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
363 result = bigInt_1.shiftLeft(1);
364 expectedResult = new Clipperz.Crypto.BigInt('01fe', 16);
365 is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)");
366
367 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
368 result = bigInt_1.shiftLeft(2);
369 expectedResult = new Clipperz.Crypto.BigInt('411949344998216388118140849290325291159199602592792139973517588004462660346196', 10);
370 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
371
372 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
373 result = bigInt_1.shiftLeft(8);
374 expectedResult = new Clipperz.Crypto.BigInt('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16);
375 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(8)");
376
377 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
378 result = bigInt_1.shiftLeft(10);
379 expectedResult = new Clipperz.Crypto.BigInt('105459032319543395358244057418323274536755098263754787833220502529142441048626176', 10);
380 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
381
382 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
383 result = bigInt_1.shiftLeft(4096);
384 expectedResult = new Clipperz.Crypto.BigInt('266319164760353889206396941232739217557890883507082863997979538237408246532747151496450837043424377376926977212182012023686831226737377369852125202402098145876219029018646049576792205484267848170179157853023266287725961304046416750146445344507869587461686016719979944538177432428730245324189334334817497396705169439104855885416460935698516539852892760625369984672271807592980051379072961966267124963131928067770749329011150668180796667192392027523071601150548205543997146350727148885425131890513407882508735446345822174200042918879518190588482963417582471561436215675823872015307629566605147920139961896995509627341070659007877630760561618021922340198636222738900413041589858099507891702174848695380017286939422770656819923801325579542295611580916900945707539132241939193098989585491346846486694653352501301851631933610655701026861715541355665900384634131852357081890301147104554877895768806174478161952060916705243614916310627428392386264214492834954273769685672081818149530274447979003153864646452529328518204716201193108795473912970645455457215455929896570875795325190705652768977680951535622436287312272907838194995042100153360373621439300266297151905265332115434133380301670205335338558744799343198526203012170200626802804318535680', 10);
385 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
386
387 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
388 result = bigInt_1.shiftLeft(5000);
389 expectedResult = new Clipperz.Crypto.BigInt('36017909319555363939297846508911757008556852467205798478749046189356513330989041570231272721076143922520578818149998351104871978707844731275672652360293180474918203352225676748028889909508585302690242044220987556901043359920075229167479636668489487021705618421769517884399224788393498408327257966673365451264730932480701037648195190724361287852846952667257156204462064385766889505990099642052739974651257588866645027017486311782036674195285521311468922365736517586569614071211079825802088151607502649165228246449902253708785396560087430392277977851200155957347440614508171640900912431375050142178348130480158080696562512167652410483775588091117019722112093545783277082149415339867358805673644654236371762589715111732737686904860620316822561292797144756685380676343141118415434643259498221414744450502163805872581378284735047416230112208369784803081434462030568662742790926051825877463257023387907801068796855629691810029349692983890802136654401365294584656484852908751516361546884362396124203127393434938355516740711953765305060269622960662047729516459906444429108776596594293559927265789943280929098971285454533928986078946124455350540187565506016643147748500262510780357259199808936108629893209819473029835119866186316144675107047007737043503194737001430981972314376700993832503282107582239603281145093446879837002884732470988727066207277180181469885503549870618810897831820650576980763622189213611885522245978572420535750015505830146119605502167931087454823309031494727688701857532561113118183883936890880', 10);
390 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
391
392
393 //
394 //BigInt compare vs ByteArray compare
395 //
396 var bigInt_byteArray_1;
397 var bigInt_byteArray_2;
398
399 //
400 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
401 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
402 bitInt_byteArray_1 = bigInt_1.asByteArray();
403 bitInt_byteArray_2 = bigInt_2.asByteArray();
404
405 result = bigInt_1.compare(bigInt_2);
406 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
407 is(result, expectedResult, "equal compare");
408
409 //
410 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
411 bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
412 bitInt_byteArray_1 = bigInt_1.asByteArray();
413 bitInt_byteArray_2 = bigInt_2.asByteArray();
414
415 result = bigInt_1.compare(bigInt_2);
416 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
417 is(result, expectedResult, "second term with one more bit at the leftmost - compare");
418
419 //
420 bigInt_1 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
421 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
422 bitInt_byteArray_1 = bigInt_1.asByteArray();
423 bitInt_byteArray_2 = bigInt_2.asByteArray();
424
425 result = bigInt_1.compare(bigInt_2);
426 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
427 is(result, expectedResult, "first term with one more bit at the leftmost - compare");
428
429 //
430 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
431 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
432 bitInt_byteArray_1 = bigInt_1.asByteArray();
433 bitInt_byteArray_2 = bigInt_2.asByteArray();
434
435 result = bigInt_1.compare(bigInt_2);
436 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
437 is(result, expectedResult, "first term with one more bit in the middle - compare");
438
439 //
440 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
441 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427aeffffffffffffffffffffffffffff", 16);
442 bitInt_byteArray_1 = bigInt_1.asByteArray();
443 bitInt_byteArray_2 = bigInt_2.asByteArray();
444
445 result = bigInt_1.compare(bigInt_2);
446 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
447 is(result, expectedResult, "first term with one more bit in the middle - compare");
448
449 //
450 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
451 bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
452 bitInt_byteArray_1 = bigInt_1.asByteArray();
453 bitInt_byteArray_2 = bigInt_2.asByteArray();
454
455 result = bigInt_1.compare(bigInt_2);
456 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
457 is(result, expectedResult, "equal compare");
458*/
459 //-------------------------------------------------------------------------
460} catch (err) {
461
462 var s = "test suite failure!\n";
463 var o = {};
464 var k = null;
465 for (k in err) {
466 // ensure unique keys?!
467 if (!o[k]) {
468 s += k + ": " + err[k] + "\n";
469 o[k] = err[k];
470 }
471 }
472 ok ( false, s );
473}
474
475</script>
476</pre>
477</body>
478</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.B283.deferred.html b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.B283.deferred.html
new file mode 100644
index 0000000..ba98167
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.B283.deferred.html
@@ -0,0 +1,155 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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<!-- - ->
32 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
33<!- - -->
34<!-- -->
35 <script type="text/javascript" src="../../../../js/MochiKit/Base.js"></script>
36 <script type="text/javascript" src="../../../../js/MochiKit/Async.js"></script>
37 <script type="text/javascript" src="../../../../js/MochiKit/DOM.js"></script>
38 <script type="text/javascript" src="../../../../js/MochiKit/Logging.js"></script>
39 <script type="text/javascript" src="../../../../js/MochiKit/Iter.js"></script>
40<!-- -->
41
42<!-- - ->
43 <script type="text/javascript" src="../../../../js/MochiKit/Style.js"></script>
44 <script type="text/javascript" src="../../../../js/MochiKit/Signal.js"></script>
45 <script type="text/javascript" src="../../../../js/MochiKit/Color.js"></script>
46 <script type="text/javascript" src="../../../../js/MochiKit/Position.js"></script>
47 <script type="text/javascript" src="../../../../js/MochiKit/Visual.js"></script>
48<!- - -->
49
50
51 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
52 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
53
54<!--<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>-->
55<!--<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>-->
56<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>-->
57
58 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
59 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
60 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
61 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
62
63 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/StandardCurves.js'></script>
64
65</head>
66<body>
67<pre id="test">
68<script type="text/javascript">
69try {
70
71 var deferredResult;
72
73
74 deferredResult = new MochiKit.Async.Deferred();
75//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 1: " + res); return res;});
76
77 //
78 //ECC.Curve.multiplication
79 //
80 varcurve;
81 var f2m;
82 var f2m_improved;
83 var value;
84 var moduledValue;
85 var result;
86 var result_improved;
87 var expectedResul;
88
89 f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
90 f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B283().finiteField();
91
92 curve = Clipperz.Crypto.ECC.StandardCurves.B283();
93
94/** /
95 value = new Clipperz.Crypto.ECC.BinaryField.Value("7b", 16);
96 result = curve.multiply(value, curve.G());
97 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Point({
98 x: new Clipperz.Crypto.ECC.BinaryField.Value('29705d23a9cda75e43984bdb9a8fd33304682da0f506a69bdbd5f36657e11b41e35fcdd', 16),
99 y: new Clipperz.Crypto.ECC.BinaryField.Value('59157d2ace16563a905361c5206cc0775c3330f4978bddf8aa9916c451cf9951313623b', 16)
100 });
101 is(result.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
102 is(result.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
103/ **/
104
105 value = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
106
107//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 6: " + res); return res;});
108 //deferredResult.addCallback(console.time, 'B283.deferred.multiply - moduled value');
109//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("2 - " + res); return res;});
110//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 7: " + res); return res;});
111 deferredResult.addMethod(curve, 'deferredMultiply', value, curve.G());
112//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("3 - " + res); return res;});
113//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 8: " + res); return res;});
114 //deferredResult.addBoth(function(res) {console.timeEnd('B283.deferred.multiply - moduled value'); return res;});
115//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("4 - " + res); return res;});
116//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 9: " + res); return res;});
117 deferredResult.addCallback(function(res) {
118 var expectedResult;
119
120 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Point({
121 x: new Clipperz.Crypto.ECC.BinaryField.Value('7cf07c0880d1ae59f567a2ce420e78d1fdfc1249df694a60e5d40d23c6dc631e1501b77', 16),
122 y: new Clipperz.Crypto.ECC.BinaryField.Value('97d1257d5c98cf71cf481bc0a495e0588150ea904526f503cd600f5e971c39700e95f1', 16)
123 });
124
125 is(res.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
126 is(res.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
127 })
128//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("5 - " + res); return res;});
129//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 10: " + res); return res;});
130 deferredResult.addBoth(function(res) {SimpleTest.finish(); return res;});
131 deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug(res); return res;});
132 deferredResult.callback();
133
134 SimpleTest.waitForExplicitFinish();
135
136 //-------------------------------------------------------------------------
137} catch (err) {
138
139 var s = "test suite failure!\n";
140 var o = {};
141 var k = null;
142 for (k in err) {
143 // ensure unique keys?!
144 if (!o[k]) {
145 s += k + ": " + err[k] + "\n";
146 o[k] = err[k];
147 }
148 }
149 ok ( false, s );
150}
151
152</script>
153</pre>
154</body>
155</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.B283.html b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.B283.html
new file mode 100644
index 0000000..3d7efaa
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.B283.html
@@ -0,0 +1,209 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
38
39 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
40 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
41<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
44 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
45 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
46 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
47</head>
48<body>
49<pre id="test">
50<script type="text/javascript">
51try {
52 //
53 //ECC.BinaryFiniteField
54 //
55 varf2m;
56 varf2m_improved;
57 var a, a1, b;
58 var result;
59 var result_improved;
60 var expectedResul;
61
62 f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
63 f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B283().finiteField();
64 a = new Clipperz.Crypto.ECC.BinaryField.Value("05c91e41 d9ca17ef 9d8a33c1 a44eba6d 368fde02 1c492077 1a46eb01 a481e5f7 f430749d", 16);
65 b = new Clipperz.Crypto.ECC.BinaryField.Value("07377071 2de7d57b a803f65f 45786c06 876b8066 db75ec47 81c053b0 a0f78e2c a6ab5187", 16);
66
67 //
68 //addition
69 //
70 result = f2m.add(a, b);
71 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
72 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.add");
73
74
75 //
76 //negation
77 //
78 result = f2m.negate(a);
79 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
80 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.negate");
81
82
83 //
84 //multiplication
85 //
86 result = f2m.multiply(a, b);
87 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2bacb89668741f6d1f7fd7d3df2f045814086adba11d8bb5f12f3f9851e3b66fbe283cb", 16);
88 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.multiply");
89
90
91 //
92 //fast multiplication
93 //
94 result = f2m.fastMultiply(a, b);
95 expectedResult = f2m.multiply(a, b);
96 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
97
98 a = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
99 b = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
100 result = f2m.fastMultiply(a, b);
101 expectedResult = f2m.multiply(a, b);
102 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.B283.fastMultiply");
103
104 //
105 //square
106 //
107 a = new Clipperz.Crypto.ECC.BinaryField.Value("1111", 16);
108 result = f2m.square(a);
109 expectedResult = f2m.multiply(a, a);
110 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
111
112 a = new Clipperz.Crypto.ECC.BinaryField.Value("11111111", 16);
113 result = f2m.square(a);
114 expectedResult = f2m.multiply(a, a);
115 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
116
117 a = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
118 result = f2m.square(a);
119 expectedResult = f2m.multiply(a, a);
120 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
121
122
123 //
124 //inverse
125 //
126 a = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
127 result = f2m.inverse(a);
128 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("3812fc574f3728c60384e141c0e2a808e21adec22dcd407b9e25dd13c6d1bf22defd84a", 16);
129 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.inverse");
130
131
132 //
133 //module
134 //
135
136 a = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
137 a1 = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
138 result = f2m.module(a);
139 result_improved = f2m_improved.module(a1);
140 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2bacb89668741f6d1f7fd7d3df2f045814086adba11d8bb5f12f3f9851e3b66fbe283cb", 16);
141 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module");
142 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved)");
143 is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods");
144
145
146 a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
147 a1 = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
148 result = f2m.module(a);
149 result_improved = f2m_improved.module(a1);
150 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("15e2097d116e745ac47480807cb5eb99dad902728aaf5692241063bc70a5b372dbce798", 16);
151 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (2)");
152 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (2)");
153 is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (2)");
154
155
156 a = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
157 a1 = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
158 result = f2m.module(a);
159 result_improved = f2m_improved.module(a1);
160 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("40f04cec8fe9caedf82adeff7e1aa06dcb9d08e097db8be2ad54b2ddc2e752152395623", 16);
161 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (3)");
162 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (3)");
163 is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (3)");
164
165
166 a = new Clipperz.Crypto.ECC.BinaryField.Value("02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
167 is(a.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value as expected (4)")
168 a1 = new Clipperz.Crypto.ECC.BinaryField.Value("02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
169 result = f2m.module(a);
170 result_improved = f2m_improved.module(a1);
171 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
172 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (4)");
173 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (4)");
174 is(result_improved.asString(16), "ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", "ECC.BinaryFinetField.module (static check) (4)");
175 is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (4)");
176
177 is(a.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value preserved by standard method (4)")
178 is(a1.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value preserved by improved method (4)")
179
180
181 a = new Clipperz.Crypto.ECC.BinaryField.Value("2f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
182 result_improved = f2m_improved.module(a);
183 result = f2m.module(a);
184 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
185 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (5)");
186 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (5)");
187 is(result_improved.asString(16), "ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", "ECC.BinaryFinetField.module (static check) (5)");
188 is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (5)");
189
190 //-------------------------------------------------------------------------
191} catch (err) {
192
193 var s = "test suite failure!\n";
194 var o = {};
195 var k = null;
196 for (k in err) {
197 // ensure unique keys?!
198 if (!o[k]) {
199 s += k + ": " + err[k] + "\n";
200 o[k] = err[k];
201 }
202 }
203 ok ( false, s );
204}
205
206</script>
207</pre>
208</body>
209</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.html b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.html
new file mode 100644
index 0000000..6bddb26
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.FiniteField.html
@@ -0,0 +1,183 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
38
39 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
40 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
41<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
44 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
45 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
46 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
47</head>
48<body>
49<pre id="test">
50<script type="text/javascript">
51try {
52 //
53 //ECC.BinaryFiniteField
54 //
55 varf2m;
56 varf2m_improved;
57 var a, b;
58 var result;
59 var result_improved;
60 var expectedResul;
61
62 f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425', 16)})
63 f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B571().finiteField();
64 a = new Clipperz.Crypto.ECC.BinaryField.Value("01401ca8 7b8f1446 84a2c58a e9308c23 7789e4bf 1f36dd11 7c150b7d 6076dd1d a6197fe4 c5225a06 4db0e422 2589d5ca 50eb6bb6 b7147a03 f6152843 8a8767c6 a6c4a688 3fd6f067", 16);
65 b = new Clipperz.Crypto.ECC.BinaryField.Value("0112f5c9 7e74737b 38925faf e22cea3e 12b868d4 ddea5b33 41db8fc2 e788cab7 4f0a7a3c c27087a8 93659453 69938650 a99217d5 66e13f80 dc87f082 73f7411b 6b01ef1d 399c772a", 16);
66
67 //
68 //addition
69 //
70 result = f2m.add(a, b);
71 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("52e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d", 16);
72 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.add");
73
74
75 //
76 //negation
77 //
78 result = f2m.negate(a);
79 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
80 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.negate");
81
82
83 //
84 //multiplication
85 //
86 result = f2m.multiply(a, b);
87 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("4f8e4c0ae7664b284d3b4cb1b3f9568a1ce6e6e96b5381e184fe0822cb3d5c3a3f01ffd0206355d9e5c4853472bb33cf6b2d861d6b48c39d33a360e9a63ad2f7102f92e68a12312", 16);
88 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.multiply");
89
90
91 //
92 //fast multiplication
93 //
94 result = f2m.fastMultiply(a, b);
95 expectedResult = f2m.multiply(a, b);
96 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
97
98 a = new Clipperz.Crypto.ECC.BinaryField.Value("52e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d", 16);
99 b = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
100 result = f2m.fastMultiply(a, b);
101 expectedResult = f2m.multiply(a, b);
102 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
103
104 //
105 //square
106 //
107 a = new Clipperz.Crypto.ECC.BinaryField.Value("1111", 16);
108 result = f2m.square(a);
109 expectedResult = f2m.multiply(a, a);
110 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
111
112 a = new Clipperz.Crypto.ECC.BinaryField.Value("11111111", 16);
113 result = f2m.square(a);
114 expectedResult = f2m.multiply(a, a);
115 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
116
117 a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
118 result = f2m.square(a);
119 expectedResult = f2m.multiply(a, a);
120 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
121
122
123 //
124 //inverse
125 //
126 a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
127 result = f2m.inverse(a);
128 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1f898c60983c4e807e619b9cbe528585fc33aaae419d5e5cb2107269ccdcf21d5ad5b5d78d37fa435a0d0a8a75f2506240c325c6a2eee1a03008f9e1b9c6c0a511b730cdaf9b97e", 16);
129 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.inverse");
130
131
132 //
133 //module
134 //
135
136 a = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
137 a1 = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
138 result = f2m.module(a);
139 result_improved = f2m_improved.module(a1);
140 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("4f8e4c0ae7664b284d3b4cb1b3f9568a1ce6e6e96b5381e184fe0822cb3d5c3a3f01ffd0206355d9e5c4853472bb33cf6b2d861d6b48c39d33a360e9a63ad2f7102f92e68a12312", 16);
141 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module");
142 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved)");
143 //is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods");
144
145
146 a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
147 a1 = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
148 result = f2m.module(a);
149 result_improved = f2m_improved.module(a1);
150 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1704018ce75dc462a5ccd1eb18b8002ecb8536c616ec625f440f6888f8c32387e53a5cb3b6050688e9b64a32215a385ee98c518d6a484d5ac0ceeafa825743c84b075bdfabc341b", 16);
151 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (2)");
152 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved) (2)");
153 is(a.asString(16), "1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", "ECC.BinaryFinetField.module (2)");
154 is(a1.asString(16), "1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", "ECC.BinaryFinetField.module (2)");
155
156
157 a = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
158 result = f2m.module(a);
159 result_improved = f2m_improved.module(a);
160 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("e160dd4a436e63877e1343d06576beaa66e06863ffe4335be38d6a37460a62d11133584a5bc6ac0590e18942e1fa88bb64a4d9fc6c1fd7b55d7e57b50b70a9e7cb2ed904ad77f4", 16);
161 is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (2)");
162 is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved) (2)");
163
164 //-------------------------------------------------------------------------
165} catch (err) {
166
167 var s = "test suite failure!\n";
168 var o = {};
169 var k = null;
170 for (k in err) {
171 // ensure unique keys?!
172 if (!o[k]) {
173 s += k + ": " + err[k] + "\n";
174 o[k] = err[k];
175 }
176 }
177 ok ( false, s );
178}
179
180</script>
181</pre>
182</body>
183</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.Value.html b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.Value.html
new file mode 100644
index 0000000..885bcc4
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.BinaryField.Value.html
@@ -0,0 +1,496 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
38
39 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
40 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
41<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
44 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
45 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
46 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
47</head>
48<body>
49<pre id="test">
50<script type="text/javascript">
51try {
52 var value_1;
53 var value_2;
54
55 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("a", 16);
56 is(value_1.asString(16), "0a");
57
58 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffff", 16);
59 is(value_1.asString(16), "ffff");
60
61 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("7fff", 16);
62 is(value_1.asString(16), "7fff");
63
64 is(parseInt("ffff", 16), 65535);
65 is(parseInt("ffffff", 16), 16777215);
66 is(parseInt("ffffffff", 16), 4294967295);
67 is(parseInt("ffffffffff", 16), 1099511627775);
68 is(parseInt("ffffffffffff", 16), 281474976710655);
69 is(parseInt("ffffffffffffff", 16), 72057594037927940);
70 is(parseInt("ffffffffffffffff", 16), 18446744073709552000);
71 is(parseInt("10000000000000000", 16), 18446744073709552001);
72 is(parseInt("10000000000000001", 16), 18446744073709552002);
73 is(parseInt("10000000000000009", 16), 18446744073709552010);
74
75 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
76 is(value_1.wordSize(), 8, "check the number of words of a 64 char hex string using the 'wordSize' method");
77
78 // 000108cb bacda1f0 3ea93603 01045434 ec7d82ba 150936df 08a229cb b4832ce1
79 is(value_1.value()[0], parseInt("b4832ce1", 16), "word[0]");
80 is(value_1.value()[1], parseInt("08a229cb", 16), "word[1]");
81 is(value_1.value()[2], parseInt("150936df", 16), "word[2]");
82 is(value_1.value()[3], parseInt("ec7d82ba", 16), "word[3]");
83 is(value_1.value()[4], parseInt("01045434", 16), "word[4]");
84 is(value_1.value()[5], parseInt("3ea93603", 16), "word[5]");
85 is(value_1.value()[6], parseInt("bacda1f0", 16), "word[6]");
86 is(value_1.value()[7], parseInt("000108cb", 16), "word[7]");
87
88 is(value_1.asString(16), "0108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "asString(16)");
89
90 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('10 00000000 00000000', 16);
91 is(value_1.wordSize(), 3, "check the number of words of a value with only a bit set on the first slot of byte at position 17");
92 is(value_1.value()[0], parseInt("00000000", 16), "word[0]");
93 is(value_1.value()[1], parseInt("00000000", 16), "word[1]");
94 is(value_1.value()[2], parseInt("10", 16), "word[2]");
95 is(value_1.asString(16), "100000000000000000", "2^17 asString(16)");
96
97 //
98 //XOR
99 //
100 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
101 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
102 result = value_1.xor(value_2);
103 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16);
104 is(result.asString(16), expectedResult.asString(16), "a xor a = 0");
105
106 //
107 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855', 16);
108 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b935c a495991b 7852b855', 16);
109 result = value_1.xor(value_2);
110 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('10 00000000 00000000', 16);
111 is(result.asString(16), expectedResult.asString(16), "single bit difference");
112
113 //
114 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("01", 16);
115 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855', 16);
116 result = value_1.xor(value_2);
117 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b854', 16);
118 is(result.asString(16), expectedResult.asString(16), "01 xor value");
119
120 //
121 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
122 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
123 result = value_1.xor(value_2);
124 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('1000000000000000000000000000000000000000000000000000000000000000', 16);
125 is(result.asString(16), expectedResult.asString(16), "first bit difference xor");
126
127 //
128 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('84a2c58a', 16);
129 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('38925faf', 16);
130 result = value_1.xor(value_2);
131 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('bc309a25', 16);
132 is(result.asString(16), expectedResult.asString(16), "84a2c58a XOR 38925faf = bc309a25");
133
134 //
135 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("01401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
136 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
137 result = value_1.xor(value_2);
138 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('0052e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d', 16);
139 is(result.asString(16), expectedResult.asString(16), "xor");
140
141
142 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", 16);
143 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("01ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f816429a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
144 result = value_2.xor(value_1.shiftLeft(value_2.bitSize() - value_1.bitSize()));
145 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f892e29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
146 is(result.asString(16), expectedResult.asString(16), "xor");
147 is(result.bitSize(), 1120, "xor.bitSize");
148 is(result.wordSize(), 35, "result wordSize");
149 is(expectedResult.bitSize(), 1120, "xor.bitSize");
150 is(expectedResult.wordSize(), 35, "expectedResult wordSize");
151 is(result.compare(expectedResult), 0, "compare");
152
153
154 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", 16);
155 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f892e29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
156 result = value_2.xor(value_1.shiftLeft(value_2.bitSize() - value_1.bitSize()));
157 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
158 is(result.asString(16), expectedResult.asString(16), "xor");
159 is(result.bitSize(), 1119, "xor.bitSize");
160 is(expectedResult.bitSize(), 1119, "xor.bitSize");
161 is(result.compare(expectedResult), 0, "compare");
162 //value_1 =
163 //value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 16);
164
165
166 value_1 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010 01010101 00000000", 16)).value();
167 value_2 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010", 16)).value();
168 result = new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(value_1, value_2, 2));
169 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("01010101 00000000", 16);
170 is(result.asString(16), expectedResult.asString(16), "xor with offset 2");
171
172 value_1 = (new Clipperz.Crypto.ECC.BinaryField.Value(" 10101010 01010101 00000000", 16)).value();
173 value_2 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010 10101010", 16)).value();
174 result = new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(value_1, value_2, 2));
175 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("10101010 00000000 01010101 00000000", 16);
176 is(result.asString(16), expectedResult.asString(16), "xor with offset 2 (2)");
177
178 //
179 //isZero
180 //
181 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16);
182 is(value_1.isZero(), true, "0.isZero() == true");
183
184 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('1', 16);
185 is(value_1.isZero(), false, "1.isZero() == false");
186
187 //
188 //Comparison
189 //
190 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
191 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
192 is (value_1.compare(value_2), 0, "BinaryField.value(0) = BinaryField.value(0)");
193 //is (value_1.compare(0), 0, "BinaryField.value(0) = 0");
194
195 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
196 is (value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) != BinaryField.value(0)");
197
198 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
199 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
200 is(value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) > BinaryField.value(0)");
201 is(value_2.compare(value_1), -1, "BinaryField.value(0) < BinaryField.value(xxxx)");
202
203 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
204 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("05", 16);
205 is(value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) > BinaryField.value(05)");
206 is(value_2.compare(value_1), -1, "BinaryField.value(05) < BinaryField.value(xxxx)");
207
208 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("-10", 16);
209 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("10", 16);
210 is(value_1.compare(value_2), -1, "BinaryField.value(-10) - BinaryField.value(10). No negative number are managed");
211
212 //
213 //more comparison
214 //
215
216 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
217 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
218 result = value_1.compare(value_2);
219 is(result, 0, "equal compare");
220
221 //
222 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442", 16);
223 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442", 16);
224 result = value_1.compare(value_2);
225 is(result, -1, "second term with one more bit at the leftmost - compare (1)");
226
227 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14", 16);
228 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14", 16);
229 result = value_1.compare(value_2);
230 is(result, -1, "second term with one more bit at the leftmost - compare (2)");
231
232 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8", 16);
233 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8", 16);
234 result = value_1.compare(value_2);
235 is(result, -1, "second term with one more bit at the leftmost - compare (3)");
236
237 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
238 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
239 result = value_1.compare(value_2);
240 is(result, -1, "second term with one more bit at the leftmost - compare (n)");
241
242 //
243 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442", 16);
244 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442", 16);
245 result = value_1.compare(value_2);
246 is(result, 1, "first term with one more bit at the leftmost - compare (1)");
247
248 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14", 16);
249 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14", 16);
250 result = value_1.compare(value_2);
251 is(result, 1, "first term with one more bit at the leftmost - compare (2)");
252
253 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
254 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
255 result = value_1.compare(value_2);
256 is(result, 1, "first term with one more bit at the leftmost - compare (n)");
257
258 //
259 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
260 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
261 result = value_1.compare(value_2);
262 is(result, 1, "first term with one more bit in the middle - compare");
263
264 //
265 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
266 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427aeffffffffffffffffffffffffffff", 16);
267 result = value_1.compare(value_2);
268 is(result, 1, "first term with one more bit in the middle - compare");
269
270 //
271 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
272 value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("05", 16);
273 result = value_1.compare(value_2);
274 is(result, 1, "equal compare");
275
276
277
278 //
279 //isBitSet
280 //
281 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
282 result = value_1.isBitSet(1);
283 expectedResult = true;
284 is(result, expectedResult, "'ff'.isBitSet(1)");
285
286 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
287 result =value_1.isBitSet(1);
288 expectedResult = false;
289 is(result, expectedResult, "'f0'.isBitSet(1)");
290
291 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
292 result = value_1.isBitSet(3);
293 expectedResult = false;
294 is(result, expectedResult, "'f0'.isBitSet(3)");
295
296 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
297 result = value_1.isBitSet(4);
298 expectedResult = true;
299 is(result, expectedResult, "'f0'.isBitSet(4)");
300
301 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff00", 16);
302 result = value_1.isBitSet(7);
303 expectedResult = false;
304 is(result, expectedResult, "'ff00'.isBitSet(7)");
305
306 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff00", 16);
307 result = value_1.isBitSet(8);
308 expectedResult = true;
309 is(result, expectedResult, "'ff00'.isBitSet(8)");
310
311 //
312 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("05000000000000", 16);
313 result = value_1.isBitSet(47);
314 expectedResult = false;
315 is(result, expectedResult, "'05000000000000'.isBitSet(47)");
316
317 result = value_1.isBitSet(48);
318 expectedResult = true;
319 is(result, expectedResult, "'05000000000000'.isBitSet(48)");
320
321 result = value_1.isBitSet(49);
322 expectedResult = false;
323 is(result, expectedResult, "'05000000000000'.isBitSet(49)");
324
325 result = value_1.isBitSet(50);
326 expectedResult = true;
327 is(result, expectedResult, "'05000000000000'.isBitSet(50)");
328
329 result = value_1.isBitSet(51);
330 expectedResult = false;
331 is(result, expectedResult, "'05000000000000'.isBitSet(51)");
332
333 //
334 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
335
336 result = value_1.isBitSet(52);
337 is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)");
338
339 result = value_1.isBitSet(53);
340 is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)");
341
342 result = value_1.isBitSet(54);
343 is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)");
344
345 result = value_1.isBitSet(55);
346 is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)");
347
348 result = value_1.isBitSet(56);
349 is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)");
350
351 result = value_1.isBitSet(57);
352 is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)");
353
354 result = value_1.isBitSet(58);
355 is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)");
356
357 result = value_1.isBitSet(59);
358 is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)");
359
360 result = value_1.isBitSet(60);
361 is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)");
362
363
364 //
365 //shiftLeft
366 //
367
368 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("7f", 16);
369 result = value_1.shiftLeft(1);
370 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('fe', 16);
371 is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)");
372
373 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
374 result = value_1.shiftLeft(1);
375 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('01fe', 16);
376 is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)");
377
378 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( 'ffff', 16);
379 expectedResult =new Clipperz.Crypto.ECC.BinaryField.Value('ffff00', 16);
380 result = value_1.shiftLeft(8);
381 is(result.asString(16), expectedResult.asString(16), "ffff.shiftLeft(8)");
382
383 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( '80000000', 16);
384 expectedResult =new Clipperz.Crypto.ECC.BinaryField.Value('1 00000000', 16);
385 result = value_1.shiftLeft(1);
386 is(result.compare(expectedResult) == 0, true, '8000000.shiftLeft(1).compare');
387 is(result.asString(16), expectedResult.asString(16), "80000000.shiftLeft(1)");
388
389 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('20000000', 16);
390 expectedResult =new Clipperz.Crypto.ECC.BinaryField.Value('40000000', 16);
391 result = value_1.shiftLeft(1);
392 is(result.compare(expectedResult) == 0, true, '2000000.shiftLeft(1).compare');
393 is(result.asString(16), expectedResult.asString(16), "20000000.shiftLeft(1)");
394
395 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('40000000', 16);
396 expectedResult =new Clipperz.Crypto.ECC.BinaryField.Value('80000000', 16);
397 result = value_1.shiftLeft(1);
398 is(result.compare(expectedResult) == 0, true, '4000000.shiftLeft(1).compare');
399 is(result.asString(16), expectedResult.asString(16), "40000000.shiftLeft(1)");
400
401 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( 'ff7fffff', 16);
402 expectedResult =new Clipperz.Crypto.ECC.BinaryField.Value('ff 7fffff00', 16);
403 result = value_1.shiftLeft(8);
404 is(result.asString(16), expectedResult.asString(16), "ff7fffff.shiftLeft(8)");
405
406 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( 'ffffffff', 16);
407 expectedResult =new Clipperz.Crypto.ECC.BinaryField.Value('ff ffffff00', 16);
408 result = value_1.shiftLeft(8);
409 is(result.asString(16), expectedResult.asString(16), "ffffffff.shiftLeft(8)");
410
411 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( "e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
412 expectedResult =new Clipperz.Crypto.ECC.BinaryField.Value('3 8ec3110a 63f07052 6befd322 65bee490 9eb90791 926e4d32 9256646d e14ae154', 16);
413 result = value_1.shiftLeft(2);
414 is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(10)");
415
416 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
417 result = value_1.shiftLeft(8);
418 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16);
419 is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(8)");
420
421 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
422 result = value_1.shiftLeft(10);
423 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('38e c3110a63 f070526b efd32265 bee4909e b9079192 6e4d3292 56646de1 4ae15400', 16);
424 is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(10)");
425
426 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
427 result = value_1.shiftLeft(32);
428 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff00000000', 16);
429 is(result.asString(16), expectedResult.asString(16), "ff.shiftLeft(32)");
430
431 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
432 result = value_1.shiftLeft(4096);
433 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 16);
434 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
435
436 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
437 result = value_1.shiftLeft(5000);
438 expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 16);
439 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
440
441 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
442 is(value_1.bitSize(), 0, "0.bitSize()");
443
444 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("10", 16);
445 is(value_1.bitSize(), 5, "10.bitSize()");
446
447 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("80", 16);
448 is(value_1.bitSize(), 8, "80.bitSize()");
449
450 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
451 is(value_1.bitSize(), 8, "ff.bitSize()");
452
453 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("100", 16);
454 is(value_1.bitSize(), 9, "100.bitSize()");
455
456 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("80000000", 16);
457 is(value_1.bitSize(), 32, "80000000.bitSize()");
458
459 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffffffff", 16);
460 is(value_1.bitSize(), 32, "ffffffff.bitSize()");
461
462 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("1 00000000", 16);
463 is(value_1.bitSize(), 33, "100000000.bitSize()");
464
465 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("8000 00000000", 16);
466 is(value_1.bitSize(), 48, "8000 00000000.bitSize()");
467
468 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffff ffffffff", 16);
469 is(value_1.bitSize(), 48, "ffff ffffffff.bitSize()");
470
471 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("10000 00000000", 16);
472 is(value_1.bitSize(), 49, "10000 00000000.bitSize()");
473
474 value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
475 is(value_1.bitSize(), 1119, "6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16.bitSize()");
476
477 //-------------------------------------------------------------------------
478} catch (err) {
479
480 var s = "test suite failure!\n";
481 var o = {};
482 var k = null;
483 for (k in err) {
484 // ensure unique keys?!
485 if (!o[k]) {
486 s += k + ": " + err[k] + "\n";
487 o[k] = err[k];
488 }
489 }
490 ok ( false, s );
491}
492
493</script>
494</pre>
495</body>
496</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.K283.deferred.html b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.K283.deferred.html
new file mode 100644
index 0000000..b53a9a1
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/ECC.K283.deferred.html
@@ -0,0 +1,160 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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<!-- - ->
32 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
33<!- - -->
34<!-- -->
35 <script type="text/javascript" src="../../../../js/MochiKit/Base.js"></script>
36 <script type="text/javascript" src="../../../../js/MochiKit/Async.js"></script>
37 <script type="text/javascript" src="../../../../js/MochiKit/DOM.js"></script>
38 <script type="text/javascript" src="../../../../js/MochiKit/Logging.js"></script>
39 <script type="text/javascript" src="../../../../js/MochiKit/Iter.js"></script>
40<!-- -->
41
42<!-- - ->
43 <script type="text/javascript" src="../../../../js/MochiKit/Style.js"></script>
44 <script type="text/javascript" src="../../../../js/MochiKit/Signal.js"></script>
45 <script type="text/javascript" src="../../../../js/MochiKit/Color.js"></script>
46 <script type="text/javascript" src="../../../../js/MochiKit/Position.js"></script>
47 <script type="text/javascript" src="../../../../js/MochiKit/Visual.js"></script>
48<!- - -->
49
50
51 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
52 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
53
54<!--<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>-->
55<!--<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>-->
56<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>-->
57
58<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>-->
59<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>-->
60<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>-->
61<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>-->
62
63 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Value.js'></script>
64 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Point.js'></script>
65 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/FiniteField.js'></script>
66 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Curve.js'></script>
67
68 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/StandardCurves.js'></script>
69
70</head>
71<body>
72<pre id="test">
73<script type="text/javascript">
74try {
75
76 var deferredResult;
77
78
79 deferredResult = new MochiKit.Async.Deferred();
80//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 1: " + res); return res;});
81
82 //
83 //ECC.Curve.multiplication
84 //
85 varcurve;
86 var f2m;
87 var f2m_improved;
88 var value;
89 var moduledValue;
90 var result;
91 var result_improved;
92 var expectedResul;
93
94 f2m = new Clipperz.Crypto.ECC.Koblitz.FiniteField({modulus:new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
95 f2m_improved = Clipperz.Crypto.ECC.StandardCurves.K283().finiteField();
96
97 curve = Clipperz.Crypto.ECC.StandardCurves.K283();
98
99/** /
100 value = new Clipperz.Crypto.ECC.Koblitz.Value("7b", 16);
101 result = curve.multiply(value, curve.G());
102 expectedResult = new Clipperz.Crypto.ECC.Koblitz.Point({
103 x: new Clipperz.Crypto.ECC.Koblitz.Value('29705d23a9cda75e43984bdb9a8fd33304682da0f506a69bdbd5f36657e11b41e35fcdd', 16),
104 y: new Clipperz.Crypto.ECC.Koblitz.Value('59157d2ace16563a905361c5206cc0775c3330f4978bddf8aa9916c451cf9951313623b', 16)
105 });
106 is(result.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
107 is(result.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
108/ **/
109
110 value = new Clipperz.Crypto.ECC.Koblitz.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
111
112//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 6: " + res); return res;});
113 //deferredResult.addCallback(console.time, 'K283.deferred.multiply - moduled value');
114//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("2 - " + res); return res;});
115//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 7: " + res); return res;});
116 deferredResult.addMethod(curve, 'deferredMultiply', value, curve.G());
117//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("3 - " + res); return res;});
118//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 8: " + res); return res;});
119 //deferredResult.addBoth(function(res) {console.timeEnd('K283.deferred.multiply - moduled value'); return res;});
120//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("4 - " + res); return res;});
121//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 9: " + res); return res;});
122 deferredResult.addCallback(function(res) {
123 var expectedResult;
124
125 expectedResult = new Clipperz.Crypto.ECC.Koblitz.Point({
126 x: new Clipperz.Crypto.ECC.Koblitz.Value('7cf07c0880d1ae59f567a2ce420e78d1fdfc1249df694a60e5d40d23c6dc631e1501b77', 16),
127 y: new Clipperz.Crypto.ECC.Koblitz.Value('97d1257d5c98cf71cf481bc0a495e0588150ea904526f503cd600f5e971c39700e95f1', 16)
128 });
129
130 is(res.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
131 is(res.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
132 })
133//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("5 - " + res); return res;});
134//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 10: " + res); return res;});
135 deferredResult.addBoth(function(res) {SimpleTest.finish(); return res;});
136//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 11: " + res); return res;});
137 deferredResult.callback();
138
139 SimpleTest.waitForExplicitFinish();
140
141 //-------------------------------------------------------------------------
142} catch (err) {
143
144 var s = "test suite failure!\n";
145 var o = {};
146 var k = null;
147 for (k in err) {
148 // ensure unique keys?!
149 if (!o[k]) {
150 s += k + ": " + err[k] + "\n";
151 o[k] = err[k];
152 }
153 }
154 ok ( false, s );
155}
156
157</script>
158</pre>
159</body>
160</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.html b/frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.html
new file mode 100644
index 0000000..1342349
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.html
@@ -0,0 +1,70 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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.JSCrypto_vs_Clipperz - tests</title>
32
33 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
34
35 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
36 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
37 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
38
39 <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
40
41 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
44 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
45 <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script>
46 <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
47 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
48 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
49 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
50 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
51 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
52 <script type='text/javascript' src='../../../../js/Clipperz/PM/Crypto.js'></script>
53
54 <script type='text/javascript' src='./jscrypto.js'></script>
55
56 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script>
57
58</head>
59<body>
60
61<pre id="test">
62 <script type="text/javascript">
63 var longAsciiText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam ac ipsum. Morbi mauris. Aenean ac elit id metus lobortis elementum. Proin at quam ac ipsum pellentesque adipiscing. Aenean vestibulum, nisl eu suscipit iaculis, quam pede congue mi, sit amet dapibus metus neque eget dui. Suspendisse posuere diam ac sapien. Nulla lobortis dapibus leo. Quisque ornare tortor quis turpis. Aliquam erat volutpat. Ut faucibus lacinia magna. Nunc metus leo, volutpat quis, mollis ac, sagittis ut, turpis. Quisque purus. Mauris ante enim, vehicula eu, suscipit vitae, laoreet vel, nulla. Pellentesque pede leo, aliquam quis, vehicula eget, rhoncus nec, metus. Vestibulum tellus. Suspendisse blandit. Pellentesque vel tellus. Maecenas arcu. Duis eget purus. Curabitur non pede nec odio cursus luctus. In non elit. Nullam eget nunc in nisl elementum commodo. Vivamus sollicitudin pede quis dui. Morbi commodo. Praesent a risus id urna hendrerit fermentum. Nunc ultricies tristique odio. Phasellus imperdiet, sapien eget viverra blandit, tortor risus blandit nisi, et sodales libero dolor quis nisl. Morbi vel enim. Nunc in quam. Vestibulum a magna. Fusce auctor elit in augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris tincidunt consectetuer leo. Etiam non turpis. Vestibulum eros. Praesent venenatis adipiscing augue. Pellentesque dapibus odio ac arcu rhoncus sagittis. Nullam vitae augue. Ut magna nulla, congue eu, porta in, egestas quis, ligula. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur malesuada neque non nulla. Nulla facilisi. Fusce viverra magna ut tellus. Sed rutrum pretium sapien. Vivamus dui. Cras fringilla. Nullam lorem. Vestibulum varius, purus at imperdiet fermentum, metus diam ultricies lacus, vitae aliquam ipsum libero sit amet felis. Sed eget eros ac velit commodo sollicitudin. Morbi in metus in mi viverra lacinia. Sed ut urna. Suspendisse imperdiet tellus ac velit. Duis malesuada velit sit amet sapien. Vestibulum a sapien id libero accumsan luctus. Fusce iaculis. Donec pulvinar orci ut pede. Nam placerat sem ut sem. Ut pretium bibendum nisl. Suspendisse potenti. Phasellus mollis neque in neque. Suspendisse augue magna, eleifend et, malesuada at, viverra in, nisl. Donec vel lectus in justo ultrices tristique. Aliquam erat volutpat. Morbi suscipit, risus ac volutpat mollis, risus metus hendrerit sapien, ac scelerisque est orci eu est. Quisque sit amet velit. Sed libero diam, semper id, eleifend ac, iaculis non, nulla. Donec varius tincidunt arcu. Sed quis metus eu erat adipiscing viverra. Donec odio. Aenean sagittis nisl sed purus. Fusce vel nibh quis felis accumsan bibendum. Etiam et risus ac tortor cursus pharetra. Maecenas tellus. Pellentesque nec felis id eros vehicula commodo. Aliquam interdum sagittis odio. Maecenas at lorem eget mi aliquet sagittis. Mauris quis nibh in odio sodales lacinia. Proin augue mauris, placerat a, blandit vel, tincidunt eget, ante. Quisque turpis purus, placerat eget, tempor consectetuer, aliquet ac, enim. Etiam eleifend vestibulum mi. Vivamus gravida. Morbi dolor. In hac habitasse platea dictumst. Nulla commodo lectus faucibus lorem. Phasellus aliquet pede id metus hendrerit tempus. Fusce convallis pede ac neque tempor dignissim. Sed vitae lorem sit amet justo dapibus porta. Ut quam orci, pretium non, sagittis nec, condimentum id, dolor. Sed tempor. Nunc porta rutrum leo. Nunc id sem. Sed nibh tortor, dapibus eget, feugiat a, pretium pretium, purus. Suspendisse suscipit lobortis sem. Praesent pharetra orci. Quisque molestie tristique quam. Maecenas nunc lorem, rhoncus non, venenatis sed, sodales at, felis. Quisque semper. Quisque malesuada est quis lacus. Nullam a justo. Aliquam pellentesque, ante ut congue molestie, nisl sapien posuere nisl, eu cursus nulla ligula vel nisl. Fusce commodo lacinia magna. Aenean rutrum vestibulum lorem. Pellentesque fermentum tristique ipsum. Nulla facilisi. Donec id mi eget ipsum commodo egestas. Mauris iaculis. Nulla vulputate mi at nisl. In condimentum sodales tellus. Donec metus orci, mollis vel, accumsan ac, ornare ac, lacus. Pellentesque accumsan est et tellus. Nam mollis. Aenean accumsan eros sit amet tellus. Praesent eu libero. Sed tempus urna nec dolor. Nulla facilisi. Duis eleifend rhoncus neque. Curabitur consectetuer quam eu justo. Sed metus. Vivamus risus. Aliquam erat volutpat. Aliquam erat volutpat. Nunc semper urna. Praesent molestie libero a lacus. Nullam suscipit lobortis velit. Praesent rhoncus, felis ut interdum dapibus, ipsum lectus vestibulum nulla, in interdum risus dolor eget orci. Nullam venenatis. Suspendisse laoreet, arcu a luctus consectetuer, libero ligula condimentum quam, eget elementum mauris tortor sed enim. Pellentesque leo. Nam interdum malesuada ante. Praesent fermentum nunc et dolor. Donec auctor volutpat odio. Pellentesque volutpat egestas ipsum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Cras ac ligula eu justo dignissim accumsan. Nullam nisi. Fusce id sem. Fusce et urna. Pellentesque commodo pharetra lorem. Donec erat. Vestibulum elit arcu, commodo et, consequat eget, posuere eget, sem. Morbi sed nulla sed neque commodo commodo. Aliquam erat volutpat. Ut id turpis a enim malesuada vestibulum. In arcu dui, dignissim vitae, blandit eu, egestas ac, arcu. In ultricies sapien vitae nisi. Proin rhoncus magna eget tortor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In dictum. Sed volutpat pharetra quam. Mauris eget eros. Fusce malesuada dolor id pede. Praesent nec justo sed nisi vehicula varius. In scelerisque convallis nulla. Pellentesque sodales massa vulputate urna. Duis metus urna, imperdiet ac, sodales vel, ullamcorper sed, pede. Vestibulum aliquam mollis metus. Praesent tempus tristique elit. Maecenas tellus tortor, pretium id, mollis id, molestie non, turpis. Vivamus nibh magna, bibendum vitae, a.";
64 var longIsoLatin1Text = "¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùù";
65 var longUtf8Text = "客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之";
66 </script>
67 <script type="text/javascript" src="JSCrypto_vs_Clipperz.test.js"></script>
68</pre>
69</body>
70</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.test.js b/frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.test.js
new file mode 100644
index 0000000..7dc688c
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/JSCrypto_vs_Clipperz.test.js
@@ -0,0 +1,418 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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//function logElapsedTime(aDescription, aStartTime, anEndTime) {
30 //MochiKit.Logging.logDebug(aDescription + " - took " + (anEndTime - aStartTime) + "ms");
31 //SimpleTest.ok(true, aDescription + " - took " + (anEndTime - aStartTime) + "ms");
32//}
33
34 var asciiTestString = longAsciiText;
35//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
36//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
37//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
38//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
39//asciiTestString = asciiTestString + asciiTestString;
40//asciiTestString = asciiTestString + asciiTestString;
41
42 var isoLatin1TestString= longIsoLatin1Text;
43//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
44//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
45//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
46//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString;
47//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString;
48
49 var utf8TestString = longUtf8Text;
50//utf8TestString = utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString;
51//utf8TestString = utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString;
52//utf8TestString = utf8TestString + utf8TestString;
53//utf8TestString = utf8TestString + utf8TestString;
54
55var times = {
56 'Clipperz': {},
57 'JSCrypto': {}
58};
59
60function appendResults (aDescription, aTimer) {
61 MochiKit.DOM.appendChildNodes(MochiKit.DOM.getElement('timerTBODY'),
62 MochiKit.DOM.TR(null,
63 MochiKit.DOM.TH({align:'left'}, aDescription),
64 MochiKit.DOM.TH(null, aTimer['ascii']['encrypt'] + ' - ' + aTimer['ascii']['decrypt'])//,
65 // MochiKit.DOM.TH(null, aTimer['isoLatin1']['encrypt']+ ' - ' + aTimer['isoLatin1']['decrypt']),
66 // MochiKit.DOM.TH(null, aTimer['utf8']['encrypt'] + ' - ' + aTimer['utf8']['decrypt'])
67 )
68 );
69
70}
71
72//=============================================================================
73
74function timeRegularFunction (aDescription, aString, anEncryptFunction, aDecryptFunction, aTimer, aKey) {
75 var start;
76 var end;
77 var encryptTime;
78 var decryptTime;
79 var ciphertext;
80 var plaintext;
81
82
83 start = new Date();
84 ciphertext = anEncryptFunction('trustno1', aString);
85 end = new Date();
86 encryptTime = end - start;
87
88 start = new Date();
89 plaintext = aDecryptFunction('trustno1', ciphertext);
90 end = new Date();
91 decryptTime = end - start;
92 aTimer[aKey] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
93 SimpleTest.is(aString, plaintext, aDescription);
94}
95/*
96function timeRegularFunction (anEncryptFunction, aDecryptFunction, aTimer) {
97 var start;
98 var end;
99 var encryptTime;
100 var decryptTime;
101 var ciphertext;
102 var plaintext;
103
104
105 start = new Date();
106 ciphertext = anEncryptFunction('trustno1', asciiTestString);
107 end = new Date();
108 encryptTime = end - start;
109
110 start = new Date();
111 plaintext = aDecryptFunction('trustno1', ciphertext);
112 end = new Date();
113 decryptTime = end - start;
114 aTimer['ascii'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
115 SimpleTest.is(asciiTestString, plaintext, "Encrypt/decrypt the ASCII text");
116
117
118 start = new Date();
119 ciphertext = anEncryptFunction('trustno1', isoLatin1TestString);
120 end = new Date();
121 encryptTime = end - start;
122
123 start = new Date();
124 plaintext = aDecryptFunction('trustno1', ciphertext);
125 end = new Date();
126 decryptTime = end - start;
127 aTimer['isoLatin1'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
128 SimpleTest.is(isoLatin1TestString, plaintext, "Encrypt/decrypt the ISO-Latin 1 text");
129
130
131 start = new Date();
132 ciphertext = anEncryptFunction('trustno1', utf8TestString);
133 end = new Date();
134 encryptTime = end - start;
135
136 start = new Date();
137 plaintext = aDecryptFunction('trustno1', ciphertext);
138 end = new Date();
139 decryptTime = end - start;
140 aTimer['utf8'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
141 SimpleTest.is(utf8TestString, plaintext, "Encrypt/decrypt the UTF-8 text");
142}
143*/
144function timeDeferredFunction (aDescription, aString, anEncryptFunction, aDecryptFunction, aTimer, aKey, someTestArgs) {
145 var start;
146 var end;
147
148 var deferredResult;
149
150 aTimer[aKey] = {};
151
152 deferredResult = new Clipperz.Async.Deferred("timeDeferredFunction", someTestArgs);
153 deferredResult.addCallback(function (aValue) { start = new Date(); return aValue});
154 deferredResult.addCallback(anEncryptFunction, 'trustno1', aString);
155 deferredResult.addCallback(function (aValue) {
156 end = new Date();
157 aTimer[aKey]['encrypt'] = end-start;
158 return aValue;
159 });
160 deferredResult.addCallback(function (aValue) { start = new Date(); return aValue});
161 deferredResult.addCallback(aDecryptFunction, 'trustno1');
162 deferredResult.addCallback(function (aValue) {
163 end = new Date();
164 aTimer[aKey]['decrypt'] = end-start;
165 return aValue;
166 });
167 deferredResult.addCallback(function (aValue) {
168 SimpleTest.is(aString, aValue, aDescription);
169 });
170
171 deferredResult.callback();
172
173 return deferredResult;
174}
175
176//=============================================================================
177
178function encryptUsingJSCrypto (aKey, aValue) {
179 var salt;
180 var key;
181 var cipher;
182 var iv;
183 var plaintext;
184 var ciphertext;
185 var tag;
186 var adata;
187
188 salt = [1,2,3,4,5,6,7,8];
189 key = generateKey(aKey, salt);
190
191 cipher = new aes(key, CCM);
192 iv = Random.random_words(4);
193
194 plaintext = aValue;
195 ciphertext = [];
196 tag = [];
197 adata = "";
198
199 cipher.encrypt(iv, plaintext, ciphertext, adata, tag);
200
201 return ciphertext;
202}
203
204//-----------------------------------------------------------------------------
205
206function decryptUsingJSCrypto (aKey, aValue) {
207 var salt;
208 var key;
209 var cipher;
210 var ciphertext;
211 var plaintext;
212 var tag;
213 var adata;
214
215 salt = [1,2,3,4,5,6,7,8];
216 key = generateKey(aKey, salt);
217 tag = [];
218 adata = "";
219
220 cipher = new aes(key, CCM);
221 ciphertext = aValue;
222 plaintext = cipher.decrypt(ciphertext, adata, tag);
223
224 return plaintext;
225}
226
227//=============================================================================
228
229function encryptUsingClipperz (aKey, aValue) {
230 var key;
231 var value;
232 var data;
233 var encryptedData;
234
235 key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
236 value = aValue;
237 data = new Clipperz.ByteArray(value);
238 encryptedData = Clipperz.Crypto.AES.encrypt(key, data);
239 return encryptedData.toBase64String();
240}
241
242//-----------------------------------------------------------------------------
243
244function decryptUsingClipperz (aKey, aValue) {
245 var key;
246 var value;
247 var decryptedData;
248
249 key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
250 value = new Clipperz.ByteArray().appendBase64String(aValue);
251
252 decryptedData = Clipperz.Crypto.AES.decrypt(key, value).asString();
253
254 return decryptedData;
255}
256
257//=============================================================================
258
259function encryptUsingClipperzAndJSON (aKey, aValue) {
260 var key;
261 var value;
262 var data;
263 var encryptedData;
264
265 key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
266 value = Clipperz.Base.serializeJSON(aValue);
267 data = new Clipperz.ByteArray(value);
268 encryptedData = Clipperz.Crypto.AES.encrypt(key, data);
269 return encryptedData.toBase64String();
270}
271
272//-----------------------------------------------------------------------------
273
274function decryptUsingClipperzAndJSON (aKey, aValue) {
275 var key;
276 var value;
277 var decryptedData;
278
279 key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
280 value = new Clipperz.ByteArray().appendBase64String(aValue);
281
282 decryptedData = Clipperz.Crypto.AES.decrypt(key, value).asString();
283
284 return Clipperz.Base.evalJSON(decryptedData);
285}
286
287//=============================================================================
288
289function deferredEncryptUsingClipperz (aKey, aValue) {
290 var deferredResult;
291 varkey;
292 var data;
293
294 key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
295 data = new Clipperz.ByteArray(aValue);
296
297 deferredResult = new Clipperz.Async.Deferred("Clipperz.deferredEncrypt", {trace:false});
298 deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, data);
299 deferredResult.addCallback(function(aResult) {
300 return aResult.toBase64String();
301 })
302 deferredResult.callback();
303
304 return deferredResult;
305}
306
307//-----------------------------------------------------------------------------
308
309function deferredDecryptUsingClipperz (aKey, aValue) {
310 var key, value;
311
312 key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
313 value = new Clipperz.ByteArray().appendBase64String(aValue);
314
315 deferredResult = new Clipperz.Async.Deferred("Clipperz.deferredDecrypt", {trace:false});
316 deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value);
317 deferredResult.addCallback(function(aResult) {
318 return aResult.asString();
319 });
320 deferredResult.callback();
321
322 return deferredResult;
323}
324
325//=============================================================================
326
327var tests = {
328
329 //-------------------------------------------------------------------------
330
331 'encryptMultipleStringsUsingClipperzFunctions': function (someTestArgs) {
332 // timeRegularFunction(encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['Regular']);
333 times['Clipperz']['NO JSON'] = {};
334
335 timeRegularFunction("Clipperz - NO JSON - Ascii", asciiTestString, encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'ascii');
336 timeRegularFunction("Clipperz - NO JSON - ISO Latin 1", isoLatin1TestString,encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'isoLatin1');
337 timeRegularFunction("Clipperz - NO JSON - UTF-8", utf8TestString, encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'utf8');
338
339 appendResults("Clipperz - NO JSON", times['Clipperz']['NO JSON']);
340 },
341
342 //-------------------------------------------------------------------------
343
344 'encryptMultipleStringsUsingClipperzAndJSONFunctions': function (someTestArgs) {
345 // timeRegularFunction(encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON']);
346 times['Clipperz']['JSON'] = {};
347
348 timeRegularFunction("Clipperz - JSON - Ascii", asciiTestString, encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'ascii');
349 timeRegularFunction("Clipperz - JSON - ISO Latin 1", isoLatin1TestString,encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'isoLatin1');
350 timeRegularFunction("Clipperz - JSON - UTF-8", utf8TestString, encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'utf8');
351
352 appendResults("Clipperz - JSON", times['Clipperz']['JSON']);
353 },
354
355 //-------------------------------------------------------------------------
356
357 'encryptMultipleStringsUsingClipperzDeferredFunctions': function (someTestArgs) {
358 times['Clipperz']['Deferred'] = {};
359 times['Clipperz']['Deferred [NO JSON]'] = {};
360
361 return Clipperz.Async.callbacks("encryptMultipleStringsUsingClipperzDeferredFunctions", [
362 MochiKit.Base.partial(timeDeferredFunction, "Deferred Ascii", asciiTestString, deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'ascii', someTestArgs),
363 // MochiKit.Base.partial(timeDeferredFunction, "Deferred IsoLatin1", isoLatin1TestString, deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'isoLatin1',someTestArgs),
364 // MochiKit.Base.partial(timeDeferredFunction, "Deferred UTF-8", utf8TestString, deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'utf8', someTestArgs),
365
366 MochiKit.Base.partial(appendResults, "Clipperz - deferred [NO JSON]", times['Clipperz']['Deferred [NO JSON]']),
367
368 MochiKit.Base.partial(timeDeferredFunction, "Deferred Ascii", asciiTestString, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredEncrypt, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredDecrypt, times['Clipperz']['Deferred'], 'ascii', someTestArgs),
369 // MochiKit.Base.partial(timeDeferredFunction, "Deferred IsoLatin1", isoLatin1TestString, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredEncrypt, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredDecrypt, times['Clipperz']['Deferred'], 'isoLatin1',someTestArgs),
370 // MochiKit.Base.partial(timeDeferredFunction, "Deferred UTF-8", utf8TestString, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredEncrypt, Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].deferredDecrypt, times['Clipperz']['Deferred'], 'utf8', someTestArgs),
371
372 MochiKit.Base.partial(appendResults, "Clipperz - PM", times['Clipperz']['Deferred'])
373 ], someTestArgs);
374 },
375
376 //-------------------------------------------------------------------------
377
378 'encryptMultipleStringsUsingJSCryptoFunctions': function (someTestArgs) {
379 timeRegularFunction("JSCrypto - Ascii", asciiTestString, encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'ascii');
380 timeRegularFunction("JSCrypto - ISO Latin 1", isoLatin1TestString,encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'isoLatin1');
381 timeRegularFunction("JSCrypto - UTF-8", utf8TestString, encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'utf8');
382
383 appendResults("JSCrypto", times['JSCrypto']);
384 },
385
386 //-------------------------------------------------------------------------
387 'syntaxFix': MochiKit.Base.noop
388};
389
390//#############################################################################
391
392SimpleTest.waitForExplicitFinish();
393Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
394Random.set_default_paranoia(0);
395
396//Random.addEventListener("seeded", MochiKit.Base.partial(SimpleTest.runDeferredTests, "Clipperz.Crypto.JSCrypto_vs_Clipperz", tests, {trace:false}));
397//Random.addEventListener("seeded", function () { console.log("SEEDED!")});
398
399
400MochiKit.DOM.appendChildNodes(MochiKit.DOM.currentDocument().body,
401 MochiKit.DOM.TABLE({border:'1', cellpadding:'4', cellspacing:'0'},
402 MochiKit.DOM.THEAD(),
403 MochiKit.DOM.TBODY({id:'timerTBODY'},
404 MochiKit.DOM.TR(null,
405 MochiKit.DOM.TH(null, "algorithm"),
406 MochiKit.DOM.TH(null, "ascii [" + asciiTestString.length + "]"),
407 MochiKit.DOM.TH(null, "ISO Latin 1 [" + isoLatin1TestString.length * 2 + "]"),
408 MochiKit.DOM.TH(null, "UTF 8 [" + utf8TestString.length * 3 + "]")
409 )
410 ),
411 MochiKit.DOM.TFOOT()
412 )//,
413 //MochiKit.DOM.H4(null, "AES chunkSize: " + Clipperz.Crypto.AES.DeferredExecution.chunkSize),
414 //MochiKit.DOM.H4(null, "AES pauseTime: " + Clipperz.Crypto.AES.DeferredExecution.pauseTime)
415);
416
417
418SimpleTest.runDeferredTests("Clipperz.Crypto.JSCrypto_vs_Clipperz", tests, {trace:false}); \ No newline at end of file
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/PRNG.html b/frontend/gamma/tests/tests/Clipperz/Crypto/PRNG.html
new file mode 100644
index 0000000..7ffd691
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/PRNG.html
@@ -0,0 +1,117 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script> jslog_config_enabled = true; </script>
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/Clipperz/YUI/Utils.js'></script>
39 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
40 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
41 <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/DOM.js'></script>
44
45<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Statistics.js'></script>-->
46 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
47 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
48 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
49 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
50 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
51</head>
52<body>
53<pre id="test">
54<script type="text/javascript">
55test_PRNG = function() {
56 varrand1, rand2;
57 var i,c;
58
59 c = 10;
60 for (i=0; i<c; i++) {
61 // jslog.debug(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString());
62 }
63
64 rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
65 is(rand1.byteAtIndex(0) <= 255, true, "getRandomByte returns always a single byte");
66
67 rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
68 is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
69
70
71 rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
72 rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
73 is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
74 is(rand1.split(0,1).equals(rand2.split(0,1)), false, "getRandomByte should almost always return two different values when called into sequence");
75 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 1", "Value for random test");
76 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 2", "Value for random test");
77 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 3", "Value for random test");
78 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 4", "Value for random test");
79 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 5", "Value for random test");
80 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 6", "Value for random test");
81 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 7", "Value for random test");
82 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 8", "Value for random test");
83 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 9", "Value for random test");
84 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 10", "Value for random test");
85 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 11", "Value for random test");
86 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 12", "Value for random test");
87 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 13", "Value for random test");
88 //is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 14", "Value for random test");
89//jslog.debug(rand1.toHexString());
90//jslog.debug(rand2.toHexString());
91
92 SimpleTest.finish();
93}
94
95try {
96 MochiKit.Signal.connect(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'readyToGenerateRandomBytes', test_PRNG);
97 Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
98 SimpleTest.waitForExplicitFinish();
99} catch (err) {
100
101 var s = "test suite failure!\n";
102 var o = {};
103 var k = null;
104 for (k in err) {
105 // ensure unique keys?!
106 if (!o[k]) {
107 s += k + ": " + err[k] + "\n";
108 o[k] = err[k];
109 }
110 }
111 ok ( false, s );
112}
113
114</script>
115</pre>
116</body>
117</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/RSA.html b/frontend/gamma/tests/tests/Clipperz/Crypto/RSA.html
new file mode 100644
index 0000000..468a987
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/RSA.html
@@ -0,0 +1,90 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/DOM.js'></script>
38
39 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
40 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
41 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/RSA.js'></script>
42
43</head>
44<body>
45<pre id="test">
46<script type="text/javascript">
47try {
48 varrsaPublicKey;
49 varrandomValue;
50 varpublicEncryptedValue;
51 var privateEncryptedValue;
52
53 varstartTime;
54 varendTime;
55
56
57startTime=new Date();
58 rsaPublicKey = Clipperz.Crypto.RSA.generatePublicKey(512);
59
60endTime=new Date();
61is(true, true, 'Time to generate the RSA public key (size 512 bit): '+(endTime.getTime()-startTime.getTime())/1000.0);
62
63 randomValue = Clipperz.Crypto.Base.generateRandomSeed();
64 publicEncryptedValue = Clipperz.Crypto.RSA.encryptUsingPublicKey(rsaPublicKey, randomValue);
65 privateEncryptedValue = Clipperz.Crypto.RSA.encryptUsingPrivateKey(rsaPublicKey, randomValue);
66
67 is(publicEncryptedValue == privateEncryptedValue, false);
68 is(Clipperz.Crypto.RSA.decryptUsingPrivateKey(rsaPublicKey, publicEncryptedValue), randomValue);
69 is(Clipperz.Crypto.RSA.decryptUsingPublicKey(rsaPublicKey, privateEncryptedValue), randomValue);
70
71 //-------------------------------------------------------------------------
72} catch (err) {
73
74 var s = "test suite failure!\n";
75 var o = {};
76 var k = null;
77 for (k in err) {
78 // ensure unique keys?!
79 if (!o[k]) {
80 s += k + ": " + err[k] + "\n";
81 o[k] = err[k];
82 }
83 }
84 ok ( false, s );
85}
86
87</script>
88</pre>
89</body>
90</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/SHA.html b/frontend/gamma/tests/tests/Clipperz/Crypto/SHA.html
new file mode 100644
index 0000000..1c88213
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/SHA.html
@@ -0,0 +1,175 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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.SHA - TEST</title>
32
33 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
34 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
35 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
36
37 <script type='text/javascript' src='../../../js/JSON/json2.js'></script>
38
39 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
40 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
41 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
44 <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script>
45
46 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
47
48
49 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script>
50
51</head>
52<body>
53<pre id="test">
54<script type="text/javascript" src="SHA.test.js"></script>
55</pre>
56</body>
57</html>
58
59
60
61<!-- html>
62<head>
63 <script>
64 jslog_config_enabled = true;
65 clipperz_profiling_enabled = true;
66 </script>
67
68 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
69 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
70 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
71 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
72
73 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
74 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
75 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
76 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
77
78 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
79</head>
80<body>
81<pre id="test">
82<script type="text/javascript">
83
84try {
85 varbyteArray;
86 varhash;
87 var longText;
88 var startTime, endTime;
89
90 longText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nunc sapien, condimentum vitae, varius vel, pharetra in, augue. Mauris quam magna, pretium sit amet, accumsan id, volutpat lobortis, nibh. Fusce sagittis. Aenean justo. Curabitur euismod pede. Morbi at ante. Proin nisl leo, ultrices sed, facilisis et, nonummy sit amet, lorem. Praesent mauris tellus, pulvinar sed, nonummy vitae, rhoncus non, nunc. Proin placerat malesuada nisl. Nunc id enim. Maecenas commodo enim ac nibh. Sed condimentum, urna sit amet euismod gravida, mi urna varius odio, luctus pretium lectus justo nec felis. Ut in augue et est malesuada rhoncus. Sed vel orci. Mauris suscipit. Praesent cursus velit non turpis. Donec tristique dolor ac est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla est sapien, vulputate eget, bibendum id, pharetra nec, mauris. Aliquam faucibus tincidunt dui. Proin iaculis. Maecenas sagittis. Integer et augue. Donec vitae urna in orci aliquet commodo. Vestibulum lorem sem, suscipit ac, placerat nec, mollis in, felis. Donec laoreet odio a mauris. Integer rutrum, sapien id varius molestie, mauris odio egestas orci, non bibendum sem felis in metus. Phasellus consectetuer lectus adipiscing mauris. Ut magna tellus, euismod ac, suscipit tincidunt, ullamcorper adipiscing, massa. Etiam orci. Phasellus a urna. Cras neque quam, laoreet at, tempus eget, euismod nec, nibh. Etiam hendrerit. Aenean vel lorem. Ut ligula lacus, congue eu, lobortis sit amet, venenatis in, magna. Nullam cursus felis quis est. Sed sem est, condimentum eu, vestibulum a, mattis vel, diam. Curabitur tincidunt pede quis pede. Sed neque diam, convallis vel, luctus at, porta id, nisl. Suspendisse potenti. Sed volutpat lobortis orci. Praesent mi. In interdum. Suspendisse suscipit ipsum eget dolor. Curabitur et tellus sed velit hendrerit varius. Cras sit amet est. Donec arcu nulla, vehicula et, pretium in, placerat id, felis. Integer mollis auctor lectus. Integer ultrices elementum sapien. Nam et erat. Nam pulvinar porta tortor. Nam at risus. Quisque nulla. Integer vestibulum, lacus id bibendum laoreet, ligula mi pharetra lorem, sit amet pharetra felis mauris quis justo. Aliquam ultricies. Duis a pede eget lorem dapibus rhoncus. Aenean eu elit non libero consectetuer viverra. Maecenas velit mi, eleifend vel, malesuada vel, condimentum quis, odio. Mauris tempus augue sed turpis. Pellentesque condimentum, lacus vitae pellentesque ultricies, risus tellus posuere nisi, et dictum turpis pede nec elit. Sed eu lectus eu justo sagittis euismod. Vestibulum lobortis, urna id mollis rhoncus, orci quam euismod ligula, at malesuada lacus magna vitae massa. Phasellus mattis fermentum velit. Nulla vulputate consequat enim. Maecenas quis neque. Curabitur sagittis facilisis neque. In elementum, eros non porttitor rhoncus, libero turpis sodales odio, vitae porta tellus purus et ante. Nullam molestie sollicitudin metus. Donec a elit. Morbi ut lacus. Donec at arcu. Quisque velit diam, interdum a, lacinia at, varius et, odio. Cras neque magna, ornare id, sollicitudin id, consequat a, est. Phasellus vestibulum est at leo. Nam facilisis, nulla dapibus condimentum pellentesque, est magna viverra ligula, at sollicitudin urna augue ut sapien. Fusce justo.";
91
92 //-------------------------------------------------------------------------
93 //
94 //Test of SHA-256 algorithm
95 //
96 //-------------------------------------------------------------------------
97
98 byteArray = new Clipperz.ByteArray();
99 hash = Clipperz.Crypto.SHA.sha256(byteArray);
100 is(hash.toHexString(), "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "sha256('')");
101
102 byteArray = new Clipperz.ByteArray("0xbd");
103 hash = Clipperz.Crypto.SHA.sha256(byteArray);
104 is(hash.toHexString(), "0x68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b", "sha256('0xbd')");
105
106 byteArray = new Clipperz.ByteArray("0x5fd4");
107 hash = Clipperz.Crypto.SHA.sha256(byteArray);
108 is(hash.toHexString(), "0x7c4fbf484498d21b487b9d61de8914b2eadaf2698712936d47c3ada2558f6788", "sha256('0x5fd4')");
109
110 byteArray = new Clipperz.ByteArray("0xc98c8e55");
111 hash = Clipperz.Crypto.SHA.sha256(byteArray);
112 is(hash.toHexString(), "0x7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504", "sha256('0xc98c8e55')");
113
114 byteArray = new Clipperz.ByteArray("0x0df1cd526b5a4edd");
115 hash = Clipperz.Crypto.SHA.sha256(byteArray);
116 is(hash.toHexString(), "0x47f527210d6e8f940b5082fec01b7305908fa2b49ea3ae597c19a3986097153c", "sha256('0x0df1cd526b5a4edd')");
117
118 byteArray = new Clipperz.ByteArray("0xfdf4700984ee11b70af1880d0e0fefd4");
119 hash = Clipperz.Crypto.SHA.sha256(byteArray);
120 is(hash.toHexString(),
121 "0xb01ae16eed3b4a770f127b98469ba26fe3d8e9f59d8a2983214afe6cff0e6b6c",
122 "sha256('0xfdf4700984ee11b70af1880d0e0fefd4')");
123
124 byteArray = new Clipperz.ByteArray("0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb");
125 hash = Clipperz.Crypto.SHA.sha256(byteArray);
126 is(hash.toHexString(),
127 "0x56059e8cb3c2978b198208bf5ca1e1ea5659b737a506324b7cec75b5ebaf057d",
128 "sha256('0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb')");
129
130 byteArray = new Clipperz.ByteArray("0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a");
131 hash = Clipperz.Crypto.SHA.sha256(byteArray);
132 is(hash.toHexString(),
133 "0xc117b9dce689c399ec99008788cd5d24d8396fab7d96315c4f3fe6d56da63bb3",
134 "sha256('0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a')");
135
136 byteArray = new Clipperz.ByteArray("0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad");
137 hash = Clipperz.Crypto.SHA.sha256(byteArray);
138 is(hash.toHexString(),
139 "0x105a60865830ac3a371d3843324d4bb5fa8ec0e02ddaa389ad8da4f10215c454",
140 "sha256('0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad')");
141
142
143 byteArray = new Clipperz.ByteArray(longText);
144startTime = new Date();
145//console.profile("SHA256");
146 hash = Clipperz.Crypto.SHA.sha256(byteArray);
147//console.profileEnd("SHA256");
148endTime = new Date();
149 is(hash.toHexString(),
150 "0xf6fac13c06784e0fbc61a3d25c41c9984840a8b617a2beb57cf6fa3e5e4a8949",
151 "sha256(longText)");
152 is((endTime - startTime) < 500, true, "Long text hash performance (" + (endTime - startTime) + ")");
153 MochiKit.Logging.logDebug("elapsed time: " + (endTime - startTime));
154
155//#############################################################################
156
157} catch (err) {
158
159 var s = "test suite failure!\n";
160 var o = {};
161 var k = null;
162 for (k in err) {
163 // ensure unique keys?!
164 if (!o[k]) {
165 s += k + ": " + err[k] + "\n";
166 o[k] = err[k];
167 }
168 }
169 ok ( false, s );
170}
171
172</script>
173</pre>
174</body>
175</html -->
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/SHA.test.js b/frontend/gamma/tests/tests/Clipperz/Crypto/SHA.test.js
new file mode 100644
index 0000000..c9f1f3b
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/SHA.test.js
@@ -0,0 +1,84 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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
29var testSHA = function (aValue, anExpectedResult) {
30 var byteArrayValue;
31
32 byteArrayValue = new Clipperz.ByteArray(aValue);
33 hash = Clipperz.Crypto.SHA.sha256(byteArrayValue);
34 is(hash.toHexString(), anExpectedResult, "sha256(' " + byteArrayValue.toHexString() + "')");
35
36}
37
38
39var tests = {
40
41 'basic_tests': function (someTestArgs) {
42 testSHA('', '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
43 testSHA('0xbd', '0x68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b');
44 testSHA('0x5fd4', '0x7c4fbf484498d21b487b9d61de8914b2eadaf2698712936d47c3ada2558f6788');
45 testSHA('0xc98c8e55', '0x7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504');
46 testSHA('0x0df1cd526b5a4edd', '0x47f527210d6e8f940b5082fec01b7305908fa2b49ea3ae597c19a3986097153c');
47 testSHA('0xfdf4700984ee11b70af1880d0e0fefd4', '0xb01ae16eed3b4a770f127b98469ba26fe3d8e9f59d8a2983214afe6cff0e6b6c');
48 testSHA('0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb', '0x56059e8cb3c2978b198208bf5ca1e1ea5659b737a506324b7cec75b5ebaf057d');
49 testSHA('0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a', '0xc117b9dce689c399ec99008788cd5d24d8396fab7d96315c4f3fe6d56da63bb3');
50 testSHA('0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad', '0x105a60865830ac3a371d3843324d4bb5fa8ec0e02ddaa389ad8da4f10215c454');
51
52 },
53
54 //-------------------------------------------------------------------------
55
56 'aldo_cortesi_tests': function (someTestArgs) {
57 testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','0xa3f01b6939256127582ac8ae9fb47a382a244680806a3f613a118851c1ca1d47');
58 testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','0xb35439a4ac6f0948b6d6f9e3c6af0f5f590ce20f1bde7090ef7970686ec6738a');
59 testSHA('0x79', '0xa1fce4363854ff888cff4b8e7875d600c2682390412a8cf79b37d0b11148b0fa');
60 testSHA('0x80', '0x76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71');
61 },
62
63 //-------------------------------------------------------------------------
64
65 'longTextPerformance_test': function (someTestArgs) {
66 var longText;
67 var startTime;
68 var endTime;
69
70 longText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nunc sapien, condimentum vitae, varius vel, pharetra in, augue. Mauris quam magna, pretium sit amet, accumsan id, volutpat lobortis, nibh. Fusce sagittis. Aenean justo. Curabitur euismod pede. Morbi at ante. Proin nisl leo, ultrices sed, facilisis et, nonummy sit amet, lorem. Praesent mauris tellus, pulvinar sed, nonummy vitae, rhoncus non, nunc. Proin placerat malesuada nisl. Nunc id enim. Maecenas commodo enim ac nibh. Sed condimentum, urna sit amet euismod gravida, mi urna varius odio, luctus pretium lectus justo nec felis. Ut in augue et est malesuada rhoncus. Sed vel orci. Mauris suscipit. Praesent cursus velit non turpis. Donec tristique dolor ac est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla est sapien, vulputate eget, bibendum id, pharetra nec, mauris. Aliquam faucibus tincidunt dui. Proin iaculis. Maecenas sagittis. Integer et augue. Donec vitae urna in orci aliquet commodo. Vestibulum lorem sem, suscipit ac, placerat nec, mollis in, felis. Donec laoreet odio a mauris. Integer rutrum, sapien id varius molestie, mauris odio egestas orci, non bibendum sem felis in metus. Phasellus consectetuer lectus adipiscing mauris. Ut magna tellus, euismod ac, suscipit tincidunt, ullamcorper adipiscing, massa. Etiam orci. Phasellus a urna. Cras neque quam, laoreet at, tempus eget, euismod nec, nibh. Etiam hendrerit. Aenean vel lorem. Ut ligula lacus, congue eu, lobortis sit amet, venenatis in, magna. Nullam cursus felis quis est. Sed sem est, condimentum eu, vestibulum a, mattis vel, diam. Curabitur tincidunt pede quis pede. Sed neque diam, convallis vel, luctus at, porta id, nisl. Suspendisse potenti. Sed volutpat lobortis orci. Praesent mi. In interdum. Suspendisse suscipit ipsum eget dolor. Curabitur et tellus sed velit hendrerit varius. Cras sit amet est. Donec arcu nulla, vehicula et, pretium in, placerat id, felis. Integer mollis auctor lectus. Integer ultrices elementum sapien. Nam et erat. Nam pulvinar porta tortor. Nam at risus. Quisque nulla. Integer vestibulum, lacus id bibendum laoreet, ligula mi pharetra lorem, sit amet pharetra felis mauris quis justo. Aliquam ultricies. Duis a pede eget lorem dapibus rhoncus. Aenean eu elit non libero consectetuer viverra. Maecenas velit mi, eleifend vel, malesuada vel, condimentum quis, odio. Mauris tempus augue sed turpis. Pellentesque condimentum, lacus vitae pellentesque ultricies, risus tellus posuere nisi, et dictum turpis pede nec elit. Sed eu lectus eu justo sagittis euismod. Vestibulum lobortis, urna id mollis rhoncus, orci quam euismod ligula, at malesuada lacus magna vitae massa. Phasellus mattis fermentum velit. Nulla vulputate consequat enim. Maecenas quis neque. Curabitur sagittis facilisis neque. In elementum, eros non porttitor rhoncus, libero turpis sodales odio, vitae porta tellus purus et ante. Nullam molestie sollicitudin metus. Donec a elit. Morbi ut lacus. Donec at arcu. Quisque velit diam, interdum a, lacinia at, varius et, odio. Cras neque magna, ornare id, sollicitudin id, consequat a, est. Phasellus vestibulum est at leo. Nam facilisis, nulla dapibus condimentum pellentesque, est magna viverra ligula, at sollicitudin urna augue ut sapien. Fusce justo.";
71 startTime = new Date();
72 testSHA(longText, '0xf6fac13c06784e0fbc61a3d25c41c9984840a8b617a2beb57cf6fa3e5e4a8949');
73 endTime = new Date();
74
75 is((endTime - startTime) < 100, true, "Long text hash performance (" + (endTime - startTime) + ")");
76 },
77
78 //-------------------------------------------------------------------------
79 'syntaxFix': MochiKit.Base.noop
80}
81
82//=============================================================================
83
84SimpleTest.runDeferredTests("Clipperz.Crypto.SHA", tests, {trace:false});
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/SRP.html b/frontend/gamma/tests/tests/Clipperz/Crypto/SRP.html
new file mode 100644
index 0000000..63278c4
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/SRP.html
@@ -0,0 +1,161 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
38 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
39 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
40
41 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
44 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
45 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
46 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SRP.js'></script>
47</head>
48<body>
49<pre id="test">
50<script type="text/javascript">
51hashString = function(aValue) {
52 return Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(aValue)).toHexString().substring(2)
53}
54try {
55 varusername;
56 varpassphrase;
57
58 var C;
59 var P;
60 var encryptedText_1;
61 var encryptedText_2;
62 varsalt;
63 varx;
64 var v;
65 var v1;
66
67 username = "giulio.cesare";
68 passphrase = "trustno1";
69
70 C = hashString(username);
71 is (C, "bde3c7b5fdcd9d6ce72782ca1ae912fc4397d668fcb3a73a04e5d47852670c4a", "C");
72
73 P = hashString(passphrase + username);
74 is (P, "d79f5c5a04e91e1c85fb64cb6ee9481cb52c181047f69da02cd6c3ce6d058a76", "P");
75
76 salt = "cf1fa93393ade60318b8276f1f39420098419445005a7dc9117975fe1f8d9988";
77
78 x = hashString(salt + P);
79 is(x, "21fe88a158e420aade86e00b5eb12a4c19bf15482fa34c542c90b1afdbd5b5fd", "x");
80
81 v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n());
82 is(v.asString(10), "33816467430011076413789931449607305355248467973000153409872503376381719918118", "v");
83 is(v.asString(16), "4ac37139dbf32ebabd2c43f91dd085066d3c457d059efd5902d32ed247fcb626", "v (base 16)");
84
85 //encryptedText_1 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
86 //encryptedText_2 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
87 //is (encryptedText_1 != encryptedText_2, true, "Two round of encryption (with random padding bits) should NOT produce the same result");
88
89 //-------------------------------------------------------------------------
90
91 username = "giulio.cesare.debug";
92 passphrase = "trustno1";
93
94 C = hashString(username);
95 is (C, "fa1af609123b97a10d676158ed538d4657a89ac33a102b22bd9a66712039e208", "C");
96
97 P = hashString(passphrase + username);
98 is (P, "e1bfba03dd626b12f29458a6ad63fb2c01b4765548504e1e2f6b1503c82e4253", "P");
99
100 salt = "cf1fa93393ade60318b8276f1f39420098419445005a7dc9117975fe1f8d9988";
101
102 x = hashString(salt + P);
103 is(x, "93d4af3cdcd2447a745d309826dff3161feed4b15f32db8e909ff032a2bc8fb8", "x");
104
105 v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n());
106 is(v.asString(10), "115049747015252903452664067168789229427785288458366249918596663144588656606556", "v");
107
108 //encryptedText_1 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
109 //encryptedText_2 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
110 //is (encryptedText_1 != encryptedText_2, true, "Two round of encryption (with random padding bits) should NOT produce the same result");
111
112 //-------------------------------------------------------------------------
113
114 var srpConnection;
115 var C, P, salt;
116
117 C = "da8602c2f847306f4eb9acdaad925277d1fad1408f173f128a078aea15e60b1e";
118 P = "77643559beca49dd21c1c31db10bb0a9009662cb504413dc3fa3b7303c7e02ba";
119 salt ="000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1";
120
121 srpConnection = new Clipperz.Crypto.SRP.Connection({C:C, P:P, hash:Clipperz.Crypto.SHA.sha_d256});
122 srpConnection._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10);
123 srpConnection.set_s(new Clipperz.Crypto.BigInt(salt, 16));
124 is (srpConnection.s().asString(16, 64), salt, "salt read/write is coherent");
125 srpConnection.set_B(new Clipperz.Crypto.BigInt("123541032067854367017620977654446651448957899464139861291542193929199957895435", 10));
126
127 is(srpConnection.serverSideCredentialsWithSalt(salt).v,
128 "c73169c8236d37bf9ef11a2349e3064b7dc6e883a58d64443ea9235677520030",
129 "server side credentials - v"
130 )
131 is(srpConnection.S(), "84134227508133659832466942692590826994401065200828529664948840490489960952050", "Server side 'S'");
132//MochiKit.Logging.logDebug("=== serverSideCredentials: " + MochiKit.Base.serializeJSON(srpConnection.serverSideCredentialsWithSalt(salt)));
133
134 srpConnection = new Clipperz.Crypto.SRP.Connection({C:C, P:P, hash:Clipperz.Crypto.SHA.sha_d256});
135 try {
136 srpConnection.set_B(new Clipperz.Crypto.BigInt("0", 10));
137 ok(false, "Setting B to 0 should raise an exception");
138 } catch(e) {
139 ok(true, "Setting B to 0 should raise an exception");
140 }
141 //-------------------------------------------------------------------------
142
143} catch (err) {
144
145 var s = "test suite failure!\n";
146 var o = {};
147 var k = null;
148 for (k in err) {
149 // ensure unique keys?!
150 if (!o[k]) {
151 s += k + ": " + err[k] + "\n";
152 o[k] = err[k];
153 }
154 }
155 ok ( false, s );
156}
157
158</script>
159</pre>
160</body>
161</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html b/frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html
new file mode 100644
index 0000000..63f7610
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/Usage.html
@@ -0,0 +1,122 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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.Usage - 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/Logging.js'></script>
44 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
45
46 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
47 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
48 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
49
50</head>
51<body>
52<pre id="test">
53<script type="text/javascript">
54Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
55
56MochiKit.Base.update(Clipperz, {
57 'PM': {
58 'Crypto': {
59 'passwordEntropy': function(aValue) {
60 var result;
61 varbitPerChar;
62
63 bitPerChar = 4;
64 if (/[a-z]/.test(aValue)) {
65 bitPerChar ++;
66 }
67 if (/[A-Z]/.test(aValue)) {
68 bitPerChar ++;
69 }
70 if (/[^a-zA-Z0-9]/.test(aValue)) {
71 bitPerChar ++;
72 }
73 //MochiKit.Logging.logDebug("--- bitPerChar: " + bitPerChar);
74
75 result = aValue.length * bitPerChar;
76
77 return result;
78 }
79 }
80 }
81})
82
83try {
84 var keyValue;
85 var keyEntropy;
86 varkey;
87 var plainText;
88 var cypherText;
89 var randomBytes;
90 var hashedValue;
91
92 key = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("This is my long and complex passphrase"));
93 keyEntropy = Clipperz.PM.Crypto.passwordEntropy(key);
94
95 cypherText = Clipperz.Crypto.AES.encrypt(key, new Clipperz.ByteArray("some text to encrypt"));
96 plainText = Clipperz.Crypto.AES.decrypt(key, cypherText).asString();
97 is(plainText, "some text to encrypt");
98
99 randomBytes = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(256/8);
100 hashedValue = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("text to hash"));
101
102//#############################################################################
103
104} catch (err) {
105
106 var s = "test suite failure!\n";
107 var o = {};
108 var k = null;
109 for (k in err) {
110 // ensure unique keys?!
111 if (!o[k]) {
112 s += k + ": " + err[k] + "\n";
113 o[k] = err[k];
114 }
115 }
116 ok ( false, s );
117}
118
119</script>
120</pre>
121</body>
122</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/index.html b/frontend/gamma/tests/tests/Clipperz/Crypto/index.html
new file mode 100644
index 0000000..67487ac
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/index.html
@@ -0,0 +1,58 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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.* - tests</title>
32
33 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
34 <script type="text/javascript" src="../../../SimpleTest/TestRunner.js"></script>
35</head>
36<body>
37<script>
38TestRunner.runTests(
39 'AES.html',
40 'AES.performance.html',
41 'Base.html',
42 'BigInt.html',
43
44 //'ECC.B283.deferred.html',
45 //'ECC.BinaryField.FiniteField.html',
46 //'ECC.BinaryField.FiniteField.B283.html',
47 //'ECC.BinaryField.Value.html',
48 //#'ECC.K283.deferred.html',
49
50 'PRNG.html',
51 //'RSA.html',
52 'SHA.html',
53 'SRP.html',
54 'Usage.html'
55);
56</script>
57</body>
58</html> \ No newline at end of file
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/jscrypto.js b/frontend/gamma/tests/tests/Clipperz/Crypto/jscrypto.js
new file mode 100644
index 0000000..e9db091
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/jscrypto.js
@@ -0,0 +1,1577 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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/* jsCrypto
30Core AES
31
32Emily Stark (estark@stanford.edu)
33Mike Hamburg (mhamburg@stanford.edu)
34Dan Boneh (dabo@cs.stanford.edu)
35
36Symmetric AES in Javascript using precomputed lookup tables for round transformations rather for speed improvements
37and code size reduction. Provides authenticated encryption in OCB and CCM modes.
38Parts of this code are based on the OpenSSL implementation of AES: http://www.openssl.org
39
40Public domain, 2009.
41
42*/
43
44
45// CCM mode is the default
46var CCM = 1, OCB = 2;
47
48/* aes object constructor. Takes as arguments:
49- 16-byte key, or an array of 4 32-bit words
50- Optionally specify a mode (aes.OCB or aes.CCM). Defaults to CCM
51- Optionally specify a MAC tag length for integrity. Defaults to 16 bytes
52*/
53function aes(key, mode, Tlen) {
54 // initialize objects for CCM and OCB modes
55 this._CCM = new cipherCCM(this);
56 this._OCB = new cipherOCB(this);
57
58 this._decryptScheduled = false;
59
60 if (mode) this._mode = mode;
61 else this._mode = OCB;
62
63 // AES round constants
64 this._RCON = [
65 [0x00, 0x00, 0x00, 0x00],
66 [0x01, 0x00, 0x00, 0x00],
67 [0x02, 0x00, 0x00, 0x00],
68 [0x04, 0x00, 0x00, 0x00],
69 [0x08, 0x00, 0x00, 0x00],
70 [0x10, 0x00, 0x00, 0x00],
71 [0x20, 0x00, 0x00, 0x00],
72 [0x40, 0x00, 0x00, 0x00],
73 [0x80, 0x00, 0x00, 0x00],
74 [0x1b, 0x00, 0x00, 0x00],
75 [0x36, 0x00, 0x00, 0x00]
76 ];
77
78 this._key_len = 16;
79 if (key.length == 4) {
80 this._key = [];
81 aes.wordsToBytes(key, this._key);
82 }
83 else
84 this._key = key;
85
86 if (Tlen) this._Tlen = Tlen;
87 else this._Tlen = 16; // tag length in bytes
88
89 this._nr = 10;
90
91 // initialize tables that will be precomputed
92 this._SBOX = [];
93 this._INV_SBOX = [];
94 this._T = new Array(4);
95 this._Tin = new Array(4);
96 for (var i=0; i < 4; i++) {
97 this._T[i] = [];
98 this._Tin[i] = [];
99 }
100
101 this._precompute();
102 this.scheduleEncrypt();
103
104 // initialize encryption and decryption buffers
105 this._ctBuffer = [];
106 this._ptBuffer = [];
107}
108
109
110//////////////////
111// KEY SCHEDULING
112//////////////////
113
114aes.prototype.scheduleEncrypt = function () {
115 this._decryptScheduled = false;
116
117 this._w = new Array(this._nr+1);
118 this._w[0] = new Array(4);
119 for (var i=0; i < 4; i++)
120 this._w[0][i] = this._key[i];
121 var temp = new Array(4);
122 for (var i=1; i < this._nr+1; i++) {
123 temp[0] = this._w[i-1][3];
124 this._w[i] = new Array(4);
125 temp[0] = (this._T[2][(temp[0]>>>16)&0xff] & 0xff000000) ^ (this._T[3][(temp[0]>>>8)&0xff]&0x00ff0000) ^ (this._T[0][(temp[0]&0xff)]&0x0000ff00) ^ (this._T[1][(temp[0]>>>24)]&0x000000ff) ^ (this._RCON[i][0]<<24);
126 this._w[i][0] = this._w[i-1][0] ^ temp[0];
127 for (var j=1; j < 4; j++) {
128 temp[j] = this._w[i][j-1];
129 this._w[i][j] = this._w[i-1][j] ^ temp[j];
130 }
131 }
132};
133
134aes.prototype.scheduleDecrypt = function() {
135
136 if (!this._w) this.scheduleEncrypt();
137 this._decryptScheduled = true;
138 var temp = [];
139 var j = this._w.length-1;
140 for (var i=0; i<j; i++) {
141 temp[0] = this._w[i][0];
142 temp[1] = this._w[i][1];
143 temp[2] = this._w[i][2];
144 temp[3] = this._w[i][3];
145 this._w[i][0] = this._w[j][0];
146 this._w[i][1] = this._w[j][1];
147 this._w[i][2] = this._w[j][2];
148 this._w[i][3] = this._w[j][3];
149 this._w[j][0] = temp[0];
150 this._w[j][1] = temp[1];
151 this._w[j][2] = temp[2];
152 this._w[j][3] = temp[3];
153 j--;
154 }
155
156 var td0 = this._Tin[0], td1 = this._Tin[1], td2 = this._Tin[2], td3 = this._Tin[3], te1 = this._T[1];
157 for (var i=1; i < this._w.length-1; i++) {
158 this._w[i][0] = td0[te1[(this._w[i][0] >>> 24) ] & 0xff] ^
159 td1[te1[(this._w[i][0] >>> 16) & 0xff] & 0xff] ^
160 td2[te1[(this._w[i][0] >>> 8) & 0xff] & 0xff] ^
161 td3[te1[(this._w[i][0] ) & 0xff] & 0xff];
162 this._w[i][1] = td0[te1[(this._w[i][1] >>> 24) ] & 0xff] ^
163 td1[te1[(this._w[i][1] >>> 16) & 0xff] & 0xff] ^
164 td2[te1[(this._w[i][1] >>> 8) & 0xff] & 0xff] ^
165 td3[te1[(this._w[i][1] ) & 0xff] & 0xff];
166 this._w[i][2] = td0[te1[(this._w[i][2] >>> 24) ] & 0xff] ^
167 td1[te1[(this._w[i][2] >>> 16) & 0xff] & 0xff] ^
168 td2[te1[(this._w[i][2] >>> 8) & 0xff] & 0xff] ^
169 td3[te1[(this._w[i][2] ) & 0xff] & 0xff];
170 this._w[i][3] = td0[te1[(this._w[i][3] >>> 24) ] & 0xff] ^
171 td1[te1[(this._w[i][3] >>> 16) & 0xff] & 0xff] ^
172 td2[te1[(this._w[i][3] >>> 8) & 0xff] & 0xff] ^
173 td3[te1[(this._w[i][3] ) & 0xff] & 0xff];
174 }
175};
176
177
178/////////////////////////
179// ENCRYPTION/DECRYPTION
180/////////////////////////
181
182
183/* Authenticated encryption on a multi-block message in OCB or CCM mode.
184iv should be an array of 32-bit words - either 4 words for OCB mode or 1, 2, or 3 words for CCM.
185Use a unique IV for every message encrypted.
186The plaintext argument will be encrypted and MACed; adata will be sent in plaintext but MACed.
187Plaintext and adata are strings.
188ciphertext is an array of bytes. tag is an array of 32-bit words.
189*/
190aes.prototype.encrypt = function(iv, plaintext, ciphertext, adata, tag) {
191 var plaintextBytes = [], adataBytes = [];
192 aes.asciiToBytes(plaintext, plaintextBytes);
193 aes.asciiToBytes(adata, adataBytes);
194
195 this._iv = iv;
196 if (this._mode == CCM)
197 this._CCM.encrypt(plaintextBytes, ciphertext, adataBytes, tag);
198 else if (this._mode == OCB) {
199 this._OCB.encrypt(plaintextBytes, ciphertext, adataBytes, tag);
200 }
201
202 // prepend to the ciphertext the length of the iv (in bytes) and the iv
203 var ivbytes=[];
204 aes.wordsToBytes(iv, ivbytes);
205 var ct = [iv.length*4].concat(ivbytes, ciphertext);
206 for (var i=0; i < ct.length; i++) ciphertext[i] = ct[i];
207
208 for (var i=0; i < ciphertext.length; i++)
209 this._ctBuffer[this._ctBuffer.length] = ciphertext[i];
210
211};
212
213/* Authenticated decryption on a multi-block ciphertext in OCB or CCM mode.
214ciphertext is an array of bytes. tag is an array of 32-bit words.
215plaintext and adata are strings.
216*/
217aes.prototype.decrypt = function(ciphertext, adata, tag) {
218 var ivlen = ciphertext[0];
219 var ivbytes = ciphertext.slice(1, ivlen+1);
220 var iv = [];
221 aes.bytesToWords(ivbytes, iv);
222 this._iv = iv;
223 var ct = ciphertext.slice(ivlen+1);
224
225 var valid = false;
226 var plaintextBytes = [], adataBytes = [];
227 aes.asciiToBytes(adata, adataBytes);
228 if (this._mode == CCM)
229 valid = this._CCM.decrypt(ct, plaintextBytes, adataBytes);
230 else if (this._mode == OCB)
231 valid = this._OCB.decrypt(ct, plaintextBytes, adataBytes, tag);
232 if (valid) {
233 var plaintext = aes.bytesToAscii(plaintextBytes);
234 for (var i=0; i < plaintext.length; i++)
235 this._ptBuffer[this._ptBuffer.length] = plaintext.charAt(i);
236 return plaintext;
237 }
238 return "";
239};
240
241// MACs (but doesn't encrypt) data using CMAC (in CCM mode) or PMAC (in OCB mode)
242aes.prototype.sign = function(data, tag) {
243 if (this._mode == CCM)
244 this._CCM.CMAC(data, "", tag, this._Tlen, false);
245 else if (this._mode == OCB) {
246 this._OCB.PMAC(data, tag);
247 }
248};
249
250// Verifies a CMAC or PMAC tag
251aes.prototype.verify = function(data, tag) {
252 var validTag = [];
253 if (this._mode == CCM)
254 this._CCM.CMAC(data, "", validTag, this._Tlen, false);
255 else if (this._mode == OCB) {
256 this._OCB.PMAC(data, validTag);
257 }
258 if (validTag.length != tag.length) return false;
259 for (var i=0; i < tag.length; i++) {
260 if (tag[i] != validTag[i]) return false;
261 }
262 return true;
263};
264
265/* Encrypts a single block message in AES. Takes the plaintext, an array in which to dump
266the ciphertext, and a boolean decrypt argument. If set to true, this function acts as
267a decryption function.
268block and ciphertext are both arrays of 4 32-bit words.
269*/
270aes.prototype.encryptBlock = function(block, ciphertext, decrypt) {
271 if (!decrypt && this._decryptScheduled) this.scheduleEncrypt();
272
273 // get key schedule
274 var w = this._w;
275 // load round transformation tables
276 var te0, te1, te2, te3;
277 if (decrypt) {
278 te0 = this._Tin[0];
279 te1 = this._Tin[1];
280 te2 = this._Tin[2];
281 te3 = this._Tin[3];
282 } else {
283 te0 = this._T[0];
284 te1 = this._T[1];
285 te2 = this._T[2];
286 te3 = this._T[3];
287 }
288
289 // perform rounds
290 var rk = w[0];
291 var s0 = block[0] ^ rk[0];
292 var s1 = block[1] ^ rk[1];
293 var s2 = block[2] ^ rk[2];
294 var s3 = block[3] ^ rk[3];
295 var t0,t1,t2,t3;
296 rk = w[1];
297 var order = [];
298 for (var round = 1; round < w.length-1; round++) {
299 order = [s1, s2, s3, s0];
300 if (decrypt) order = [s3, s0, s1, s2];
301 t0 = te0[(s0>>>24)] ^ te1[(order[0]>>>16) & 0xff]^ te2[(s2>>>8)&0xff] ^ te3[order[2]&0xff] ^ rk[0];
302 t1 = te0[(s1>>>24)] ^ te1[(order[1]>>>16) & 0xff]^ te2[(s3>>>8)&0xff] ^ te3[order[3]&0xff] ^ rk[1];
303 t2 = te0[(s2>>>24)] ^ te1[(order[2]>>>16) & 0xff]^ te2[(s0>>>8)&0xff] ^ te3[order[0]&0xff] ^ rk[2];
304 t3 = te0[(s3>>>24)] ^ te1[(order[3]>>>16) & 0xff]^ te2[(s1>>>8)&0xff] ^ te3[order[1]&0xff] ^ rk[3];
305 s0 = t0;
306 s1 = t1;
307 s2 = t2;
308 s3 = t3;
309 rk = w[round+1];
310 }
311 if (decrypt) {
312 s0 = ((this._INV_SBOX[(t0>>>24)])<<24) ^ ((this._INV_SBOX[(t3>>>16)&0xff])<<16) ^ ((this._INV_SBOX[(t2>>>8)&0xff])<<8) ^ (this._INV_SBOX[(t1)&0xff]) ^ rk[0];
313 s1 = ((this._INV_SBOX[(t1>>>24)])<<24) ^ ((this._INV_SBOX[(t0>>>16)&0xff])<<16) ^ ((this._INV_SBOX[(t3>>>8)&0xff])<<8) ^ (this._INV_SBOX[(t2)&0xff]) ^ rk[1]
314 s2 = ((this._INV_SBOX[(t2>>>24)])<<24) ^ ((this._INV_SBOX[(t1>>>16)&0xff])<<16) ^ ((this._INV_SBOX[(t0>>>8)&0xff])<<8) ^ (this._INV_SBOX[(t3)&0xff]) ^ rk[2];
315 s3 = (this._INV_SBOX[(t3>>>24)]<<24) ^ (this._INV_SBOX[(t2>>>16)&0xff]<<16) ^ (this._INV_SBOX[(t1>>>8)&0xff]<<8) ^ (this._INV_SBOX[(t0)&0xff]) ^ rk[3];
316 } else {
317 s0 = (te2[t0>>>24]&0xff000000) ^ (te3[(t1>>>16)&0xff]&0x00ff0000) ^ (te0[(t2>>>8)&0xff]&0x0000ff00) ^ (te1[(t3)&0xff]&0x000000ff) ^ rk[0];
318 s1 = (te2[t1>>>24]&0xff000000) ^ (te3[(t2>>>16)&0xff]&0x00ff0000) ^ (te0[(t3>>>8)&0xff]&0x0000ff00) ^ (te1[(t0)&0xff]&0x000000ff) ^ rk[1];
319 s2 = (te2[t2>>>24]&0xff000000) ^ (te3[(t3>>>16)&0xff]&0x00ff0000) ^ (te0[(t0>>>8)&0xff]&0x0000ff00) ^ (te1[(t1)&0xff]&0x000000ff) ^ rk[2];
320 s3 = (te2[t3>>>24]&0xff000000) ^ (te3[(t0>>>16)&0xff]&0x00ff0000) ^ (te0[(t1>>>8)&0xff]&0x0000ff00) ^ (te1[(t2)&0xff]&0x000000ff) ^ rk[3];
321 }
322 ciphertext[0] = s0;
323 ciphertext[1] = s1;
324 ciphertext[2] = s2;
325 ciphertext[3] = s3;
326};
327
328// As above, block and plaintext are arrays of 4 32-bit words.
329aes.prototype.decryptBlock = function(block, plaintext) {
330 if (!this._decryptScheduled) this.scheduleDecrypt();
331
332 this.encryptBlock(block, plaintext, true);
333};
334
335
336////////////////////
337// HELPER FUNCTIONS
338////////////////////
339
340aes._hex = function(n) {
341 var out = "",i,digits="0123456789ABCDEF";
342 for (i=0; i<8; i++) {
343 var digit = n&0xF;
344 out = digits.substring(digit,digit+1) + out;
345 n = n >>> 4;
346 }
347 return out;
348}
349
350aes._hexall = function(nn) {
351 var out = "",i;
352 for (i=0;i<nn.length;i++) {
353 if (i%4 == 0) out+= "<br/>\n";
354 else if (i) out += " ";
355 out += aes._hex(nn[i]);
356 }
357 return out;
358}
359
360aes.bytesToAscii = function(bytes) {
361 var ascii = "";
362 var len = bytes.length;
363 for (var i=0; i < len; i++) {
364 ascii = ascii + String.fromCharCode(bytes[i]);
365 }
366 return ascii;
367};
368
369aes.asciiToBytes = function(ascii, bytes) {
370 var len = ascii.length;
371 for (var i=0; i < len; i++)
372 bytes[i] = ascii.charCodeAt(i);
373};
374
375aes.wordsToBytes = function(words, bytes) {
376 var bitmask = 1;
377 for (var i=0; i < 7; i++) bitmask = (bitmask << 1) | 1;
378 for (var i=0; i < words.length; i++) {
379 var bstart = i*4;
380 for (var j=0; j < 4; j++) {
381 bytes[bstart+j] = (words[i] & (bitmask << (8*(3-j)))) >>> (8*(3-j));
382 }
383 }
384};
385
386aes.bytesToWords = function(bytes, words) {
387 var paddedBytes = bytes.slice();
388 while (paddedBytes.length % 4 != 0) paddedBytes.push(0);
389 var num_words = Math.floor(paddedBytes.length/4);
390 for (var j=0; j < num_words; j++)
391 words[j] = ((paddedBytes[(j<<2)+3]) | (paddedBytes[(j<<2)+2] << 8) | (paddedBytes[(j<<2)+1] << 16) | (paddedBytes[j<<2] << 24));
392};
393
394
395///////////////////////////////////////
396// KEY DERIVATION
397//////////////////////////////////////
398
399// password is a string, presumably a password entered by the user.
400// salt is eight random bytes associated with each user
401// This function returns an array of bytes of length 16
402function generateKey(password, salt) {
403 var pwBytes = [];
404 aes.asciiToBytes(password, pwBytes);
405 var pwWords = [], saltWords = [];
406 aes.bytesToWords(pwBytes, pwWords);
407 aes.bytesToWords(salt, saltWords);
408
409 var iterations = 1000;
410
411 var derivedKey = [];
412 var blockIndex = 1;
413
414 var xorHashes = function(h1, h2) {
415 var xor = [];
416 var i;
417 for (i=0; i < h1.length; i++) xor.push(h1[i] ^ h2[i]);
418 return xor;
419 };
420
421 while (derivedKey.length < 16) {
422 var hashBytes = pwWords.concat(saltWords);
423 hashBytes.push(blockIndex);
424 var T = SHA256.hash_words_big_endian(hashBytes);
425 var u = T;
426 for (var i=2; i < iterations; i++) {
427 var hash = SHA256.hash_words_big_endian(pwWords.concat(u));
428 u = xorHashes(T, hash);
429 }
430 var block = [];
431 aes.wordsToBytes(T, block);
432 for (var i=0; i < block.length; i++) derivedKey.push(block[i]);
433 }
434
435 if (derivedKey.length > 16) derivedKey.length = 16;
436 return derivedKey;
437}
438
439///////////////////////////////////////
440// ROUND TRANSFORMATION PRECOMPUTATION
441///////////////////////////////////////
442
443
444// Precomputation code by Mike Hamburg
445
446aes.prototype._precompute = function() {
447 var x,xi,sx,tx,tisx,i;
448 var d=[];
449
450 /* compute double table */
451 for (x=0;x<256;x++) {
452 d[x]= x&128 ? x<<1 ^ 0x11b : x<<1;
453 //d[x] = x<<1 ^ (x>>7)*0x11b; //but I think that's less clear.
454 }
455
456 /* Compute the round tables.
457 *
458 * We'll need access to x and x^-1, which we'll get by walking
459 * GF(2^8) as generated by (82,5).
460 */
461 for(x=xi=0;;) {
462 // compute sx := sbox(x)
463 sx = xi^ xi<<1 ^ xi<<2 ^ xi<<3 ^ xi<<4;
464 sx = sx>>8 ^ sx&0xFF ^ 0x63;
465
466 var dsx = d[sx], x2=d[x],x4=d[x2],x8=d[x4];
467
468 // te(x) = rotations of (2,1,1,3) * sx
469 tx = dsx<<24 ^ sx<<16 ^ sx<<8 ^ sx^dsx;
470
471 // similarly, td(sx) = (E,9,D,B) * x
472 tisx = (x8^x4^x2) <<24 ^
473 (x8^x ) <<16 ^
474 (x8^x4^x ) << 8 ^
475 (x8^x2^x );
476
477 // This can be done by multiplication instead but I think that's less clear
478 // tisx = x8*0x1010101 ^ x4*0x1000100 ^ x2*0x1000001 ^ x*0x10101;
479 // tx = dsx*0x1000001^sx*0x10101;
480
481 // rotate and load
482 for (i=0;i<4;i++) {
483 this._T[i][x] = tx;
484 this._Tin[i][sx] = tisx;
485 tx = tx<<24 | tx>>>8;
486 tisx = tisx<<24 | tisx>>>8;
487 }
488
489 // te[4] is the sbox; td[4] is its inverse
490 this._SBOX[ x] = sx;
491 this._INV_SBOX[sx] = x;
492
493
494 // wonky iteration goes through 0
495 if (x==5) {
496 break;
497 } else if (x) {
498 x = x2^d[d[d[x8^x2]]]; // x *= 82 = 0b1010010
499 xi ^= d[d[xi]]; // xi *= 5 = 0b101
500 } else {
501 x=xi=1;
502 }
503 }
504
505 // We computed the arrays out of order. On Firefox, this matters.
506 // Compact them.
507 for (i=0; i<4; i++) {
508 this._T[i] = this._T[i].slice(0);
509 this._Tin[i] = this._Tin[i].slice(0);
510 }
511 this._SBOX = this._SBOX.slice(0);
512 this._INV_SBOX = this._INV_SBOX.slice(0);
513
514
515};
516
517
518
519
520
521/* jsCrypto
522CCM mode
523
524Emily Stark (estark@stanford.edu)
525Mike Hamburg (mhamburg@stanford.edu)
526Dan Boneh (dabo@cs.stanford.edu)
527
528CCM mode for authenticated encryption of multiple 16-byte blocks. Uses AES as core cipher.
529
530Public domain, 2009.
531
532*/
533
534// Constructor takes an aes object as its core cipher
535function cipherCCM(cipher) {
536 this._cipher = cipher;
537}
538
539/* Formats plaintext and adata for MACing and encryption.
540adata and plaintext are arrays of bytes, B will be an array of arrays of 16 bytes
541Tlen specifies the number of bytes in the tag.
542Formatted according to the CCM specification.
543 */
544cipherCCM.prototype._formatInput = function(adata, plaintext, Tlen, B) {
545 // compute B[0]
546 var flags, nbytes=[];
547 aes.wordsToBytes(this._cipher._iv, nbytes);
548 if (adata) flags = 0x01<<6;
549 else flags = 0x00<<6;
550 flags = flags | (((Tlen-2)/2)<<3); // (t-2)/2
551 var q = 15-this._cipher._iv.length*4;
552 flags = flags | (q-1);
553 B[0] = new Array(16);
554 B[0][0] = flags;
555 for (var i=1; i <= 15-q; i++) B[0][i] = nbytes[i-1];
556 var Q = plaintext.length;
557
558 // make some bitmasks
559 var bitmask = 1;
560 for (var i=0; i < 7; i++) bitmask = (bitmask<<1) | 1;
561 for (var i=15; i > 15-q; i--) {
562 B[0][i] = Q & bitmask;
563 Q = Q>>>8;
564 }
565
566 // compute the blocks which identify adata
567 if (adata) {
568 var a = adata.length, Bind=1, BIind = 0, aind=0;
569 B[1] = new Array(16);
570 if (a < (2<<16 - 2<<8)) {
571 B[1][0] = a>>>8;
572 B[1][1] = a & bitmask;
573 BIind = 2;
574 } else if (a < (2<<32)) {
575 B[1][0] = 0xff;
576 B[1][1] = 0xfe;
577 for (var i=5; i >= 0; i--) {
578 B[1][2+i] = a & bitmask;
579 a = a>>>8;
580 }
581 BIind=8;
582 } else {
583 B[1][0] = 0xff;
584 B[1][0] = 0xff;
585 for (i=9; i >= 0; i--) {
586 B[1][2+i] = a & bitmask;
587 a = a >>> 8;
588 }
589 BIind = 12;
590 }
591 }
592
593 while (aind < adata.length) {
594 B[Bind][BIind] = adata[aind];
595 aind++;
596 if (BIind == 15) {
597 Bind++;
598 BIind = 0;
599 if (aind != adata.length) B[Bind] = new Array(16);
600 } else BIind++;
601 }
602 if (BIind != 0) {
603 while (BIind <= 15) {
604 B[Bind][BIind] = 0x00;
605 BIind++;
606 }
607 }
608
609 Bind++;
610 BIind=0;
611 B[Bind] = new Array(16);
612
613 // compute the payload blocks
614 var pind = 0;
615 while (pind < plaintext.length) {
616 B[Bind][BIind] = plaintext[pind];
617 pind++;
618 if (BIind == 15) {
619 Bind++;
620 BIind = 0;
621 if (pind != plaintext.length) B[Bind] = new Array(16);
622 } else BIind++;
623 }
624 if (BIind != 0) {
625 while (BIind <= 15) {
626 B[Bind][BIind] = 0x00;
627 BIind++;
628 }
629 }
630
631};
632
633/* Generate the blocks that will be used as counters.
634ctr will be an array of m+1 arrays of 16 bytes. */
635cipherCCM.prototype._generateCtrBlocks = function(m, ctr) {
636 var nbytes = [];
637 aes.wordsToBytes(this._cipher._iv, nbytes);
638 var flags = 15 - (this._cipher._iv.length*4) - 1;
639 var bitmask = 1;
640 for (var i=0; i < 7; i++) bitmask = (bitmask<<1) | 1;
641 for (var i=0; i <= m; i++) {
642 ctr[i] = new Array(16);
643 ctr[i][0] = flags;
644 for (var j=0; j < nbytes.length; j++) {
645 ctr[i][j+1] = nbytes[j];
646 }
647 for (var j=15; j > nbytes.length; j--) {
648 ctr[i][j] = (i>>>(8*(15-j))) & bitmask;
649 }
650 }
651
652};
653
654
655/* CBC-MAC adata and plaintext, and store the tag in tag.
656adata and plaintext are arrays of bytes
657tag will be an array of Tlen/4 32-bit words
658Tlen is an integer divisible by 4 that specifies the number of bytes in the tag.
659*/
660cipherCCM.prototype.CBCMAC = function(adata, plaintext, tag, Tlen, formatInput) {
661 var B = [];
662 if (formatInput)
663 this._formatInput(adata,plaintext,Tlen,B);
664 else {
665 var Sind = 0, SIind = 0, aind = 0, alen = adata.length;
666 B[0] = [];
667 while (aind < alen) {
668 B[Sind][SIind] = adata[aind];
669 SIind++;
670 if (SIind == 16) {
671 SIind = 0;
672 Sind++;
673 if (aind != alen-1) B[Sind] = [];
674 }
675 aind++;
676 }
677 }
678 var words = [];
679 var Yprev = [], Y = [];
680 aes.bytesToWords(B[0],words);
681 this._cipher.encryptBlock(words, Y);
682 var r = B.length, t = new Array(4);
683
684 for (var i=1; i < r; i++) {
685 for (var j=0; j < 4; j++) {
686 var bstart = j*4;
687 t[j] = Y[j] ^ ((B[i][bstart++]<<24) | (B[i][bstart++]<<16) | (B[i][bstart++]<<8) | (B[i][bstart++]));
688 Yprev[j] = Y[j];
689 }
690 this._cipher.encryptBlock(t, Y);
691 }
692 for (var i=0; i < Tlen/4; i++)
693 tag[i] = Y[i];
694};
695
696
697/* Provides authenticated encryption using CBCMAC and CTR-mode encryption on plaintext.
698adata is MACed but not encrypted.
699plaintext, adata, and tag are arrays of bytes
700Tlen is the number of bytes in the tag
701ciphertext will be an array of bytes. */
702cipherCCM.prototype.encrypt = function(plaintext, ciphertext, adata, tag) {
703 var Tlen = this._cipher._Tlen;
704 this.CBCMAC(adata, plaintext, tag, Tlen, true);
705 var ctr = [], m = Math.ceil(plaintext.length/16);
706 this._generateCtrBlocks(m, ctr);
707 var cblocks = [], S=[], t = new Array(4);
708 for (var i=0; i <= m; i++) {
709 S[i] = new Array(16);
710 aes.bytesToWords(ctr[i], cblocks);
711 this._cipher.encryptBlock(cblocks, t);
712 aes.wordsToBytes(t, S[i]);
713 }
714 var Sind = 1, SIind = 0;
715 for (var i=0; i < plaintext.length; i++) {
716 ciphertext[i] = plaintext[i] ^ S[Sind][SIind];
717 SIind++;
718 if (SIind == 16) {
719 Sind++;
720 SIind = 0;
721 }
722 }
723 var tbytes = [];
724 aes.wordsToBytes(tag, tbytes);
725 var cstart = plaintext.length;
726 for (var i=0; i < Tlen; i++)
727 ciphertext[cstart+i] = tbytes[i] ^ S[0][i];
728};
729
730
731/* Decrypt and verify the MAC on ciphertext and adata. The integrity of adata is verified, but isn't decrypted.
732ciphertext, adata are arrays of bytes
733plaintext will be an array of bytes
734Returns true if tag is valid, false otherwise.
735*/
736cipherCCM.prototype.decrypt = function(ciphertext, plaintext, adata) {
737 var Tlen = this._cipher._Tlen;
738 if (ciphertext.length <= Tlen) return false;
739 var ctr = [], tag = new Array(Tlen), m = Math.ceil(ciphertext.length/16);
740 this._generateCtrBlocks(m, ctr);
741 var S = [], t = new Array(4), cblocks=[];
742
743 for (var i=0; i <= m; i++) {
744 S[i] = new Array(16);
745 aes.bytesToWords(ctr[i], cblocks);
746 this._cipher.encryptBlock(cblocks, t);
747 aes.wordsToBytes(t, S[i]);
748 }
749
750 var Sind = 1, SIind = 0;
751 for (var i=0; i < (ciphertext.length-Tlen); i++) {
752 plaintext[i] = ciphertext[i] ^ S[Sind][SIind];
753 SIind++;
754 if (SIind == 16) {
755 SIind = 0;
756 Sind++;
757 }
758 }
759
760 for (var i=0; i < Tlen; i++)
761 tag[i] = ciphertext[ciphertext.length-Tlen+i] ^ S[0][i];
762
763 // verify integrity
764 var validTag = [], vtbytes = [];
765 this.CBCMAC(adata, plaintext, validTag, Tlen, true);
766 aes.wordsToBytes(validTag, vtbytes);
767 for (var i=0; i < Tlen; i++) {
768 if (vtbytes[i] != tag[i])
769 return false;
770 }
771 return true;
772
773};
774
775// Generate subkeys according to the CCM specification. */
776cipherCCM.prototype._generateSubkeys = function(k1,k2) {
777 var t = [0x00000000,0x00000000,0x00000000,0x00000000], t2 = new Array(4);
778 this._cipher.encryptBlock(t, t2);
779 for (var i=0; i < 3; i++)
780 k1[i] = t2[i]<<1 | t2[i+1]>>>31;
781 k1[3] = t2[3]<<1;
782 if (t2[0]>>>31 != 0)
783 k1[3] = k1[3] ^ 135;
784 for (var i=0; i < 3; i++)
785 k2[i] = k1[i]<<1 | k1[i+1]>>>31;
786 k2[3] = k1[3]<<1;
787 if (k1[0]>>>31 != 0)
788 k2[3] = k2[3] ^ 135;
789};
790
791
792/* CMAC used for integrity only (no encryption). */
793cipherCCM.prototype.CMAC = function(adata, plaintext, tag, Tlen, formatInput) {
794 var B = [], t = new Array(4); // will be an array of arrays of 16 bytes
795 if (formatInput)
796 this._formatInput(adata,plaintext,Tlen,B);
797 else {
798 var Sind = 0, SIind = 0, aind = 0, alen = adata.length;
799 B[0] = [];
800 while (aind < alen) {
801 B[Sind][SIind] = adata[aind];
802 SIind++;
803 if (SIind == 16) {
804 SIind = 0;
805 Sind++;
806 if (aind != alen-1) B[Sind] = [];
807 }
808 aind++;
809 }
810 }
811 var k1 = new Array(4), k2 = new Array(4);
812 this._generateSubkeys(k1,k2);
813 var last = B.length-1, kbytes = [];
814 if (alen % 16 == 0) {
815 aes.wordsToBytes(k1, kbytes);
816 } else {
817 aes.wordsToBytes(k2, kbytes);
818 B[last][B[last].length] = 1<<7;
819 while (B[last].length % 16 != 0)
820 B[last][B[last].length] = 0x00;
821 }
822 for (var i=0; i < 16; i++) B[last][i] = B[last][i] ^ kbytes[i];
823 var C = [0x00000000,0x00000000,0x00000000,0x00000000], Cprev = new Array(4), words = new Array(4);
824 for (var i=0; i < B.length; i++) {
825 aes.bytesToWords(B[i], words);
826 for (var j=0; j < 4; j++) {
827 Cprev[j] = C[j];
828 t[j] = C[j] ^ words[j];
829 }
830 this._cipher.encryptBlock(t, C);
831 }
832 var cbytes=[];
833 aes.wordsToBytes(C, cbytes);
834 for (var i=0; i < Tlen; i++)
835 tag[i] = cbytes[i];
836
837};
838
839
840
841/* jsCrypto
842OCB mode
843
844Emily Stark (estark@stanford.edu)
845Mike Hamburg (mhamburg@stanford.edu)
846Dan Boneh (dabo@cs.stanford.edu)
847
848OCB mode for authenticated encryption of multiple 16-byte blocks. Uses AES as core cipher.
849
850Public domain, 2009.
851*/
852
853/* Constructor takes an aes object as the core cipher. */
854function cipherOCB(cipher) {
855 this._cipher = cipher;
856}
857
858
859/* Provides integrity only, no encryption.
860header is an array of bytes, tag will be an array of 4 32-bit words */
861cipherOCB.prototype.PMAC = function(header, tag) {
862 var carry, t = new Array(4), t2 = new Array(4), Checksum = [0x00000000,0x00000000,0x00000000,0x00000000];
863 var Offset = new Array(4);
864 this._cipher.encryptBlock(Checksum, Offset);
865 this._times2(t, Offset);
866 for (var i=0; i < 4; i++) Offset[i] = t[i] ^ Offset[i];
867 this._times2(t, Offset);
868 for (var i=0; i < 4; i++) Offset[i] = t[i] ^ Offset[i];
869
870 // accumulate all but the last block
871 var num_blocks = Math.floor((header.length-1)/16);
872 for (var i=0; i < num_blocks; i++) {
873 this._times2(Offset,Offset);
874 var bstart = i*16; // start-of-block index
875 for (var j=0; j < 4; j++)
876 t[j] = Offset[j] ^ ((header[bstart+(j<<2)+3]) | (header[bstart+(j<<2)+2] << 8) | (header[bstart+(j<<2)+1] << 16) | (header[bstart+(j<<2)] << 24));
877 this._cipher.encryptBlock(t, t2);
878 for (var j=0; j < 4; j++) Checksum[j] = Checksum[j] ^ t2[j];
879 }
880
881 // accumulate the last block
882 this._times2(Offset,Offset);
883
884 if (header.length%16 == 0) {
885 var bstart = header.length-16;
886 for (var j=0; j < 4; j++)
887 Checksum[j] = Checksum[j] ^ ((header[bstart+(j<<2)+3]) | (header[bstart+(j<<2)+2] << 8) | (header[bstart+(j<<2)+1] << 16) | (header[bstart+(j<<2)] << 24));
888 this._times2(t, Offset);
889 for (var i=0; i < 4; i++) Offset[i] = Offset[i] ^ t[i];
890 } else {
891 var block_bytes = [], block = new Array(4), len = header.length, ind=0;
892 for (var i=(header.length-(header.length%16)); i < len; i++) {
893 block_bytes[ind] = header[i];
894 ind++;
895 }
896 block_bytes[ind] = 0x80;
897 ind++;
898 while (block_bytes.length%16 != 0) {
899 block_bytes[ind] = 0x00;
900 ind++;
901 }
902 aes.bytesToWords(block_bytes,block);
903 for (var j=0; j < 4; j++) {
904 var bstart = 4*j;
905 Checksum[j] = Checksum[j] ^ ((block_bytes[bstart++]<<24) | (block_bytes[bstart++]<<16) | (block_bytes[bstart++]<<8) | (block_bytes[bstart++]));
906 }
907 this._times2(t, Offset);
908 for (var i=0; i < 4; i++) Offset[i] = Offset[i] ^ t[i];
909 this._times2(t, Offset);
910 for (var i=0; i < 4; i++) Offset[i] = Offset[i] ^ t[i];
911 }
912
913 // compute result
914 for (var i=0; i < 4; i++) t[i] = Offset[i] ^ Checksum[i];
915 this._cipher.encryptBlock(t, tag);
916};
917
918
919/* Encrypts and MACs plaintext, only MACS header.
920plaintext, ciphertext and header are arrays of bytes. tag will be an array of 4 32-bit words. */
921cipherOCB.prototype.encrypt = function(plaintext, ciphertext, header, tag) {
922 var Checksum = [0x00000000,0x00000000,0x00000000,0x00000000];
923 var t = [0x00000000,0x00000000,0x00000000,0x00000000], t2 = new Array(4);
924 var Offset = new Array(4);
925 this._cipher.encryptBlock(this._cipher._iv, Offset);
926 var cbytes = [];
927
928 // encrypt and accumulate all but last block
929 var num_blocks = Math.floor((plaintext.length-1)/16), bstart=0, block = new Array(4);
930 for (var i=0; i < num_blocks; i++) {
931 this._times2(Offset,Offset);
932 bstart = 16*i;
933 for (var j=0; j < 4; j++)
934 block[j] = ((plaintext[bstart+(j<<2)+3]) | (plaintext[bstart+(j<<2)+2] << 8) | (plaintext[bstart+(j<<2)+1] << 16) | (plaintext[bstart+(j<<2)] << 24));
935 for (var j=0; j < 4; j++)
936 t[j] = Offset[j] ^ block[j];
937 this._cipher.encryptBlock(t,t2);
938 for (var j=0; j < 4; j++) t[j] = Offset[j] ^ t2[j];
939 aes.wordsToBytes(t, cbytes);
940 for (var j=0; j < 16; j++) ciphertext[bstart+j] = cbytes[j];
941 for (var j=0; j < 4; j++) Checksum[j] = Checksum[j] ^ block[j];
942 }
943
944 // encrypt and accumulate last block
945 var num_bytes = plaintext.length%16;
946 if ((num_bytes == 0) && (plaintext.length > 0)) num_bytes=16;
947 this._times2(Offset,Offset);
948 t = [0x00000000,0x00000000,0x00000000,0x00000000];
949 t[3] = num_bytes*8;
950 for (var i=0; i < 4; i++) t[i] = Offset[i] ^ t[i];
951 var Pad = new Array(4);
952 this._cipher.encryptBlock(t, Pad);
953 var pad_bytes = new Array(16);
954 aes.wordsToBytes(Pad, pad_bytes);
955 var tempbytes = [];
956 bstart = plaintext.length-num_bytes;
957 for (var i=0; i < num_bytes; i++) {
958 ciphertext[bstart+i] = plaintext[bstart+i] ^ pad_bytes[i];
959 tempbytes[tempbytes.length] = plaintext[bstart+i];
960 }
961 for (var i=num_bytes; i < 16; i++)
962 tempbytes[tempbytes.length] = pad_bytes[i];
963 aes.bytesToWords(tempbytes, t);
964 for (var i=0; i < 4; i++) Checksum[i] = Checksum[i] ^ t[i];
965
966 // compute authentication tag
967 this._times2(t,Offset);
968 for (var i=0; i < 4; i++) {
969 Offset[i] = t[i] ^ Offset[i];
970 t[i] = Checksum[i] ^ Offset[i];
971 }
972 this._cipher.encryptBlock(t,t2);
973 if (header.length > 0) {
974 this.PMAC(header, t);
975 for (var i=0; i < 4; i++) tag[i] = t[i] ^ t2[i];
976 } else {
977 for (var i=0; i < 4; i++) tag[i] = t2[i];
978 }
979};
980
981
982/* Decrypts and verifies integrity of ciphertext, only verifies integrity of header.
983ciphertext, plaintext, and header are arrays of bytes. tag is an array of 4 32-bit words.
984Returns true if tag is valid, false otherwise. */
985cipherOCB.prototype.decrypt = function(ciphertext, plaintext, header, tag) {
986 var Offset = new Array(4), Checksum = [0x00000000,0x00000000,0x00000000,0x00000000];
987 this._cipher.encryptBlock(this._cipher._iv, Offset);
988
989 var t = new Array(4), t2 = new Array(4), block = new Array(4);
990
991 // decrypt and accumulate first m-1 blocks
992 var num_blocks = Math.floor((ciphertext.length-1)/16);
993 var bstart = 0, pbytes = new Array(16);
994 this._cipher.scheduleDecrypt();
995 for (var i=0; i < num_blocks; i++) {
996 this._times2(Offset,Offset);
997 bstart = i*16;
998 for (var j=0; j < 4; j++)
999 t[j] = Offset[j] ^ ((ciphertext[bstart+(j<<2)+3]) | (ciphertext[bstart+(j<<2)+2] << 8) | (ciphertext[bstart+(j<<2)+1] << 16) | (ciphertext[bstart+(j<<2)] << 24));
1000 this._cipher.decryptBlock(t,t2);
1001 for (var j=0; j < 4; j++) {
1002 block[j] = Offset[j] ^ t2[j];
1003 Checksum[j] = block[j] ^ Checksum[j];
1004 }
1005 aes.wordsToBytes(block,pbytes);
1006 for (var j=0; j < 16; j++)
1007 plaintext[bstart+j] = pbytes[j];
1008 }
1009
1010 // decrypt and accumulate final block
1011 var Pad = new Array(4), padbytes=[];
1012 this._cipher.scheduleEncrypt()
1013 this._times2(Offset,Offset);
1014 var num_bytes = ciphertext.length%16;
1015 if ((num_bytes == 0) && (ciphertext.length > 0)) num_bytes=16;
1016 t = [0x00000000,0x00000000,0x00000000,0x00000000];
1017 t[3] = num_bytes*8;
1018 for (var i=0; i < 4; i++) t[i] = t[i] ^ Offset[i]
1019 this._cipher.encryptBlock(t,Pad);
1020 aes.wordsToBytes(Pad, padbytes);
1021 bstart = ciphertext.length - num_bytes;
1022 for (var i=0; i < num_bytes; i++) {
1023 plaintext[bstart+i] = ciphertext[bstart+i] ^ padbytes[i];
1024 t[i] = plaintext[bstart+i];
1025 }
1026 for (var i = num_bytes; i < 16; i++)
1027 t[i] = padbytes[i];
1028 aes.bytesToWords(t,t2);
1029 for (var i=0; i < 4; i++) Checksum[i] = Checksum[i] ^ t2[i];
1030
1031 // compute valid authentication tag
1032 this._times2(t, Offset);
1033 for (var i=0; i < 4; i++) {
1034 Offset[i] = Offset[i] ^ t[i];
1035 t[i] = Offset[i] ^ Checksum[i];
1036 }
1037 var validTag = new Array(4);
1038 this._cipher.encryptBlock(t,validTag);
1039 t = new Array(4);
1040 if (header.length > 0) {
1041 this.PMAC(header, t);
1042 for (var i=0; i < 4; i++) validTag[i] = validTag[i] ^ t[i];
1043 }
1044 // compute results
1045 for (var i=0; i < 4; i++) {
1046 if (aes._hex(tag[i]) != aes._hex(validTag[i])) {
1047 return false;
1048 }
1049 }
1050 return true;
1051};
1052
1053
1054
1055cipherOCB.prototype._times2 = function(dst, src) {
1056 var carry = src[0]>>>31;
1057 for (var i=0; i < 3; i++)
1058 dst[i] = (src[i]<<1) | (src[i+1]>>>31);
1059 dst[3] = (src[3]<<1) ^ (carry * 0x87);
1060};
1061
1062
1063
1064
1065
1066
1067
1068
1069/*
1070jsCrypto
1071
1072sha256.js
1073Mike Hamburg, 2008. Public domain.
1074 */
1075
1076
1077function SHA256() {
1078 if (!this.k[0])
1079 this.precompute();
1080 this.initialize();
1081}
1082
1083SHA256.prototype = {
1084 /*
1085 init:[0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19],
1086
1087 k:[0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
1088 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
1089 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
1090 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
1091 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
1092 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
1093 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
1094 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2],
1095 */
1096
1097 init:[], k:[],
1098
1099 precompute: function() {
1100 var p=2,i=0,j;
1101
1102 function frac(x) { return (x-Math.floor(x)) * 4294967296 | 0 }
1103
1104 outer: for (;i<64;p++) {
1105 for (j=2;j*j<=p;j++)
1106 if (p % j == 0)
1107 continue outer;
1108
1109 if (i<8) this.init[i] = frac(Math.pow(p,1/2));
1110 this.k[i] = frac(Math.pow(p,1/3));
1111 i++;
1112 }
1113 },
1114
1115 initialize:function() {
1116 this.h = this.init.slice(0);
1117 this.word_buffer = [];
1118 this.bit_buffer = 0;
1119 this.bits_buffered = 0;
1120 this.length = 0;
1121 this.length_upper = 0;
1122 },
1123
1124 // one cycle of SHA256
1125 block:function(words) {
1126 var w=words.slice(0),i,h=this.h,tmp,k=this.k;
1127
1128 var h0=h[0],h1=h[1],h2=h[2],h3=h[3],h4=h[4],h5=h[5],h6=h[6],h7=h[7];
1129
1130 for (i=0;i<64;i++) {
1131 if (i<16) {
1132 tmp=w[i];
1133 } else {
1134 var a=w[(i+1)&15], b=w[(i+14)&15];
1135 tmp=w[i&15]=((a>>>7^a>>>18^a>>>3^a<<25^a<<14) + (b>>>17^b>>>19^b>>>10^b<<15^b<<13) + w[i&15] + w[(i+9)&15]) | 0;
1136 }
1137
1138 tmp += h7 + (h4>>>6^h4>>>11^h4>>>25^h4<<26^h4<<21^h4<<7) + (h6 ^ h4&(h5^h6)) + k[i];
1139
1140 h7=h6; h6=h5; h5=h4;
1141 h4 = h3 + tmp | 0;
1142
1143 h3=h2; h2=h1; h1=h0;
1144
1145 h0 = (tmp + ((h1&h2)^(h3&(h1^h2))) + (h1>>>2^h1>>>13^h1>>>22^h1<<30^h1<<19^h1<<10)) | 0;
1146 }
1147
1148 h[0]+=h0; h[1]+=h1; h[2]+=h2; h[3]+=h3;
1149 h[4]+=h4; h[5]+=h5; h[6]+=h6; h[7]+=h7;
1150 },
1151
1152 update_word_big_endian:function(word) {
1153 var bb;
1154 if ((bb = this.bits_buffered)) {
1155 this.word_buffer.push(word>>>(32-bb) ^ this.bit_buffer);
1156 this.bit_buffer = word << bb;
1157 } else {
1158 this.word_buffer.push(word);
1159 }
1160 this.length += 32;
1161 if (this.length == 0) this.length_upper ++; // mmhm..
1162 if (this.word_buffer.length == 16) {
1163 this.block(this.word_buffer);
1164 this.word_buffer = [];
1165 }
1166 },
1167
1168 update_word_little_endian:function(word) {
1169 word = word >>> 16 ^ word << 16;
1170 word = ((word>>>8) & 0xFF00FF) ^ ((word<<8) & 0xFF00FF00);
1171 this.update_word_big_endian(word);
1172 },
1173
1174 update_words_big_endian: function(words) {
1175 for (var i=0; i<words.length; i++) this.update_word_big_endian(words[i]);
1176 },
1177
1178 update_words_little_endian: function(words) {
1179 for (var i=0; i<words.length; i++) this.update_word_little_endian(words[i]);
1180 },
1181
1182 update_byte:function(byte) {
1183 this.bit_buffer ^= (byte & 0xff) << (24 - (this.bits_buffered));
1184 this.bits_buffered += 8;
1185 if (this.bits_buffered == 32) {
1186 this.bits_buffered = 0;
1187 this.update_word_big_endian(this.bit_buffer);
1188 this.bit_buffer = 0;
1189 }
1190 },
1191
1192 update_string:function(string) {
1193 throw "not yet implemented";
1194 },
1195
1196 finalize:function() {
1197 var i, wb = this.word_buffer;
1198
1199 wb.push(this.bit_buffer ^ (0x1 << (31 - this.bits_buffered)));
1200 for (i = (wb.length + 2) & 15; i<16; i++) {
1201 wb.push(0);
1202 }
1203
1204 wb.push(this.length_upper);
1205 wb.push(this.length + this.bits_buffered);
1206
1207 this.block(wb.slice(0,16));
1208 if (wb.length > 16) {
1209 this.block(wb.slice(0,16));
1210 }
1211
1212 var h = this.h;
1213 this.initialize();
1214 return h;
1215 }
1216}
1217
1218SHA256.hash_words_big_endian = function(words) {
1219 var s = new SHA256();
1220 for (var i=0; i<=words.length-16; i+=16) {
1221 s.block(words.slice(i,i+16));
1222 }
1223 s.length = i << 5; // so don't pass this function more than 128M words
1224 if (i<words.length)
1225 s.update_words_little_endian(words.slice(i));
1226 return s.finalize();
1227}
1228
1229SHA256.hash_words_little_endian = function(words) {
1230 var w = words.slice(0);
1231 for (var i=0; i<w.length; i++) {
1232 w[i] = w[i] >>> 16 ^ w[i] << 16;
1233 w[i] = ((w[i]>>>8) & 0xFF00FF) ^ ((w[i]<<8) & 0xFF00FF00);
1234 }
1235 return SHA256.hash_words_big_endian(w);
1236}
1237
1238
1239
1240
1241
1242
1243
1244/*
1245
1246 jsCrypto
1247
1248 * Random.js -- cryptographic random number generator
1249 * Mike Hamburg, 2008. Public domain.
1250 *
1251 * This generator uses a modified version of Fortuna. Fortuna has
1252 * excellent resilience to compromise, relies on a state file, and is
1253 * intended to run for a long time. As such, it does not need an
1254 * entropy estimator. Unfortunately, Fortuna's startup in low-entropy
1255 * conditions leaves much to be desired.
1256 *
1257 * This generator features the following modifications. First, the
1258 * generator does not create the n-th entropy pool until it exhausts
1259 * the n-1-st. This means that entropy doesn't get "stuck" in pools
1260 * 10-31, which will never be used on a typical webpage. It also
1261 * means that the entropy will all go into a single pool until the
1262 * generator is seeded.
1263 *
1264 * Second, there is a very crude entropy estimator. The primary goal
1265 * of this estimator is to prevent the generator from being used in
1266 * low-entropy situations. Corresponding to this entropy estimator,
1267 * there is a "paranoia control". This controls how many bits of
1268 * estimated entropy must be present before the generator is used.
1269 * The generator cannot have more than 256 bits of actual entropy in
1270 * the main pool; rather, the paranoia control is designed to deal
1271 * with the fact that the entropy estimator is probably horrible.
1272 *
1273 * Third, the "statefile" is optional and stored in a cookie. As
1274 * such, it is not protected from multiple simultaneous usage, and so
1275 * is treated conservatively.
1276 */
1277
1278Random = {
1279 /* public */
1280NOT_READY: 0,
1281READY: 1,
1282REQUIRES_RESEED: 2,
1283
1284 /* generate one random word */
1285random_word: function(paranoia) {
1286 return this.random_words(1, paranoia)[0];
1287},
1288
1289 /* generate nwords random words, and return them in an array */
1290random_words: function(nwords, paranoia) {
1291 var out = [], i, readiness = this.is_ready(paranoia);
1292
1293 if (readiness == this.NOT_READY)
1294 throw("Random: generator isn't seeded!");
1295
1296 else if (readiness && this.REQUIRES_RESEED)
1297 this._reseed_from_pools(!(readiness & this.READY));
1298
1299 for (i=0; i<nwords; i+= 4) {
1300 if ((i+1) % this._max_words_per_burst == 0)
1301 this._gate();
1302
1303 var g = this._gen_4_words();
1304 out.push(g[0],g[1],g[2],g[3]);
1305 }
1306 this._gate();
1307
1308 return out.slice(0,nwords);
1309},
1310
1311set_default_paranoia: function(paranoia) {
1312 this._default_paranoia = paranoia;
1313},
1314
1315 /* Add entropy to the pools. Pass data as an array, number or
1316 * string. Pass estimated_entropy in bits. Pass the source as a
1317 * number or string.
1318 */
1319add_entropy: function(data, estimated_entropy, source) {
1320 source = source || "user";
1321
1322 var id = this._collector_ids[source] ||
1323 (this._collector_ids[source] = this._collector_id_next ++);
1324
1325 var i, ty = 0;
1326
1327 var t = new Date().valueOf();
1328
1329 var robin = this._robins[source];
1330 if (robin == undefined) robin = this._robins[source] = 0;
1331 this._robins[source] = ( this._robins[source] + 1 ) % this._pools.length;
1332
1333 switch(typeof(data)) {
1334
1335 case "number":
1336 data=[data];
1337 ty=1;
1338 break;
1339
1340 case "object":
1341 if (!estimated_entropy) {
1342 /* horrible entropy estimator */
1343 estimated_entropy = 0;
1344 for (i=0; i<data.length; i++) {
1345 var x = data[i];
1346 while (x>0) {
1347 estimated_entropy++;
1348 x = x >>> 1;
1349 }
1350 }
1351 }
1352 this._pools[robin].update_words_big_endian([id,this._event_id++,ty||2,estimated_entropy,t,data.length].concat(data));
1353 break;
1354
1355 case "string":
1356 if (!estimated_entropy) {
1357 /* English text has just over 1 bit per character of entropy.
1358 * But this might be HTML or something, and have far less
1359 * entropy than English... Oh well, let's just say one bit.
1360 */
1361 estimated_entropy = data.length;
1362 }
1363 this._pools[robin].update_words_big_endian([id,this._event_id++,3,estimated_entropy,t,data.length])
1364 this._pools[robin].update_string(data);
1365 break;
1366
1367 default:
1368 throw "add_entropy: must give an array, number or string"
1369 }
1370
1371 var old_ready = this.is_ready();
1372
1373 /* record the new strength */
1374 this._pool_entropy[robin] += estimated_entropy;
1375 this._pool_strength += estimated_entropy;
1376
1377 /* fire off events */
1378 if (!old_ready && this.is_ready())
1379 this._fire_event("seeded", Math.max(this._strength, this._pool_strength));
1380
1381 if (!old_ready)
1382 this._fire_event("progress", this.get_progress());
1383},
1384
1385 /* is the generator ready? */
1386is_ready: function(paranoia) {
1387 var entropy_required = this._PARANOIA_LEVELS[ paranoia ? paranoia : this._default_paranoia ];
1388
1389 if (this._strength >= entropy_required) {
1390 return (this._pool_entropy[0] > this._BITS_PER_RESEED && new Date.valueOf() > this._next_reseed) ?
1391 this.REQUIRES_RESEED | this.READY :
1392 this.READY;
1393 } else {
1394 return (this._pool_strength > entropy_required) ?
1395 this.REQUIRES_RESEED | this.NOT_READY :
1396 this.NOT_READY;
1397 }
1398},
1399
1400 /* how close to ready is it? */
1401get_progress: function(paranoia) {
1402 var entropy_required = this._PARANOIA_LEVELS[ paranoia ? paranoia : this._default_paranoia ];
1403
1404 if (this._strength >= entropy_required) {
1405 return 1.0;
1406 } else {
1407 return (this._pool_strength > entropy_required) ?
1408 1.0 :
1409 this._pool_strength / entropy_required;
1410 }
1411},
1412
1413 /* start the built-in entropy collectors */
1414start_collectors: function() {
1415 if (this._collectors_started) return;
1416
1417 if (window.addEventListener) {
1418 window.addEventListener("load", this._load_time_collector, false);
1419 window.addEventListener("mousemove", this._mouse_collector, false);
1420 } else if (document.attachEvent) {
1421 document.attachEvent("onload", this._load_time_collector);
1422 document.attachEvent("onmousemove", this._mouse_collector);
1423 }
1424 else throw("can't attach event");
1425
1426 this._collectors_started = true;
1427},
1428
1429 /* stop the built-in entropy collectors */
1430stop_collectors: function() {
1431 if (!this._collectors_started) return;
1432
1433 if (window.removeEventListener) {
1434 window.removeEventListener("load", this._load_time_collector);
1435 window.removeEventListener("mousemove", this._mouse_collector);
1436 } else if (window.detachEvent) {
1437 window.detachEvent("onload", this._load_time_collector);
1438 window.detachEvent("onmousemove", this._mouse_collector)
1439 }
1440 this._collectors_started = false;
1441},
1442
1443use_cookie: function(all_cookies) {
1444 throw "TODO: implement use_cookie";
1445},
1446
1447 /* add an event listener for progress or seeded-ness */
1448addEventListener: function(name, callback) {
1449 this._callbacks[name][this._callback_i++] = callback;
1450},
1451
1452 /* remove an event listener for progress or seeded-ness */
1453removeEventListener: function(name, cb) {
1454 var i, j, cbs=this._callbacks[name], js_temp=[];
1455
1456 /* I'm not sure if this is necessary; in C++, iterating over a
1457 * collection and modifying it at the same time is a no-no.
1458 */
1459
1460 for (j in cbs)
1461 if (cbs.hasOwnProperty[j] && cbs[j] === cb)
1462 js_temp.push(j);
1463
1464 for (i=0; i<js_temp.length; i++) {
1465 j = js[i];
1466 delete cbs[j];
1467 }
1468},
1469
1470 /* private */
1471 _pools : [new SHA256()],
1472 _pool_entropy : [0],
1473 _reseed_count : 0,
1474 _robins : {},
1475 _event_id : 0,
1476
1477 _collector_ids : {},
1478 _collector_id_next : 0,
1479
1480 _strength : 0,
1481 _pool_strength : 0,
1482 _next_reseed : 0,
1483 _key : [0,0,0,0,0,0,0,0],
1484 _counter : [0,0,0,0],
1485 _cipher : undefined,
1486 _default_paranoia : 6,
1487
1488 /* event listener stuff */
1489 _collectors_started : false,
1490 _callbacks : {progress: {}, seeded: {}},
1491 _callback_i : 0,
1492
1493 /* constants */
1494 _MAX_WORDS_PER_BURST : 65536,
1495 _PARANOIA_LEVELS : [0,48,64,96,128,192,256,384,512,768,1024],
1496 _MILLISECONDS_PER_RESEED : 100,
1497 _BITS_PER_RESEED : 80,
1498
1499 /* generate 4 random words, no reseed, no gate */
1500_gen_4_words: function() {
1501 var words = [];
1502 for (var i=0; i<3; i++) if (++this._counter[i]) break;
1503 this._cipher.encryptBlock(this._counter, words);
1504 return words;
1505},
1506
1507 /* rekey the AES instance with itself after a request, or every _MAX_WORDS_PER_BURST words */
1508_gate: function() {
1509 this._key = this._gen_4_words().concat(this._gen_4_words());
1510 this._cipher = new aes(this._key);
1511},
1512
1513 /* reseed the generator with the given words */
1514_reseed: function(seedWords) {
1515 this._key = SHA256.hash_words_big_endian(this._key.concat(seedWords));
1516 this._cipher = new aes(this._key);
1517 for (var i=0; i<3; i++) if (++this._counter[i]) break;
1518},
1519
1520 /* reseed the data from the entropy pools */
1521_reseed_from_pools: function(full) {
1522 var reseed_data = [], strength = 0;
1523
1524 this._next_reseed = new Date().valueOf() + this._MILLISECONDS_PER_RESEED;
1525
1526 for (i=0; i<this._pools.length; i++) {
1527 reseed_data = reseed_data.concat(this._pools[i].finalize());
1528 strength += this._pool_entropy[i];
1529 this._pool_entropy[i] = 0;
1530
1531 if (!full && (this._reseed_count & (1<<i))) break;
1532 }
1533
1534 /* if we used the last pool, push a new one onto the stack */
1535 if (this._reseed_count >= 1 << this._pools.length) {
1536 this._pools.push(new SHA256());
1537 this._pool_entropy.push(0);
1538 }
1539
1540 /* how strong was this reseed? */
1541 this._pool_strength -= strength;
1542 if (strength > this._strength) this._strength = strength;
1543
1544 this._reseed_count ++;
1545 this._reseed(reseed_data);
1546},
1547
1548_mouse_collector: function(ev) {
1549 var x = ev.x || ev.clientX || ev.offsetX;
1550 var y = ev.y || ev.clientY || ev.offsetY;
1551 Random.add_entropy([x,y], 2, "mouse");
1552},
1553
1554_load_time_collector: function(ev) {
1555 var d = new Date();
1556 Random.add_entropy(d, 2, "loadtime");
1557},
1558
1559_fire_event: function(name, arg) {
1560 var j, cbs=Random._callbacks[name], cbs_temp=[];
1561
1562 /* I'm not sure if this is necessary; in C++, iterating over a
1563 * collection and modifying it at the same time is a no-no.
1564 */
1565
1566 for (j in cbs) {
1567 if (cbs.hasOwnProperty(j)) {
1568 cbs_temp.push(cbs[j]);
1569 }
1570 }
1571
1572 for (j=0; j<cbs_temp.length; j++) {
1573 cbs_temp[j](arg);
1574 }
1575}
1576};
1577