summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Crypto
Side-by-side diff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto') (more/less context) (ignore 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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.Crypto.AES_v3 - TEST</title>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+
+try {
+ var block;
+ var keyValue;
+ var key;
+ var encryptedBlock;
+ var startTime, endTime;
+
+ startTime = new Date();
+
+ keyValue = new Clipperz.ByteArray("0x00010203050607080a0b0c0d0f10111214151617191a1b1c1e1f202123242526");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0x834eadfccac7e1b30664b1aba44815ab");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x1946dabf6a03a2a2c3d0b05080aed6fc", "Test 1");
+
+ keyValue = new Clipperz.ByteArray("0x28292a2b2d2e2f30323334353738393a3c3d3e3f41424344464748494b4c4d4e");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0xd9dc4dba3021b05d67c0518f72b62bf1");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x5ed301d747d3cc715445ebdec62f2fb4", "Test 2");
+
+ keyValue = new Clipperz.ByteArray("0x50515253555657585a5b5c5d5f60616264656667696a6b6c6e6f707173747576");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0xa291d86301a4a739f7392173aa3c604c");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x6585c8f43d13a6beab6419fc5935b9d0", "Test 3");
+
+ keyValue = new Clipperz.ByteArray("0x78797a7b7d7e7f80828384858788898a8c8d8e8f91929394969798999b9c9d9e");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0x4264b2696498de4df79788a9f83e9390");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x2a5b56a596680fcc0e05f5e0f151ecae", "Test 4");
+
+ keyValue = new Clipperz.ByteArray("0xa0a1a2a3a5a6a7a8aaabacadafb0b1b2b4b5b6b7b9babbbcbebfc0c1c3c4c5c6");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0xee9932b3721804d5a83ef5949245b6f6");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0xf5d6ff414fd2c6181494d20c37f2b8c4", "Test 5");
+
+ keyValue = new Clipperz.ByteArray("0xc8c9cacbcdcecfd0d2d3d4d5d7d8d9dadcdddedfe1e2e3e4e6e7e8e9ebecedee");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0xe6248f55c5fdcbca9cbbb01c88a2ea77");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x85399c01f59fffb5204f19f8482f00b8", "Test 6");
+
+ keyValue = new Clipperz.ByteArray("0xf0f1f2f3f5f6f7f8fafbfcfdfe01000204050607090a0b0c0e0f101113141516");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0xb8358e41b9dff65fd461d55a99266247");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x92097b4c88a041ddf98144bc8d22e8e7", "Test 7");
+
+ keyValue = new Clipperz.ByteArray("0x18191a1b1d1e1f20222324252728292a2c2d2e2f31323334363738393b3c3d3e");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0xf0e2d72260af58e21e015ab3a4c0d906");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x89bd5b73b356ab412aef9f76cea2d65c", "Test 8");
+
+ keyValue = new Clipperz.ByteArray("0x40414243454647484a4b4c4d4f50515254555657595a5b5c5e5f606163646566");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0x475b8b823ce8893db3c44a9f2a379ff7");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x2536969093c55ff9454692f2fac2f530", "Test 9");
+
+ keyValue = new Clipperz.ByteArray("0x68696a6b6d6e6f70727374757778797a7c7d7e7f81828384868788898b8c8d8e");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ block = new Clipperz.ByteArray("0x688f5281945812862f5f3076cf80412f");
+ encryptedBlock = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(key, block.arrayValues()));
+ is(encryptedBlock.toHexString(), "0x07fc76a872843f3f6e0081ee9396d637", "Test 10");
+
+ //-------------------------------------------------------------------------
+ //
+ // Key expansion
+ //
+ //-------------------------------------------------------------------------
+ // test vector: http://en.wikipedia.org/wiki/Rijndael_key_schedule#Test_vectors
+
+ keyValue = new Clipperz.ByteArray("0x0000000000000000000000000000000012345678");
+ try {
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ is(true, false, "Unsupported key size");
+ } catch (exception) {
+ is(true, true, "Unsupported key size");
+ }
+
+ keyValue = new Clipperz.ByteArray("0x00000000000000000000000000000000");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ is( key.stretchedKey().toHexString(),
+ "0x" + "00000000000000000000000000000000" +
+ "62636363626363636263636362636363" +
+ "9b9898c9f9fbfbaa9b9898c9f9fbfbaa" +
+ "90973450696ccffaf2f457330b0fac99" +
+ "ee06da7b876a1581759e42b27e91ee2b" +
+ "7f2e2b88f8443e098dda7cbbf34b9290" +
+ "ec614b851425758c99ff09376ab49ba7" +
+ "217517873550620bacaf6b3cc61bf09b" +
+ "0ef903333ba9613897060a04511dfa9f" +
+ "b1d4d8e28a7db9da1d7bb3de4c664941" +
+ "b4ef5bcb3e92e21123e951cf6f8f188e",
+ "Stretched empty key");
+
+
+ keyValue = new Clipperz.ByteArray("0x0000000000000000000000000000000000000000000000000000000000000000");
+ key = new Clipperz.Crypto.AES.Key({key:keyValue});
+ is( key.stretchedKey().toHexString(),
+ "0x" + "00000000000000000000000000000000" +
+ "00000000000000000000000000000000" +
+ "62636363626363636263636362636363" +
+ "aafbfbfbaafbfbfbaafbfbfbaafbfbfb" +
+ "6f6c6ccf0d0f0fac6f6c6ccf0d0f0fac" +
+ "7d8d8d6ad77676917d8d8d6ad7767691" +
+ "5354edc15e5be26d31378ea23c38810e" +
+ "968a81c141fcf7503c717a3aeb070cab" +
+ "9eaa8f28c0f16d45f1c6e3e7cdfe62e9" +
+ "2b312bdf6acddc8f56bca6b5bdbbaa1e" +
+ "6406fd52a4f79017553173f098cf1119" +
+ "6dbba90b0776758451cad331ec71792f" +
+ "e7b0e89c4347788b16760b7b8eb91a62" +
+ "74ed0ba1739b7e252251ad14ce20d43b" +
+ "10f80a1753bf729c45c979e7cb706385",
+ "Stretched empty key");
+
+ var roundIndex;
+
+ roundIndex = 0;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x00000000000000000000000000000000", "empty key, subKeyAtRound(0)");
+ roundIndex = 1;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x00000000000000000000000000000000", "empty key, subKeyAtRound(1)");
+ roundIndex = 2;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x62636363626363636263636362636363", "empty key, subKeyAtRound(2)");
+ roundIndex = 3;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0xaafbfbfbaafbfbfbaafbfbfbaafbfbfb", "empty key, subKeyAtRound(3)");
+ roundIndex = 4;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6f6c6ccf0d0f0fac6f6c6ccf0d0f0fac", "empty key, subKeyAtRound(4)");
+ roundIndex = 5;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x7d8d8d6ad77676917d8d8d6ad7767691", "empty key, subKeyAtRound(5)");
+ roundIndex = 6;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x5354edc15e5be26d31378ea23c38810e", "empty key, subKeyAtRound(6)");
+ roundIndex = 7;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x968a81c141fcf7503c717a3aeb070cab", "empty key, subKeyAtRound(7)");
+ roundIndex = 8;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x9eaa8f28c0f16d45f1c6e3e7cdfe62e9", "empty key, subKeyAtRound(8)");
+ roundIndex = 9;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x2b312bdf6acddc8f56bca6b5bdbbaa1e", "empty key, subKeyAtRound(9)");
+ roundIndex = 10;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6406fd52a4f79017553173f098cf1119", "empty key, subKeyAtRound(10)");
+ roundIndex = 11;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x6dbba90b0776758451cad331ec71792f", "empty key, subKeyAtRound(11)");
+ roundIndex = 12;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0xe7b0e89c4347788b16760b7b8eb91a62", "empty key, subKeyAtRound(12)");
+ roundIndex = 13;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x74ed0ba1739b7e252251ad14ce20d43b", "empty key, subKeyAtRound(13)");
+ roundIndex = 14;
+ is(key.stretchedKey().split(roundIndex*16, roundIndex*16 + 16).toHexString(), "0x10f80a1753bf729c45c979e7cb706385", "empty key, subKeyAtRound(14)");
+
+
+ //-------------------------------------------------------------------------
+ //
+ // Encrypt / decrypt
+ //
+ //-------------------------------------------------------------------------
+ // Test vectors: http://www.zvon.org/tmRFC/RFC3686/Output/chapter6.html
+ // http://www.cs.utsa.edu/~wagner/laws/AEStestRuns.html
+ // http://www.ietf.org/rfc/rfc3686.txt
+
+ {
+ //
+ // http://www.cs.utsa.edu/~wagner/laws/AEStestRuns.html
+ //
+ var key;
+ var plainText;
+ var cipherText;
+ var result;
+
+ //
+ // 256-bit key size
+ //
+
+ // Gladman's Test Data, 256-bit key - encrypt
+ key = new Clipperz.ByteArray("0x2b7e151628aed2a6abf7158809cf4f3c762e7160f38b4da56a784d9045190cfe", 16);
+ plainText = new Clipperz.ByteArray("0x3243f6a8885a308d313198a2e0370734", 16);
+ cipherText = new Clipperz.ByteArray("0x1a6e6c2c662e7da6501ffb62bc9e93f3", 16);
+
+ result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
+ is(result.toHexString(), cipherText.toHexString(), "Gladman's Test Data, 256-bit key - encrypt");
+
+ // AES Specification Test Data, 256-bit key - encrypt
+ key = new Clipperz.ByteArray("0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 16);
+ plainText = new Clipperz.ByteArray("0x00112233445566778899aabbccddeeff", 16);
+ cipherText = new Clipperz.ByteArray("0x8ea2b7ca516745bfeafc49904b496089", 16);
+
+ result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
+ is(result.toHexString(), cipherText.toHexString(), "AES Specification Test Data, 256-bit key - encrypt");
+
+ //
+ // 128-bit key size
+ //
+
+ // Gladman's Test Data, 128-bit key - encrypt
+ key = new Clipperz.ByteArray("0x2b7e151628aed2a6abf7158809cf4f3c", 16);
+ plainText = new Clipperz.ByteArray("0x3243f6a8885a308d313198a2e0370734", 16);
+ cipherText = new Clipperz.ByteArray("0x3925841d02dc09fbdc118597196a0b32", 16);
+
+ result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
+ is(result.toHexString(), cipherText.toHexString(), "Gladman's Test Data, 128-bit key - encrypt");
+
+ // AES Specification Test Data, 128-bit key - encrypt
+ key = new Clipperz.ByteArray("0x000102030405060708090a0b0c0d0e0f", 16);
+ plainText = new Clipperz.ByteArray("0x00112233445566778899aabbccddeeff", 16);
+ cipherText = new Clipperz.ByteArray("0x69c4e0d86a7b0430d8cdb78070b4c55a", 16);
+
+ result = new Clipperz.ByteArray(Clipperz.Crypto.AES.encryptBlock(new Clipperz.Crypto.AES.Key({key:key}), plainText.arrayValues()));
+ is(result.toHexString(), cipherText.toHexString(), "AES Specification Test Data, 128-bit key - encrypt");
+
+ }
+
+
+ endTime = new Date();
+ MochiKit.Logging.logDebug("elapsed time: " + (endTime - startTime));
+
+//#############################################################################
+
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.Crypto.AES_performance - TEST</title>
+
+ <script>
+ jslog_config_enabled = true;
+ </script>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/PM/Proxy.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/PM/Connection.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/PM/Crypto.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
+
+try {
+
+ var password;
+ var plainText;
+ var encryptedText;
+ var decryptedText;
+/*
+ password = "trustno1";
+ plainText = "The quick brown fox jumps over the lazy dog";
+//console.profile("encrypt");
+ encryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].encrypt(password, plainText);
+//console.profileEnd();
+//console.profile("decrypt");
+ decryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].decrypt(password, encryptedText);
+//console.profileEnd();
+ is(decryptedText, plainText, "simple string encrypted/decrypted");
+*/
+
+ password = "L7bd9fQMhborMbYcHtlr";
+ 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"}};
+/* */
+ plainText = {
+ "records": {
+ "1": {
+ "label":"imap4all [no]",
+ "key":"f54b5033d1152456acb67974c45ee6771f8411e300c9533359dfacacf60dcbbd",
+ "notes":""
+ },
+ "2": {
+ "label":"Il manifesto",
+ "key":"6e0ef134503110e72f444e7d102a4b1cc6ae28f2e0b1287c2b1875ff052fc16c",
+ "notes":""
+ },
+ "3": {
+ "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:"
+ },
+ "4": {
+ "label": "R@cine",
+ "key": "57295772c84669b0a224f435e9b75c797ae5999a2d9473ab50f9384ae54f49d6",
+ "notes": ""
+ },
+ "5": {
+ "label": "NewsGator",
+ "key": "6ee16f6932ee02000c49dbcc685c84074b40d7956e5f4bc1100030a0f9a41f1a",
+ "notes": ""
+ },
+ "6": {
+ "label": "GMail - giulio.cesare",
+ "key": "0395efd852b00700bcf78b65350ec15932430df71201d2c53a11b0269b557d1a",
+ "notes": ""
+ },
+ "7": {
+ "label": "GMail - clipperz.com",
+ "key": "90d6ae70d89c8211404b6f9d6c70b6b9c113fff74f474a67b34acd9c1c048d1f",
+ "notes": ""
+ },
+ "8": {
+ "label": "Aruba - hosting",
+ "key": "5c7472d24d57391c63ea99ed1fc9de179d225abd335fa65702018cfea6083d47",
+ "notes": ""
+ },
+ "9": {
+ "label": "Aruba - sql hosting",
+ "key": "f6bd942ac3b0b7065771e5197c7499b345a10f7a4843d00c3ba3809d0ea059dc",
+ "notes": ""
+ },
+ "10": {
+ "label": "Amazon",
+ "key": "1ae022b4d14b642f113703b2a98931bd892dec2da785ab5ff6fc1d0aac7537f1",
+ "notes": ""
+ },
+ "11": {
+ "label": "YouTube [no]",
+ "key": "4c6593d4f6448137939b364b84c81501fadb60f7871fe5fa63c93e97bb5c4648",
+ "notes": ""
+ },
+ "12": {
+ "label": "DynDns - gcsolaroli",
+ "key": "f8ed9e7a3630deed046eda37ebc63ecb4d63668a2f97224d7628fdc53b242467",
+ "notes": ""
+ },
+ "13": {
+ "label": "DynDns - clipperz",
+ "key": "d8bc295177383a523e67b61b166e0ca956ab4c2ee86800559a009d2716064f6d",
+ "notes": ""
+ },
+ "14": {
+ "label": "Bol.it",
+ "key": "cada5dadeebd8d12190954d21f1a944c8799d034f028be195b448935fcf970c7",
+ "notes": ""
+ },
+ "15": {
+ "label": "Freenigma - clipperz.com",
+ "key": "f09cb3790c1110794b834702b8c487c1a42b2508fbe6450a8468477d93790b2e",
+ "notes": ""
+ },
+ "16": {
+ "label": "Freenigma",
+ "key": "4b05738f6faebc147eac5e425054a91d3cc59dd63844e82d1f0864c0ac8efec7",
+ "notes": ""
+ },
+ "17": {
+ "label": "clipperz.com - blog",
+ "key": "9cc24328bbce18e8713962428d8123e309a12f7e1d9537bc252e134501734003",
+ "notes": ""
+ },
+ "18": {
+ "label": "Apple",
+ "key": "75f2651af400629c4e5dd8bcdc3a6c691150d23d6e1a4eb263ff810926d1228f",
+ "notes": ""
+ },
+ "19": {
+ "label": ".mac",
+ "key": "5934ae96d2e01282effb368d9086c2ba5d1d856ad91dd6f04f5bace26a1c0cbe",
+ "notes": ""
+ },
+ "20": {
+ "label": "3nity",
+ "key": "33d84c4a91ab053cbf8115c689ede7e504b81199884de449acc257bea534f57f",
+ "notes": ""
+ },
+ "21": {
+ "label": "ACM",
+ "key": "b4976bb0892baba81d628513d191de100d89acd58efbb07c823a5bb4abe48a7a",
+ "notes": ""
+ },
+ "22": {
+ "label": "Adobe",
+ "key": "d162bc404994a79ec97e0106c3a4edf2f83aca25def130242e11e95e74bd0aaa",
+ "notes": ""
+ },
+ "23": {
+ "label": "Adobe Photoshop Elements 3",
+ "key": "18a62c3c2065399819707322f467ff4be030d7939acbe5182c8194599845c428",
+ "notes": "Photoshop Elements 2:\n1057-4312-5223-2206-9509-6837"
+ },
+ "24": {
+ "label": "Agatra",
+ "key": "c35158a21b2af75d414232b742ab738d042314e00209f8fca94c8c704c891f23",
+ "notes": ""
+ },
+ "25": {
+ "label": "AIM",
+ "key": "8561ac421d845921978387b5e6b362750b57ed08feda8ec12b9378b69f67ceff",
+ "notes": ""
+ },
+ "26": {
+ "label": "Anna Vespignani",
+ "key": "79a970af0d2d30643dc2db4d16757395c1f22c311919036c2a22b7581982144a",
+ "notes": ""
+ },
+ "27": {
+ "label": "Bloglines",
+ "key": "fe81f4df8c42fd81c830f9af408e9b074e77fd430e26d0ee285844fe3b092aec",
+ "notes": ""
+ },
+ "28": {
+ "label": "Bow.it",
+ "key": "64a1a9fec99c9238dc8180a01484a1ccf5f50fcd6e9a95a52b8b49fb9ca00bdc",
+ "notes": ""
+ },
+ "29": {
+ "label": "GMail - feedback",
+ "key": "fad310cb2e6152c3faf78b7183c99f3044f5d31ee364068b80580c271a7784ef",
+ "notes": ""
+ },
+ "30": {
+ "label": "Fineco",
+ "key": "8f99de2635b5dad7987180bc0bff49947eb37cc75d6a5d1ee1f13ed7567465a3",
+ "notes": ""
+ },
+ "31": {
+ "label": "mon.itor.us",
+ "key": "d2aa7164007c5deac8bb73580a6ab0d051f747e801ecd30284eff725d0ffaba2",
+ "notes": ""
+ },
+ "32": {
+ "label": "Lamba Probe - forum",
+ "key": "f73906817fddba4d8f816334cb2fd0cd5ae91bc29bce6a69fdd5cf98fc96911f",
+ "notes": ""
+ },
+ "33": {
+ "label": "MeasureMap",
+ "key": "2385ce9536ebb7863b6a4c8b1f5c428587e4d6420a4bbcd31b935cb00bbd768e",
+ "notes": ""
+ },
+ "34": {
+ "label": "NGI - Squillo",
+ "key": "96f20c212be02fb38c8b2dfc83d8e864dd84dcb95297a7fecf9280e1e4dcffe3",
+ "notes": ""
+ },
+ "35": {
+ "label": "NGI - F5",
+ "key": "00347769244b208647c24e6a64f8fa4213e97eb2135ecfcb277b341c28616a59",
+ "notes": ""
+ },
+ "36": {
+ "label": "CVSdude",
+ "key": "ed0ab5080a29eb1b20927142d21ab8f67b61c2c7b19623bb610af030dfd42c02",
+ "notes": ""
+ },
+ "37": {
+ "label": "Yahoo",
+ "key": "6380a7655cd790d1f1e6f482e92ae04201568ff0cab887e65102e9396df1b86e",
+ "notes": "note"
+ }
+ },
+ "directLogins": {
+ "1": { "record": "1", "label": "R@cine - WebMail", "favicon": "http://www.racine.ra.it/favicon.ico" },
+ "2": { "record": "2", "label": "Amazon sign in", "favicon": "http://www.amazon.com/favicon.ico" },
+ "3": { "record": "3", "label": "Aruba - hosting", "favicon": "http://hosting.aruba.it/favicon.ico" },
+ "4": { "record": "4", "label": "Aruba - sql hosting", "favicon":"http://mysql.aruba.it/favicon.ico" },
+ "5": { "record": "5", "label":"clipperz.com - blog", "favicon":"http://www.clipperz.com/favicon.ico" },
+ "6": { "record":"6", "label":"DynDns - clipperz", "favicon":"http://www.dyndns.com/favicon.ico" },
+ "7": { "record":"7", "label":"DynDns - gcsolaroli", "favicon":"http://www.dyndns.com/favicon.ico" },
+ "8":{"record":"8", "label":"GMail - giulio.cesare", "favicon":"http://www.google.com/favicon.ico" },
+ "9":{"record":"9", "label":"Il manifesto", "favicon":"http://abbonati.ilmanifesto.it/favicon.ico" },
+ "10":{"record":"10", "label":"Imap4All.com - account", "favicon":"http://www.imap4all.com/favicon.ico" },
+ "11":{"record":"12", "label":"Imap4all.com - WebMail", "favicon":"http://webmail.imap4all.com/favicon.ico" },
+ "13":{"record":"13", "label":"YouTube [no]", "favicon":"http://www.youtube.com/favicon.ico" },
+ "14":{"record":"14", "label":"Apple Store - Italia", "favicon":"http://store.apple.com/favicon.ico" },
+ "15":{"record":"15", "label":"3nity", "favicon":"http://www.3nity.de/favicon.ico" },
+ "16":{"record":"16", "label":"ACM Web Account", "favicon":"http://portal.acm.org/favicon.ico" },
+ "17":{"record":"17", "label":"Adobe - Sign In", "favicon":"http://www.adobe.com/favicon.ico" },
+ "18":{"record":"18", "label":"Agatra [no]", "favicon":"http://www.agatra.com/favicon.ico" },
+ "19":{"record":"19", "label":"AIM [no]", "favicon":"http://my.screenname.aol.com/favicon.ico" },
+ "20":{"record":"20", "label":"Bloglines", "favicon":"http://www.bloglines.com/favicon.ico" },
+ "21":{"record":"21", "label":"Bow.it", "favicon":"http://www.bow.it/favicon.ico" },
+ "22":{"record":"22", "label":"GMail - Clipperz", "favicon":"http://www.google.com/favicon.ico" },
+ "23":{"record":"23", "label":"GMail - feedback", "favicon":"http://www.google.com/favicon.ico" },
+ "24":{"record":"24", "label":"Blogger", "favicon":"http://www.google.com/favicon.ico" },
+ "25":{"record":"25", "label":"NewsGator", "favicon":"http://www.newsgator.com/favicon.ico" },
+ "26":{"record":"26", "label":"Lambda Probe - forum", "favicon":"http://www.lambdaprobe.org/favicon.ico" },
+ "27":{"record":"27", "label":"Measure Map", "favicon":"http://alpha.measuremap.com/favicon.ico" },
+ "28":{"record":"28", "label":"NGI - Squillo", "favicon":"http://www.ngi.it/favicon.ico" },
+ "29":{"record":"29", "label":"NGI - F5", "favicon":"http://www.ngi.it/favicon.ico" },
+ "30":{"record":"30", "label":"Yahoo! Mail", "favicon":"http://login.yahoo.com/favicon.ico"}
+ },
+ "preferences":{"preferredLanguage":"en-US"}
+ }
+/* */
+
+//console.profile("encrypt 0.2");
+ encryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].encrypt(password, plainText);
+//console.profileEnd();
+//console.profile("decrypt");
+// decryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.2'].decrypt(password, encryptedText);
+//console.profileEnd();
+// is(MochiKit.Base.serializeJSON(decryptedText), MochiKit.Base.serializeJSON(plainText), "complex structure encrypted/decrypted");
+
+//console.profile("encrypt 0.3");
+ encryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].encrypt(password, plainText);
+//console.profileEnd();
+ decryptedText = Clipperz.PM.Crypto.encryptingFunctions.versions['0.3'].decrypt(password, encryptedText);
+ is(MochiKit.Base.serializeJSON(decryptedText), MochiKit.Base.serializeJSON(plainText), "complex structure encrypted/decrypted");
+
+
+//#############################################################################
+
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+ var secretKey;
+ var publicKey;
+ var plainString;
+ var encryptedString;
+
+
+ secretKey = "s3cr37k39";
+ plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+
+ //-------------------------------------------------------------------------
+ //
+ // Secret key encryption / decryption
+ //
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string should not be empty");
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ try {
+ var decryptedText;
+
+ decryptedText = Clipperz.Crypto.Base.decryptUsingSecretKey("anotherKey", encryptedString);
+ ok( false, "It should not be possible to decrypt a text with a different passphrase (decrypted text: " + decryptedText + ")" );
+ } catch (e) {
+ ok( e instanceof Error, "Trying to decrypt a message with the wrong passphrase raised an error" );
+ }
+
+ is (encryptedString == Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString), false, "Two consecutive encryption of the same text should return different values");
+
+ secretKey = "trustno1";
+ plainString = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ secretKey = "trustno1";
+ 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.";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ secretKey = "trustno1";
+ 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";
+ encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+// secretKey = "trustno1";
+// plainString = "{}";
+// 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'}}} ";
+// plainString = "{'tags': {}, 'records': {'07a5a92fcb334f757998ba14f3251f126d038318b3ac5e584bd712804c548084': {'label': 'Un bel record', 'key': '2a3f261c20a6a98dcc82b13fba013130b759f20602b4b13c5760879e087482a4'}}}";
+// encryptedString = Clipperz.Crypto.Base.encryptUsingSecretKey(secretKey, plainString);
+// is(encryptedString, "{}", "encrypted value");
+
+
+// secretKey = "trustno1";
+// encryptedString = "0d43a4544424ffa519f2e43b7a46f703884fd94ff9879479563f6f252a573b253d3e77bc4f5f30f17bd11d2907718921ab8c9e1faccbe4314793fa323eb85eaf1bfbce5f7deea601e15b781782181cbff3c649dafef39abb70e8573e4f9be220f2286b01c3bd51d5c4a79b9d44a27be3b0994667302e301ca3dc074fb1bc7abc03d12b9e58ba0249435a120858c96e8ae99570718541499ab958a8fb92b63390be070ff61fc6ef107061693ab14c1915118cc6671ab7cf99b9cca553d6b5a7c314bffcd933e0a59f056d842a47cfe8571110b4764c5225443210d99b43b80a23c20fe953de3e1329d72cfb20139fe1ca";
+// plainString = Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString);
+// is(plainString, "{}", "decrypted value");
+
+ //-------------------------------------------------------------------------
+ //
+ // Java secret key encryption / JavaScript decryption
+ //
+ secretKey = "s3cr37k39";
+ plainString = "The Quick Brown Fox Jumps Over The Lazy Dog";
+ encryptedString = "9be538c3dde4dfab9384c0ef71dc624299fbbe71be8d1fe8991fd6cae88a883cf459d7cd56913a2b69815782cf74d7ce5c2c08034661f7f8aa59cf420e913086896840ebb45102d44d733d32de2a7dc8";
+ is (plainString, Clipperz.Crypto.Base.decryptUsingSecretKey(secretKey, encryptedString), "I should be able to encrypt and then decrypt safely");
+
+ //-------------------------------------------------------------------------
+ //
+ // Public key encryption -> Private key decryption
+ //
+ {
+ var cleanKey;
+ var t1, t2;
+/*
+ //
+ // 128
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039"; // a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "202700adbd85e2d7182720c3a0ee19c1",
+ "30db31542ace0f7d37a629ee5eba28cb"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 128");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 128");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 128");
+*/
+/*
+ //
+ // 256
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
+ "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 256");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 256");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 256");
+*/
+/*
+ //
+ // 512
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
+ "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+//is("Encrypting with public key (512)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 512");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 512");
+t2 = new Date().getTime();
+//is("Decrypting with private key (512)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 512");
+*/
+/*
+ //
+ // 1024
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
+ "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with public key (1024)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 1024");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 1024");
+t2 = new Date().getTime();
+is("Decrypting with private key (1024)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 1024");
+*/
+/*
+ //
+ // 2048
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
+ "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPublicKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with public key (2048)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PUBLIC 2048");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PUBLIC 2048");
+t2 = new Date().getTime();
+is("Decrypting with private key (2048)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PUBLIC 2048");
+*/
+ }
+
+ //-------------------------------------------------------------------------
+ //
+ // Private key encryption -> Public key decryption
+ //
+ {
+ var cleanKey;
+ var t1, t2;
+/*
+ //
+ // 128
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039"; // a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "202700adbd85e2d7182720c3a0ee19c1",
+ "30db31542ace0f7d37a629ee5eba28cb"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 128");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 128");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 128");
+*/
+/*
+ //
+ // 256
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ cleanKey = "a3c2863242653caf566b02d8be5d6eb6c816ac212378bcec7ff2bdce8e2ec709";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "8064edb1f26944f6bec2b68789db7ffd08b074d0953b76feca71dc8265c60e9",
+ "2687f5ac6c70f9cab32fcbded7059502f4c7cc95fc3e09a560c68975ac4bf5e3"
+ );
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 256");
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 256");
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again the private key - PRIVATE 256");
+*/
+/*
+ //
+ // 512
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da90415623fb73386e9635034fb65ad5f248445a1c66703f760d64a8271ad342b1",
+ "8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+//is("Encrypting with private key (512)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 512");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 512");
+t2 = new Date().getTime();
+//is("Decrypting with public key (512)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 512");
+*/
+/*
+ //
+ // 1024
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "12e8da920d4599458e84ec5ef1656161807f427d05eb79182b7418259d6f6c14364d1f5caf9130c8d9d9d6ea71d1bdbc87781a46a16bcb9e672814fed3b9c96ddffe0a1b0955ae68055c8f92fef518a04fc32a2ea8390e617cc5556a251f9ae9eee70a32e579cb3e9f298848a9b3aaf634f5930ffbf74473f7cb6c0cefee1751",
+ "130ebebd67b16a9ab2c53a437badbf8f01a80c750095a7fcfe95742c3d5ed1abb318babc5cb5d9350fee4da65ee074f65e1758117e6945f0fcfc8137528053ce9d1da8618890dee24e5e0bf8c87795bb1d09eddd544640824ee0dd0ea9fd908d27b0f8a1ae5c37f3647fbf2f5795500ad76c195b3387d0458a8f51b701472301"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with private key (1024)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 1024");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 1024");
+t2 = new Date().getTime();
+is("Decrypting with public key (1024)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 1024");
+*/
+/*
+ //
+ // 2048
+ //
+ cleanKey = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ publicKey = Clipperz.Crypto.Base.publicKeyWithValues(
+ "10001",
+ "409c6fe2b6474762b5c07f4e55ef80d174814dc1fb0fb58e979691116fb3dc433f759ff8a88d1a0f0666862b0b3758c54b7355fa87ee827369381e1f97c5d74944e032c7186b51a956fb49d6deb3aee0b2c7e65fc53bfd46d217764850667ed0363de143f3f3d06d5a0018693ad3dacdf78a18d037ceeccb7508776f27b30852b8b505666a8dca5bfbb455d2f85918f8b5295061c97673c78802c5f5cf4581c7215dc32af8dfb6fc10e9ba51fb5a88abab94157ccecf615e104a91a45e9bee072fe7b388344c1bbad4a8f7d5daeccbadf778d59eff2a491a067bba5343c5a094c61b575fe367ecfcc01c3d208c2f8c05b9496a929b2b72e70160d07d07f248f1",
+ "9800012b1e533c2c28187424e1289fd4f7fe67487058f5ac7f27f18476c6c93db20b6d2c63d04ff310c1e7211cf8014adc006176529abc53fd1780274fc2629cf51d627c7465c3cbf4f110c3560e2128b97c4ea8a431f0b2a326fc31899790515ad45874ca75c68ee6695558736490ea895d598b8525bccab3156104d360b115ae25e99e9d899a2219136bad0336eeee0c6d725aa9c3b6b923c1ad95a9057b9deb7b563e05614acc800d9d8ec5de405d74feea722c5146feb80829508180ab5c80bf792b83f07c04c73ce0b3cf0d9f74aa92a4704819d103e58f5d4b8ca750148ba1cbab8eb55f92775b18da427c3a0b592809f3853274841a44b7129ec6a623"
+ );
+t1 = new Date().getTime();
+ encryptedString = Clipperz.Crypto.Base.encryptUsingPrivateKey(publicKey, cleanKey);
+t2 = new Date().getTime();
+is("Encrypting with private key (2048)", (t2 - t1));
+
+ is (isUndefinedOrNull(encryptedString), false, "An encrypted string is not empty - PRIVATE 2048");
+t1 = new Date().getTime();
+ is (cleanKey, Clipperz.Crypto.Base.decryptUsingPublicKey(publicKey, encryptedString), "I can encrypt and then decrypt safely - PRIVATE 2048");
+t2 = new Date().getTime();
+is("Decrypting with public key (2048)", (t2 - t1));
+ isnt (cleanKey, Clipperz.Crypto.Base.decryptUsingPrivateKey(publicKey, encryptedString), "I should not be able to decrypt using again th public key - PRIVATE 2048");
+*/
+ }
+
+ var originalMessage;
+ var processedMessage;
+ var expectedResult;
+
+ //-------------------------------------------------------------------------
+ //
+ // Hash SHA-256
+ //
+
+ originalMessage = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+ expectedResult = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "";
+ expectedResult = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "abc";
+ expectedResult = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "message digest";
+ expectedResult = "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "secure hash algorithm";
+ expectedResult = "f30ceb2bb2829e79e4ca9753d35a8ecc00262d164cc077080295381cbd643f0d";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "SHA256 is considered to be safe";
+ expectedResult = "6819d915c73f4d1e77e4e1b52d1fa0f9cf9beaead3939f15874bd988e2a23630";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "For this sample, this 63-byte string will be used as input data";
+ expectedResult = "f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ originalMessage = "This is exactly 64 bytes long, not counting the terminating byte";
+ expectedResult = "ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ 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.";
+ expectedResult = "528059709af4087fb8cd4427e291d89f24d8c0429b2a3b6fd152c32ce5b4680f";
+ processedMessage = Clipperz.Crypto.Base.computeHashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+ //-------------------------------------------------------------------------
+ //
+ // Hash MD5
+ //
+ originalMessage = "59fed719f8959a468de367f77a33a7536d53b8e4d25ed49ccc89a94cd6899da9";
+ expectedResult = "fde790d7da7d0d54a8db4ac500f1bbdb";
+ processedMessage = Clipperz.Crypto.Base.computeMD5HashValue(originalMessage);
+ is(processedMessage, expectedResult, "");
+
+
+
+
+ //-------------------------------------------------------------------------
+ //
+ // Random seed
+ //
+ var randomSeed;
+
+ randomSeed = Clipperz.Crypto.Base.generateRandomSeed();
+ is(randomSeed.length, 64, "");
+
+ ok(randomSeed != Clipperz.Crypto.Base.generateRandomSeed(), "");
+
+//#############################################################################
+
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+ var bigInt_1;
+ var bigInt_2;
+ var result;
+ var expectedResult;
+
+ //
+ // Constructur and equality test
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("110");
+ is (bigInt_1.equals(bigInt_1), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("110");
+ bigInt_2 = new Clipperz.Crypto.BigInt("110", 10);
+ is (bigInt_1.equals(bigInt_2), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("110");
+ bigInt_2 = new Clipperz.Crypto.BigInt(110);
+ is (bigInt_1.equals(bigInt_2), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ bigInt_2 = new Clipperz.Crypto.BigInt("110", 2);
+ is (bigInt_1.equals(bigInt_2), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ bigInt_2 = new Clipperz.Crypto.BigInt("110", 3);
+ is (bigInt_1.equals(bigInt_2), false, "");
+
+
+ //
+ // Addition test
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ bigInt_2 = new Clipperz.Crypto.BigInt(110);
+ result = bigInt_1.add(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt(116);
+ is (result.equals(expectedResult), true, "");
+ is (result.equals(Clipperz.Crypto.BigInt.add(bigInt_1, bigInt_2)), true, "instance method === static function");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ result = bigInt_1.add(6);
+ expectedResult = new Clipperz.Crypto.BigInt(12);
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
+ bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
+ result = bigInt_1.add(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585858585858585858585858585858585");
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
+ bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
+ result = bigInt_1.add(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585851585858585858585858585858585");
+ is (result.equals(expectedResult), false, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("86161616161616161616161616161616161616161616161616161");
+ bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
+ result = bigInt_1.add(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt("128585858585858585858585858585858585858585858585858585");
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt( "6541652165410321654063516540621063540654" +
+ "0654065106540654165416521654103216540635" +
+ "1654062106354065406540651065406541");
+ bigInt_2 = new Clipperz.Crypto.BigInt( "3046540351035403510354035103510351351351" +
+ "0351350435103213540634132135401351035403" +
+ "5403540354103540");
+ result = bigInt_1.add(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt( "6541652165410321657110056891656467051008" +
+ "1005100210054167675767872089206430081269" +
+ "2975416119864419441944191419510081");
+ is (result.equals(expectedResult), true, "");
+
+
+ //
+ // Moltiplication test
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ bigInt_2 = new Clipperz.Crypto.BigInt(110);
+ result = bigInt_1.multiply(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt(660);
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ result = bigInt_1.multiply(5);
+ expectedResult = new Clipperz.Crypto.BigInt(30);
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt( "5465465165465465132743540354354032135463" +
+ "5435135403513516843052413543054035");
+ bigInt_2 = new Clipperz.Crypto.BigInt( "3543513543543213543032135435413054365430" +
+ "5130513540351354354305435403");
+ result = bigInt_1.multiply(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt( "1936694983559052629352223965314822970014" +
+ "6364423657014976098029153153101751605574" +
+ "5077086464435601381095664357540911830059" +
+ "9503335163757031001105");
+ is (result.equals(expectedResult), true, "");
+
+ //
+ // Module test
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt(106);
+ bigInt_2 = new Clipperz.Crypto.BigInt(10);
+ result = bigInt_1.module(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt(6);
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt(106);
+ result = bigInt_1.module(10);
+ expectedResult = new Clipperz.Crypto.BigInt(6);
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt( "5465465465468468465468463541358438543513" +
+ "8543135435135423545624354235123512531235" +
+ "1356463543840351351305135435121354305413" +
+ "543");
+
+
+ bigInt_2 = new Clipperz.Crypto.BigInt( "3543543213543213540543545463542354385768" +
+ "512584354354215");
+ result = bigInt_1.module(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt("52689987206612998786765715819079250963638640081836513");
+ is (result.equals(expectedResult), true, "");
+
+ //
+ // Power (Module) test
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ bigInt_2 = new Clipperz.Crypto.BigInt(3);
+ result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt(1000));
+ expectedResult = new Clipperz.Crypto.BigInt(216);
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt(6);
+ result = bigInt_1.powerModule(3, 1000);
+ expectedResult = new Clipperz.Crypto.BigInt(216);
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("354354354354687638546846846846846576876468746846846846");
+ bigInt_2 = new Clipperz.Crypto.BigInt("354");
+ result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt("3543541354354354354354351354354351354354354354354354"));
+ expectedResult = new Clipperz.Crypto.BigInt("1957028940698171231089373321334263118681605242465644");
+ is (result.equals(expectedResult), true, "");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", 16);
+// is(bigInt_1.toString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "IE bug");
+ is(bigInt_1.asString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "fix for IE bug");
+
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ is(bigInt_1.asString(16, 64), "000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "fix to ensure the string representation has a minimum fixed length");
+
+/*
+ //
+ // Comparison
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("0", 10);
+ bigInt_2 = new Clipperz.Crypto.BigInt("0", 10);
+ is (bigInt_1.equals(bigInt_2), true, "bigInt(0) = bigInt(0)");
+ is (bigInt_1.equals(0), true, "bigInt(0) = 0");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ is (bigInt_1.equals(bigInt_2), false, "bigInt(xxxxxx) != bigInt(0)");
+ is (bigInt_1.equals(0), false, "bigInt(xxxxx) != 0");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("0", 16);
+ is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(0)");
+ is(bigInt_2.compare(bigInt_1), -1, "bigInt(0) < bigInt(xxxx)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
+ is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(05)");
+ is(bigInt_2.compare(bigInt_1), -1, "bigInt(05) < bigInt(xxxx)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("-10", 10);
+ bigInt_2 = new Clipperz.Crypto.BigInt("10", 10);
+ is(bigInt_1.equals(bigInt_2), true, "bigInt(-10) - bigInt(10). No negative number are managed");
+
+ //
+ // XOR
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = bigInt_1.xor(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt(0);
+ is(result.asString(16), expectedResult.asString(16), "a xor a = 0");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
+ result = bigInt_1.xor(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt('295147905179352825856');
+ is(result.asString(16), expectedResult.asString(16), "single bit difference");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("01", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
+ result = bigInt_1.xor(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt('102987336249554097029535212322581322789799900648198034993674544906295017912404');
+ is(result.asString(16), expectedResult.asString(16), "01 xor value");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = bigInt_1.xor(bigInt_2);
+ expectedResult = new Clipperz.Crypto.BigInt('7237005577332262213973186563042994240829374041602535252466099000494570602496');
+ is(result.asString(16), expectedResult.asString(16), "first bit difference xor");
+
+
+ //
+ // isBitSet
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
+ result = bigInt_1.isBitSet(1);
+ expectedResult = true;
+ is(result, expectedResult, "'ff'.isBitSet(1)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
+ result = bigInt_1.isBitSet(1);
+ expectedResult = false;
+ is(result, expectedResult, "'f0'.isBitSet(1)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
+ result = bigInt_1.isBitSet(3);
+ expectedResult = false;
+ is(result, expectedResult, "'f0'.isBitSet(3)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
+ result = bigInt_1.isBitSet(4);
+ expectedResult = true;
+ is(result, expectedResult, "'f0'.isBitSet(4)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
+ result = bigInt_1.isBitSet(7);
+ expectedResult = false;
+ is(result, expectedResult, "'ff00'.isBitSet(7)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
+ result = bigInt_1.isBitSet(8);
+ expectedResult = true;
+ is(result, expectedResult, "'ff00'.isBitSet(8)");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("05000000000000", 16);
+ result = bigInt_1.isBitSet(47);
+ expectedResult = false;
+ is(result, expectedResult, "'05000000000000'.isBitSet(47)");
+
+ result = bigInt_1.isBitSet(48);
+ expectedResult = true;
+ is(result, expectedResult, "'05000000000000'.isBitSet(48)");
+
+ result = bigInt_1.isBitSet(49);
+ expectedResult = false;
+ is(result, expectedResult, "'05000000000000'.isBitSet(49)");
+
+ result = bigInt_1.isBitSet(50);
+ expectedResult = true;
+ is(result, expectedResult, "'05000000000000'.isBitSet(50)");
+
+ result = bigInt_1.isBitSet(51);
+ expectedResult = false;
+ is(result, expectedResult, "'05000000000000'.isBitSet(51)");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+
+ result = bigInt_1.isBitSet(52);
+ expectedResult = true;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)");
+
+ result = bigInt_1.isBitSet(53);
+ expectedResult = false;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)");
+
+ result = bigInt_1.isBitSet(54);
+ expectedResult = false;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)");
+
+ result = bigInt_1.isBitSet(55);
+ expectedResult = true;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)");
+
+ result = bigInt_1.isBitSet(56);
+ expectedResult = false;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)");
+
+ result = bigInt_1.isBitSet(57);
+ expectedResult = false;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)");
+
+ result = bigInt_1.isBitSet(58);
+ expectedResult = true;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)");
+
+ result = bigInt_1.isBitSet(59);
+ expectedResult = false;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)");
+
+ result = bigInt_1.isBitSet(60);
+ expectedResult = false;
+ is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)");
+
+ //
+ // shiftLeft
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("7f", 16);
+ result = bigInt_1.shiftLeft(1);
+ expectedResult = new Clipperz.Crypto.BigInt('fe', 16);
+ is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
+ result = bigInt_1.shiftLeft(1);
+ expectedResult = new Clipperz.Crypto.BigInt('01fe', 16);
+ is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = bigInt_1.shiftLeft(2);
+ expectedResult = new Clipperz.Crypto.BigInt('411949344998216388118140849290325291159199602592792139973517588004462660346196', 10);
+ is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = bigInt_1.shiftLeft(8);
+ expectedResult = new Clipperz.Crypto.BigInt('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16);
+ is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(8)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = bigInt_1.shiftLeft(10);
+ expectedResult = new Clipperz.Crypto.BigInt('105459032319543395358244057418323274536755098263754787833220502529142441048626176', 10);
+ is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
+ result = bigInt_1.shiftLeft(4096);
+ expectedResult = new Clipperz.Crypto.BigInt('266319164760353889206396941232739217557890883507082863997979538237408246532747151496450837043424377376926977212182012023686831226737377369852125202402098145876219029018646049576792205484267848170179157853023266287725961304046416750146445344507869587461686016719979944538177432428730245324189334334817497396705169439104855885416460935698516539852892760625369984672271807592980051379072961966267124963131928067770749329011150668180796667192392027523071601150548205543997146350727148885425131890513407882508735446345822174200042918879518190588482963417582471561436215675823872015307629566605147920139961896995509627341070659007877630760561618021922340198636222738900413041589858099507891702174848695380017286939422770656819923801325579542295611580916900945707539132241939193098989585491346846486694653352501301851631933610655701026861715541355665900384634131852357081890301147104554877895768806174478161952060916705243614916310627428392386264214492834954273769685672081818149530274447979003153864646452529328518204716201193108795473912970645455457215455929896570875795325190705652768977680951535622436287312272907838194995042100153360373621439300266297151905265332115434133380301670205335338558744799343198526203012170200626802804318535680', 10);
+ is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
+
+ bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
+ result = bigInt_1.shiftLeft(5000);
+ expectedResult = new Clipperz.Crypto.BigInt('36017909319555363939297846508911757008556852467205798478749046189356513330989041570231272721076143922520578818149998351104871978707844731275672652360293180474918203352225676748028889909508585302690242044220987556901043359920075229167479636668489487021705618421769517884399224788393498408327257966673365451264730932480701037648195190724361287852846952667257156204462064385766889505990099642052739974651257588866645027017486311782036674195285521311468922365736517586569614071211079825802088151607502649165228246449902253708785396560087430392277977851200155957347440614508171640900912431375050142178348130480158080696562512167652410483775588091117019722112093545783277082149415339867358805673644654236371762589715111732737686904860620316822561292797144756685380676343141118415434643259498221414744450502163805872581378284735047416230112208369784803081434462030568662742790926051825877463257023387907801068796855629691810029349692983890802136654401365294584656484852908751516361546884362396124203127393434938355516740711953765305060269622960662047729516459906444429108776596594293559927265789943280929098971285454533928986078946124455350540187565506016643147748500262510780357259199808936108629893209819473029835119866186316144675107047007737043503194737001430981972314376700993832503282107582239603281145093446879837002884732470988727066207277180181469885503549870618810897831820650576980763622189213611885522245978572420535750015505830146119605502167931087454823309031494727688701857532561113118183883936890880', 10);
+ is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
+
+
+ //
+ // BigInt compare vs ByteArray compare
+ //
+ var bigInt_byteArray_1;
+ var bigInt_byteArray_2;
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bitInt_byteArray_1 = bigInt_1.asByteArray();
+ bitInt_byteArray_2 = bigInt_2.asByteArray();
+
+ result = bigInt_1.compare(bigInt_2);
+ expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
+ is(result, expectedResult, "equal compare");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bitInt_byteArray_1 = bigInt_1.asByteArray();
+ bitInt_byteArray_2 = bigInt_2.asByteArray();
+
+ result = bigInt_1.compare(bigInt_2);
+ expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
+ is(result, expectedResult, "second term with one more bit at the leftmost - compare");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bitInt_byteArray_1 = bigInt_1.asByteArray();
+ bitInt_byteArray_2 = bigInt_2.asByteArray();
+
+ result = bigInt_1.compare(bigInt_2);
+ expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
+ is(result, expectedResult, "first term with one more bit at the leftmost - compare");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bitInt_byteArray_1 = bigInt_1.asByteArray();
+ bitInt_byteArray_2 = bigInt_2.asByteArray();
+
+ result = bigInt_1.compare(bigInt_2);
+ expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
+ is(result, expectedResult, "first term with one more bit in the middle - compare");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427aeffffffffffffffffffffffffffff", 16);
+ bitInt_byteArray_1 = bigInt_1.asByteArray();
+ bitInt_byteArray_2 = bigInt_2.asByteArray();
+
+ result = bigInt_1.compare(bigInt_2);
+ expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
+ is(result, expectedResult, "first term with one more bit in the middle - compare");
+
+ //
+ bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
+ bitInt_byteArray_1 = bigInt_1.asByteArray();
+ bitInt_byteArray_2 = bigInt_2.asByteArray();
+
+ result = bigInt_1.compare(bigInt_2);
+ expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
+ is(result, expectedResult, "equal compare");
+*/
+ //-------------------------------------------------------------------------
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+<!-- - ->
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+<!- - -->
+<!-- -->
+ <script type="text/javascript" src="../../../../js/MochiKit/Base.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Async.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/DOM.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Logging.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Iter.js"></script>
+<!-- -->
+
+<!-- - ->
+ <script type="text/javascript" src="../../../../js/MochiKit/Style.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Signal.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Color.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Position.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Visual.js"></script>
+<!- - -->
+
+
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>-->
+<!--<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>-->
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>-->
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/StandardCurves.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+
+ var deferredResult;
+
+
+ deferredResult = new MochiKit.Async.Deferred();
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 1: " + res); return res;});
+
+ //
+ // ECC.Curve.multiplication
+ //
+ var curve;
+ var f2m;
+ var f2m_improved;
+ var value;
+ var moduledValue;
+ var result;
+ var result_improved;
+ var expectedResul;
+
+ f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
+ f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B283().finiteField();
+
+ curve = Clipperz.Crypto.ECC.StandardCurves.B283();
+
+/** /
+ value = new Clipperz.Crypto.ECC.BinaryField.Value("7b", 16);
+ result = curve.multiply(value, curve.G());
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Point({
+ x: new Clipperz.Crypto.ECC.BinaryField.Value('29705d23a9cda75e43984bdb9a8fd33304682da0f506a69bdbd5f36657e11b41e35fcdd', 16),
+ y: new Clipperz.Crypto.ECC.BinaryField.Value('59157d2ace16563a905361c5206cc0775c3330f4978bddf8aa9916c451cf9951313623b', 16)
+ });
+ is(result.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
+ is(result.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
+/ **/
+
+ value = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
+
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 6: " + res); return res;});
+// deferredResult.addCallback(console.time, 'B283.deferred.multiply - moduled value');
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("2 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 7: " + res); return res;});
+ deferredResult.addMethod(curve, 'deferredMultiply', value, curve.G());
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("3 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 8: " + res); return res;});
+// deferredResult.addBoth(function(res) {console.timeEnd('B283.deferred.multiply - moduled value'); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("4 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 9: " + res); return res;});
+ deferredResult.addCallback(function(res) {
+ var expectedResult;
+
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Point({
+ x: new Clipperz.Crypto.ECC.BinaryField.Value('7cf07c0880d1ae59f567a2ce420e78d1fdfc1249df694a60e5d40d23c6dc631e1501b77', 16),
+ y: new Clipperz.Crypto.ECC.BinaryField.Value('97d1257d5c98cf71cf481bc0a495e0588150ea904526f503cd600f5e971c39700e95f1', 16)
+ });
+
+ is(res.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
+ is(res.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
+ })
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("5 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 10: " + res); return res;});
+ deferredResult.addBoth(function(res) {SimpleTest.finish(); return res;});
+ deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug(res); return res;});
+ deferredResult.callback();
+
+ SimpleTest.waitForExplicitFinish();
+
+ //-------------------------------------------------------------------------
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+ //
+ // ECC.BinaryFiniteField
+ //
+ var f2m;
+ var f2m_improved;
+ var a, a1, b;
+ var result;
+ var result_improved;
+ var expectedResul;
+
+ f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
+ f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B283().finiteField();
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("05c91e41 d9ca17ef 9d8a33c1 a44eba6d 368fde02 1c492077 1a46eb01 a481e5f7 f430749d", 16);
+ b = new Clipperz.Crypto.ECC.BinaryField.Value("07377071 2de7d57b a803f65f 45786c06 876b8066 db75ec47 81c053b0 a0f78e2c a6ab5187", 16);
+
+ //
+ // addition
+ //
+ result = f2m.add(a, b);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.add");
+
+
+ //
+ // negation
+ //
+ result = f2m.negate(a);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.negate");
+
+
+ //
+ // multiplication
+ //
+ result = f2m.multiply(a, b);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2bacb89668741f6d1f7fd7d3df2f045814086adba11d8bb5f12f3f9851e3b66fbe283cb", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.multiply");
+
+
+ //
+ // fast multiplication
+ //
+ result = f2m.fastMultiply(a, b);
+ expectedResult = f2m.multiply(a, b);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
+ b = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
+ result = f2m.fastMultiply(a, b);
+ expectedResult = f2m.multiply(a, b);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.B283.fastMultiply");
+
+ //
+ // square
+ //
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("1111", 16);
+ result = f2m.square(a);
+ expectedResult = f2m.multiply(a, a);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("11111111", 16);
+ result = f2m.square(a);
+ expectedResult = f2m.multiply(a, a);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("5c91e41d9ca17ef9d8a33c1a44eba6d368fde021c4920771a46eb01a481e5f7f430749d", 16);
+ result = f2m.square(a);
+ expectedResult = f2m.multiply(a, a);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
+
+
+ //
+ // inverse
+ //
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("2fe6e30f42dc2943589c59ee136d66bb1e45e64c73ccc309b86b8b104766bdb529b251a", 16);
+ result = f2m.inverse(a);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("3812fc574f3728c60384e141c0e2a808e21adec22dcd407b9e25dd13c6d1bf22defd84a", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.inverse");
+
+
+ //
+ // module
+ //
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ a1 = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ result = f2m.module(a);
+ result_improved = f2m_improved.module(a1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("2bacb89668741f6d1f7fd7d3df2f045814086adba11d8bb5f12f3f9851e3b66fbe283cb", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved)");
+ is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods");
+
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
+ a1 = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
+ result = f2m.module(a);
+ result_improved = f2m_improved.module(a1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("15e2097d116e745ac47480807cb5eb99dad902728aaf5692241063bc70a5b372dbce798", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (2)");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (2)");
+ is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (2)");
+
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ a1 = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ result = f2m.module(a);
+ result_improved = f2m_improved.module(a1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("40f04cec8fe9caedf82adeff7e1aa06dcb9d08e097db8be2ad54b2ddc2e752152395623", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (3)");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (3)");
+ is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (3)");
+
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
+ is(a.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value as expected (4)")
+ a1 = new Clipperz.Crypto.ECC.BinaryField.Value("02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
+ result = f2m.module(a);
+ result_improved = f2m_improved.module(a1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (4)");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (4)");
+ is(result_improved.asString(16), "ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", "ECC.BinaryFinetField.module (static check) (4)");
+ is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (4)");
+
+ is(a.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value preserved by standard method (4)")
+ is(a1.asString(16), "02f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", "ECC.BinaryFiniteField - original value preserved by improved method (4)")
+
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("2f4bf57710a7e0826a80a339e59e34476c343e75452e4bf4355847e6b41e655ecb08f4c418b172d7963c525c26fdc84ac294a348d3907652f0fcbff3e4c8e2238a478e4277489ce", 16);
+ result_improved = f2m_improved.module(a);
+ result = f2m.module(a);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (5)");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFiniteField.module (improved) (5)");
+ is(result_improved.asString(16), "ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", "ECC.BinaryFinetField.module (static check) (5)");
+ is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods (5)");
+
+ //-------------------------------------------------------------------------
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+ //
+ // ECC.BinaryFiniteField
+ //
+ var f2m;
+ var f2m_improved;
+ var a, b;
+ var result;
+ var result_improved;
+ var expectedResul;
+
+ f2m = new Clipperz.Crypto.ECC.BinaryField.FiniteField({modulus:new Clipperz.Crypto.ECC.BinaryField.Value('80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425', 16)})
+ f2m_improved = Clipperz.Crypto.ECC.StandardCurves.B571().finiteField();
+ 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);
+ 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);
+
+ //
+ // addition
+ //
+ result = f2m.add(a, b);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("52e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.add");
+
+
+ //
+ // negation
+ //
+ result = f2m.negate(a);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.negate");
+
+
+ //
+ // multiplication
+ //
+ result = f2m.multiply(a, b);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("4f8e4c0ae7664b284d3b4cb1b3f9568a1ce6e6e96b5381e184fe0822cb3d5c3a3f01ffd0206355d9e5c4853472bb33cf6b2d861d6b48c39d33a360e9a63ad2f7102f92e68a12312", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.multiply");
+
+
+ //
+ // fast multiplication
+ //
+ result = f2m.fastMultiply(a, b);
+ expectedResult = f2m.multiply(a, b);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("52e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d", 16);
+ b = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ result = f2m.fastMultiply(a, b);
+ expectedResult = f2m.multiply(a, b);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.fastMultiply");
+
+ //
+ // square
+ //
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("1111", 16);
+ result = f2m.square(a);
+ expectedResult = f2m.multiply(a, a);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("11111111", 16);
+ result = f2m.square(a);
+ expectedResult = f2m.multiply(a, a);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ result = f2m.square(a);
+ expectedResult = f2m.multiply(a, a);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.square");
+
+
+ //
+ // inverse
+ //
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ result = f2m.inverse(a);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1f898c60983c4e807e619b9cbe528585fc33aaae419d5e5cb2107269ccdcf21d5ad5b5d78d37fa435a0d0a8a75f2506240c325c6a2eee1a03008f9e1b9c6c0a511b730cdaf9b97e", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.inverse");
+
+
+ //
+ // module
+ //
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ a1 = new Clipperz.Crypto.ECC.BinaryField.Value("015655ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f060a0aa6c29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ result = f2m.module(a);
+ result_improved = f2m_improved.module(a1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("4f8e4c0ae7664b284d3b4cb1b3f9568a1ce6e6e96b5381e184fe0822cb3d5c3a3f01ffd0206355d9e5c4853472bb33cf6b2d861d6b48c39d33a360e9a63ad2f7102f92e68a12312", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved)");
+// is(result.asString(16), result_improved.asString(16), "standard vs improved 'module' methods");
+
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
+ a1 = new Clipperz.Crypto.ECC.BinaryField.Value("1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
+ result = f2m.module(a);
+ result_improved = f2m_improved.module(a1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("1704018ce75dc462a5ccd1eb18b8002ecb8536c616ec625f440f6888f8c32387e53a5cb3b6050688e9b64a32215a385ee98c518d6a484d5ac0ceeafa825743c84b075bdfabc341b", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (2)");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved) (2)");
+ is(a.asString(16), "1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", "ECC.BinaryFinetField.module (2)");
+ is(a1.asString(16), "1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", "ECC.BinaryFinetField.module (2)");
+
+
+ a = new Clipperz.Crypto.ECC.BinaryField.Value("112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a1401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ result = f2m.module(a);
+ result_improved = f2m_improved.module(a);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("e160dd4a436e63877e1343d06576beaa66e06863ffe4335be38d6a37460a62d11133584a5bc6ac0590e18942e1fa88bb64a4d9fc6c1fd7b55d7e57b50b70a9e7cb2ed904ad77f4", 16);
+ is(result.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (2)");
+ is(result_improved.asString(16), expectedResult.asString(16), "ECC.BinaryFinetField.module (improved) (2)");
+
+ //-------------------------------------------------------------------------
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC.js'></script>-->
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+ var value_1;
+ var value_2;
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("a", 16);
+ is(value_1.asString(16), "0a");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffff", 16);
+ is(value_1.asString(16), "ffff");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("7fff", 16);
+ is(value_1.asString(16), "7fff");
+
+ is(parseInt("ffff", 16), 65535);
+ is(parseInt("ffffff", 16), 16777215);
+ is(parseInt("ffffffff", 16), 4294967295);
+ is(parseInt("ffffffffff", 16), 1099511627775);
+ is(parseInt("ffffffffffff", 16), 281474976710655);
+ is(parseInt("ffffffffffffff", 16), 72057594037927940);
+ is(parseInt("ffffffffffffffff", 16), 18446744073709552000);
+ is(parseInt("10000000000000000", 16), 18446744073709552001);
+ is(parseInt("10000000000000001", 16), 18446744073709552002);
+ is(parseInt("10000000000000009", 16), 18446744073709552010);
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ is(value_1.wordSize(), 8, "check the number of words of a 64 char hex string using the 'wordSize' method");
+
+// 000108cb bacda1f0 3ea93603 01045434 ec7d82ba 150936df 08a229cb b4832ce1
+ is(value_1.value()[0], parseInt("b4832ce1", 16), "word[0]");
+ is(value_1.value()[1], parseInt("08a229cb", 16), "word[1]");
+ is(value_1.value()[2], parseInt("150936df", 16), "word[2]");
+ is(value_1.value()[3], parseInt("ec7d82ba", 16), "word[3]");
+ is(value_1.value()[4], parseInt("01045434", 16), "word[4]");
+ is(value_1.value()[5], parseInt("3ea93603", 16), "word[5]");
+ is(value_1.value()[6], parseInt("bacda1f0", 16), "word[6]");
+ is(value_1.value()[7], parseInt("000108cb", 16), "word[7]");
+
+ is(value_1.asString(16), "0108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "asString(16)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('10 00000000 00000000', 16);
+ 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");
+ is(value_1.value()[0], parseInt("00000000", 16), "word[0]");
+ is(value_1.value()[1], parseInt("00000000", 16), "word[1]");
+ is(value_1.value()[2], parseInt("10", 16), "word[2]");
+ is(value_1.asString(16), "100000000000000000", "2^17 asString(16)");
+
+ //
+ // XOR
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
+ result = value_1.xor(value_2);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16);
+ is(result.asString(16), expectedResult.asString(16), "a xor a = 0");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855', 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b935c a495991b 7852b855', 16);
+ result = value_1.xor(value_2);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('10 00000000 00000000', 16);
+ is(result.asString(16), expectedResult.asString(16), "single bit difference");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("01", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855', 16);
+ result = value_1.xor(value_2);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b854', 16);
+ is(result.asString(16), expectedResult.asString(16), "01 xor value");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 16);
+ result = value_1.xor(value_2);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('1000000000000000000000000000000000000000000000000000000000000000', 16);
+ is(result.asString(16), expectedResult.asString(16), "first bit difference xor");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('84a2c58a', 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value('38925faf', 16);
+ result = value_1.xor(value_2);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('bc309a25', 16);
+ is(result.asString(16), expectedResult.asString(16), "84a2c58a XOR 38925faf = bc309a25");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("01401ca87b8f144684a2c58ae9308c237789e4bf1f36dd117c150b7d6076dd1da6197fe4c5225a064db0e4222589d5ca50eb6bb6b7147a03f61528438a8767c6a6c4a6883fd6f067", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0112f5c97e74737b38925fafe22cea3e12b868d4ddea5b3341db8fc2e788cab74f0a7a3cc27087a89365945369938650a99217d566e13f80dc87f08273f7411b6b01ef1d399c772a", 16);
+ result = value_1.xor(value_2);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('0052e96105fb673dbc309a250b1c661d65318c6bc2dc86223dce84bf87fe17aae91305d80752ddaeded570714c1a539af9797c63d1f545832a92d8c1f97026ddcdc54995064a874d', 16);
+ is(result.asString(16), expectedResult.asString(16), "xor");
+
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("01ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f816429a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ result = value_2.xor(value_1.shiftLeft(value_2.bitSize() - value_1.bitSize()));
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f892e29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ is(result.asString(16), expectedResult.asString(16), "xor");
+ is(result.bitSize(), 1120, "xor.bitSize");
+ is(result.wordSize(), 35, "result wordSize");
+ is(expectedResult.bitSize(), 1120, "xor.bitSize");
+ is(expectedResult.wordSize(), 35, "expectedResult wordSize");
+ is(result.compare(expectedResult), 0, "compare");
+
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("ebcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f892e29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ result = value_2.xor(value_1.shiftLeft(value_2.bitSize() - value_1.bitSize()));
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ is(result.asString(16), expectedResult.asString(16), "xor");
+ is(result.bitSize(), 1119, "xor.bitSize");
+ is(expectedResult.bitSize(), 1119, "xor.bitSize");
+ is(result.compare(expectedResult), 0, "compare");
+// value_1 =
+// value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", 16);
+
+
+ value_1 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010 01010101 00000000", 16)).value();
+ value_2 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010", 16)).value();
+ result = new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(value_1, value_2, 2));
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("01010101 00000000", 16);
+ is(result.asString(16), expectedResult.asString(16), "xor with offset 2");
+
+ value_1 = (new Clipperz.Crypto.ECC.BinaryField.Value(" 10101010 01010101 00000000", 16)).value();
+ value_2 = (new Clipperz.Crypto.ECC.BinaryField.Value("10101010 10101010", 16)).value();
+ result = new Clipperz.Crypto.ECC.BinaryField.Value(Clipperz.Crypto.ECC.BinaryField.Value._xor(value_1, value_2, 2));
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value("10101010 00000000 01010101 00000000", 16);
+ is(result.asString(16), expectedResult.asString(16), "xor with offset 2 (2)");
+
+ //
+ // isZero
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('0', 16);
+ is(value_1.isZero(), true, "0.isZero() == true");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('1', 16);
+ is(value_1.isZero(), false, "1.isZero() == false");
+
+ //
+ // Comparison
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
+ is (value_1.compare(value_2), 0, "BinaryField.value(0) = BinaryField.value(0)");
+// is (value_1.compare(0), 0, "BinaryField.value(0) = 0");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ is (value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) != BinaryField.value(0)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
+ is(value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) > BinaryField.value(0)");
+ is(value_2.compare(value_1), -1, "BinaryField.value(0) < BinaryField.value(xxxx)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("05", 16);
+ is(value_1.compare(value_2), 1, "BinaryField.value(xxxxxx) > BinaryField.value(05)");
+ is(value_2.compare(value_1), -1, "BinaryField.value(05) < BinaryField.value(xxxx)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("-10", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("10", 16);
+ is(value_1.compare(value_2), -1, "BinaryField.value(-10) - BinaryField.value(10). No negative number are managed");
+
+ //
+ // more comparison
+ //
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = value_1.compare(value_2);
+ is(result, 0, "equal compare");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442", 16);
+ result = value_1.compare(value_2);
+ is(result, -1, "second term with one more bit at the leftmost - compare (1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14", 16);
+ result = value_1.compare(value_2);
+ is(result, -1, "second term with one more bit at the leftmost - compare (2)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8", 16);
+ result = value_1.compare(value_2);
+ is(result, -1, "second term with one more bit at the leftmost - compare (3)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
+ result = value_1.compare(value_2);
+ is(result, -1, "second term with one more bit at the leftmost - compare (n)");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442", 16);
+ result = value_1.compare(value_2);
+ is(result, 1, "first term with one more bit at the leftmost - compare (1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14", 16);
+ result = value_1.compare(value_2);
+ is(result, 1, "first term with one more bit at the leftmost - compare (2)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
+ result = value_1.compare(value_2);
+ is(result, 1, "first term with one more bit at the leftmost - compare (n)");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = value_1.compare(value_2);
+ is(result, 1, "first term with one more bit in the middle - compare");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427aeffffffffffffffffffffffffffff", 16);
+ result = value_1.compare(value_2);
+ is(result, 1, "first term with one more bit in the middle - compare");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ value_2 = new Clipperz.Crypto.ECC.BinaryField.Value("05", 16);
+ result = value_1.compare(value_2);
+ is(result, 1, "equal compare");
+
+
+
+ //
+ // isBitSet
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
+ result = value_1.isBitSet(1);
+ expectedResult = true;
+ is(result, expectedResult, "'ff'.isBitSet(1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
+ result =value_1.isBitSet(1);
+ expectedResult = false;
+ is(result, expectedResult, "'f0'.isBitSet(1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
+ result = value_1.isBitSet(3);
+ expectedResult = false;
+ is(result, expectedResult, "'f0'.isBitSet(3)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("f0", 16);
+ result = value_1.isBitSet(4);
+ expectedResult = true;
+ is(result, expectedResult, "'f0'.isBitSet(4)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff00", 16);
+ result = value_1.isBitSet(7);
+ expectedResult = false;
+ is(result, expectedResult, "'ff00'.isBitSet(7)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff00", 16);
+ result = value_1.isBitSet(8);
+ expectedResult = true;
+ is(result, expectedResult, "'ff00'.isBitSet(8)");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("05000000000000", 16);
+ result = value_1.isBitSet(47);
+ expectedResult = false;
+ is(result, expectedResult, "'05000000000000'.isBitSet(47)");
+
+ result = value_1.isBitSet(48);
+ expectedResult = true;
+ is(result, expectedResult, "'05000000000000'.isBitSet(48)");
+
+ result = value_1.isBitSet(49);
+ expectedResult = false;
+ is(result, expectedResult, "'05000000000000'.isBitSet(49)");
+
+ result = value_1.isBitSet(50);
+ expectedResult = true;
+ is(result, expectedResult, "'05000000000000'.isBitSet(50)");
+
+ result = value_1.isBitSet(51);
+ expectedResult = false;
+ is(result, expectedResult, "'05000000000000'.isBitSet(51)");
+
+ //
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+
+ result = value_1.isBitSet(52);
+ is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)");
+
+ result = value_1.isBitSet(53);
+ is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)");
+
+ result = value_1.isBitSet(54);
+ is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)");
+
+ result = value_1.isBitSet(55);
+ is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)");
+
+ result = value_1.isBitSet(56);
+ is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)");
+
+ result = value_1.isBitSet(57);
+ is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)");
+
+ result = value_1.isBitSet(58);
+ is(result, true, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)");
+
+ result = value_1.isBitSet(59);
+ is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)");
+
+ result = value_1.isBitSet(60);
+ is(result, false, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)");
+
+
+ //
+ // shiftLeft
+ //
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("7f", 16);
+ result = value_1.shiftLeft(1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('fe', 16);
+ is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
+ result = value_1.shiftLeft(1);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('01fe', 16);
+ is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( 'ffff', 16);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ffff00', 16);
+ result = value_1.shiftLeft(8);
+ is(result.asString(16), expectedResult.asString(16), "ffff.shiftLeft(8)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( '80000000', 16);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('1 00000000', 16);
+ result = value_1.shiftLeft(1);
+ is(result.compare(expectedResult) == 0, true, '8000000.shiftLeft(1).compare');
+ is(result.asString(16), expectedResult.asString(16), "80000000.shiftLeft(1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('20000000', 16);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('40000000', 16);
+ result = value_1.shiftLeft(1);
+ is(result.compare(expectedResult) == 0, true, '2000000.shiftLeft(1).compare');
+ is(result.asString(16), expectedResult.asString(16), "20000000.shiftLeft(1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value('40000000', 16);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('80000000', 16);
+ result = value_1.shiftLeft(1);
+ is(result.compare(expectedResult) == 0, true, '4000000.shiftLeft(1).compare');
+ is(result.asString(16), expectedResult.asString(16), "40000000.shiftLeft(1)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( 'ff7fffff', 16);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff 7fffff00', 16);
+ result = value_1.shiftLeft(8);
+ is(result.asString(16), expectedResult.asString(16), "ff7fffff.shiftLeft(8)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( 'ffffffff', 16);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff ffffff00', 16);
+ result = value_1.shiftLeft(8);
+ is(result.asString(16), expectedResult.asString(16), "ffffffff.shiftLeft(8)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value( "e3b0c442 98fc1c14 9afbf4c8 996fb924 27ae41e4 649b934c a495991b 7852b855", 16);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('3 8ec3110a 63f07052 6befd322 65bee490 9eb90791 926e4d32 9256646d e14ae154', 16);
+ result = value_1.shiftLeft(2);
+ is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(10)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = value_1.shiftLeft(8);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16);
+ is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(8)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
+ result = value_1.shiftLeft(10);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('38e c3110a63 f070526b efd32265 bee4909e b9079192 6e4d3292 56646de1 4ae15400', 16);
+ is(result.asString(16), expectedResult.asString(16), "Value.shiftLeft(10)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
+ result = value_1.shiftLeft(32);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff00000000', 16);
+ is(result.asString(16), expectedResult.asString(16), "ff.shiftLeft(32)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
+ result = value_1.shiftLeft(4096);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 16);
+ is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
+ result = value_1.shiftLeft(5000);
+ expectedResult = new Clipperz.Crypto.ECC.BinaryField.Value('ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 16);
+ is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("0", 16);
+ is(value_1.bitSize(), 0, "0.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("10", 16);
+ is(value_1.bitSize(), 5, "10.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("80", 16);
+ is(value_1.bitSize(), 8, "80.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ff", 16);
+ is(value_1.bitSize(), 8, "ff.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("100", 16);
+ is(value_1.bitSize(), 9, "100.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("80000000", 16);
+ is(value_1.bitSize(), 32, "80000000.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffffffff", 16);
+ is(value_1.bitSize(), 32, "ffffffff.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("1 00000000", 16);
+ is(value_1.bitSize(), 33, "100000000.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("8000 00000000", 16);
+ is(value_1.bitSize(), 48, "8000 00000000.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("ffff ffffffff", 16);
+ is(value_1.bitSize(), 48, "ffff ffffffff.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("10000 00000000", 16);
+ is(value_1.bitSize(), 49, "10000 00000000.bitSize()");
+
+ value_1 = new Clipperz.Crypto.ECC.BinaryField.Value("6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16", 16);
+ is(value_1.bitSize(), 1119, "6bcb09fac51945162a0775f42df6151169826efdc55dea5d17c22adb92e6b1a6ae8311545ad7e0f46f09a5b960855e673db1e803a5b94562161213204ca1f24792e81f06a4f8d0b29a492f106cc6d0b0ff4617b736dab590590a8cff9f807a15282544404e6b35841703c9fb00a9cad1d6878d601efc25368bdc51d5ff14a81610f4fe62cb2f452aee520a16.bitSize()");
+
+ //-------------------------------------------------------------------------
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+<!-- - ->
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+<!- - -->
+<!-- -->
+ <script type="text/javascript" src="../../../../js/MochiKit/Base.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Async.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/DOM.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Logging.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Iter.js"></script>
+<!-- -->
+
+<!-- - ->
+ <script type="text/javascript" src="../../../../js/MochiKit/Style.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Signal.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Color.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Position.js"></script>
+ <script type="text/javascript" src="../../../../js/MochiKit/Visual.js"></script>
+<!- - -->
+
+
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>-->
+<!--<script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>-->
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>-->
+
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Value.js'></script>-->
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Point.js'></script>-->
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/FiniteField.js'></script>-->
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/BinaryField/Curve.js'></script>-->
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Value.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Point.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/FiniteField.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/Koblitz/Curve.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/ECC/StandardCurves.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+
+ var deferredResult;
+
+
+ deferredResult = new MochiKit.Async.Deferred();
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 1: " + res); return res;});
+
+ //
+ // ECC.Curve.multiplication
+ //
+ var curve;
+ var f2m;
+ var f2m_improved;
+ var value;
+ var moduledValue;
+ var result;
+ var result_improved;
+ var expectedResul;
+
+ f2m = new Clipperz.Crypto.ECC.Koblitz.FiniteField({modulus:new Clipperz.Crypto.ECC.Koblitz.Value('08000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000010a1', 16)})
+ f2m_improved = Clipperz.Crypto.ECC.StandardCurves.K283().finiteField();
+
+ curve = Clipperz.Crypto.ECC.StandardCurves.K283();
+
+/** /
+ value = new Clipperz.Crypto.ECC.Koblitz.Value("7b", 16);
+ result = curve.multiply(value, curve.G());
+ expectedResult = new Clipperz.Crypto.ECC.Koblitz.Point({
+ x: new Clipperz.Crypto.ECC.Koblitz.Value('29705d23a9cda75e43984bdb9a8fd33304682da0f506a69bdbd5f36657e11b41e35fcdd', 16),
+ y: new Clipperz.Crypto.ECC.Koblitz.Value('59157d2ace16563a905361c5206cc0775c3330f4978bddf8aa9916c451cf9951313623b', 16)
+ });
+ is(result.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
+ is(result.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
+/ **/
+
+ value = new Clipperz.Crypto.ECC.Koblitz.Value("ba35032a24eb81238251d85824998bebae3b3e09f4d3845256c87585cf62416ee43191", 16);
+
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 6: " + res); return res;});
+// deferredResult.addCallback(console.time, 'K283.deferred.multiply - moduled value');
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("2 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 7: " + res); return res;});
+ deferredResult.addMethod(curve, 'deferredMultiply', value, curve.G());
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("3 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 8: " + res); return res;});
+// deferredResult.addBoth(function(res) {console.timeEnd('K283.deferred.multiply - moduled value'); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("4 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 9: " + res); return res;});
+ deferredResult.addCallback(function(res) {
+ var expectedResult;
+
+ expectedResult = new Clipperz.Crypto.ECC.Koblitz.Point({
+ x: new Clipperz.Crypto.ECC.Koblitz.Value('7cf07c0880d1ae59f567a2ce420e78d1fdfc1249df694a60e5d40d23c6dc631e1501b77', 16),
+ y: new Clipperz.Crypto.ECC.Koblitz.Value('97d1257d5c98cf71cf481bc0a495e0588150ea904526f503cd600f5e971c39700e95f1', 16)
+ });
+
+ is(res.x().asString(16), expectedResult.x().asString(16), "ECC.Curve.multiplication: result.x does match");
+ is(res.y().asString(16), expectedResult.y().asString(16), "ECC.Curve.multiplication: result.y does match");
+ })
+//deferredResult.addBoth(function(res) {MochiKit.Base.logDebug("5 - " + res); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 10: " + res); return res;});
+ deferredResult.addBoth(function(res) {SimpleTest.finish(); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("** 11: " + res); return res;});
+ deferredResult.callback();
+
+ SimpleTest.waitForExplicitFinish();
+
+ //-------------------------------------------------------------------------
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.Crypto.JSCrypto_vs_Clipperz - tests</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/PM/Crypto.js'></script>
+
+ <script type='text/javascript' src='./jscrypto.js'></script>
+
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script>
+
+</head>
+<body>
+
+<pre id="test">
+ <script type="text/javascript">
+ 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.";
+ var longIsoLatin1Text = "¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¡¢£¤¥¦§¨©ª«¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùù";
+ var longUtf8Text = "客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之所以能统称为汉语第客家方言简体字危及了对古代文学的研究共有找华语并不被中国政府很好的接受然而汉语之";
+ </script>
+ <script type="text/javascript" src="JSCrypto_vs_Clipperz.test.js"></script>
+</pre>
+</body>
+</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 @@
+/*
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+*/
+
+//function logElapsedTime(aDescription, aStartTime, anEndTime) {
+// MochiKit.Logging.logDebug(aDescription + " - took " + (anEndTime - aStartTime) + "ms");
+// SimpleTest.ok(true, aDescription + " - took " + (anEndTime - aStartTime) + "ms");
+//}
+
+var asciiTestString = longAsciiText;
+//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
+//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
+//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
+//asciiTestString = asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString + asciiTestString;
+//asciiTestString = asciiTestString + asciiTestString;
+//asciiTestString = asciiTestString + asciiTestString;
+
+var isoLatin1TestString = longIsoLatin1Text;
+//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
+//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
+//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString + isoLatin1TestString;
+//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString;
+//isoLatin1TestString = isoLatin1TestString + isoLatin1TestString;
+
+var utf8TestString = longUtf8Text;
+//utf8TestString = utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString;
+//utf8TestString = utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString + utf8TestString;
+//utf8TestString = utf8TestString + utf8TestString;
+//utf8TestString = utf8TestString + utf8TestString;
+
+var times = {
+ 'Clipperz': {},
+ 'JSCrypto': {}
+};
+
+function appendResults (aDescription, aTimer) {
+ MochiKit.DOM.appendChildNodes(MochiKit.DOM.getElement('timerTBODY'),
+ MochiKit.DOM.TR(null,
+ MochiKit.DOM.TH({align:'left'}, aDescription),
+ MochiKit.DOM.TH(null, aTimer['ascii']['encrypt'] + ' - ' + aTimer['ascii']['decrypt'])//,
+// MochiKit.DOM.TH(null, aTimer['isoLatin1']['encrypt'] + ' - ' + aTimer['isoLatin1']['decrypt']),
+// MochiKit.DOM.TH(null, aTimer['utf8']['encrypt'] + ' - ' + aTimer['utf8']['decrypt'])
+ )
+ );
+
+}
+
+//=============================================================================
+
+function timeRegularFunction (aDescription, aString, anEncryptFunction, aDecryptFunction, aTimer, aKey) {
+ var start;
+ var end;
+ var encryptTime;
+ var decryptTime;
+ var ciphertext;
+ var plaintext;
+
+
+ start = new Date();
+ ciphertext = anEncryptFunction('trustno1', aString);
+ end = new Date();
+ encryptTime = end - start;
+
+ start = new Date();
+ plaintext = aDecryptFunction('trustno1', ciphertext);
+ end = new Date();
+ decryptTime = end - start;
+ aTimer[aKey] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
+ SimpleTest.is(aString, plaintext, aDescription);
+}
+/*
+function timeRegularFunction (anEncryptFunction, aDecryptFunction, aTimer) {
+ var start;
+ var end;
+ var encryptTime;
+ var decryptTime;
+ var ciphertext;
+ var plaintext;
+
+
+ start = new Date();
+ ciphertext = anEncryptFunction('trustno1', asciiTestString);
+ end = new Date();
+ encryptTime = end - start;
+
+ start = new Date();
+ plaintext = aDecryptFunction('trustno1', ciphertext);
+ end = new Date();
+ decryptTime = end - start;
+ aTimer['ascii'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
+ SimpleTest.is(asciiTestString, plaintext, "Encrypt/decrypt the ASCII text");
+
+
+ start = new Date();
+ ciphertext = anEncryptFunction('trustno1', isoLatin1TestString);
+ end = new Date();
+ encryptTime = end - start;
+
+ start = new Date();
+ plaintext = aDecryptFunction('trustno1', ciphertext);
+ end = new Date();
+ decryptTime = end - start;
+ aTimer['isoLatin1'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
+ SimpleTest.is(isoLatin1TestString, plaintext, "Encrypt/decrypt the ISO-Latin 1 text");
+
+
+ start = new Date();
+ ciphertext = anEncryptFunction('trustno1', utf8TestString);
+ end = new Date();
+ encryptTime = end - start;
+
+ start = new Date();
+ plaintext = aDecryptFunction('trustno1', ciphertext);
+ end = new Date();
+ decryptTime = end - start;
+ aTimer['utf8'] = { 'encrypt': encryptTime, 'decrypt': decryptTime };
+ SimpleTest.is(utf8TestString, plaintext, "Encrypt/decrypt the UTF-8 text");
+}
+*/
+function timeDeferredFunction (aDescription, aString, anEncryptFunction, aDecryptFunction, aTimer, aKey, someTestArgs) {
+ var start;
+ var end;
+
+ var deferredResult;
+
+ aTimer[aKey] = {};
+
+ deferredResult = new Clipperz.Async.Deferred("timeDeferredFunction", someTestArgs);
+ deferredResult.addCallback(function (aValue) { start = new Date(); return aValue});
+ deferredResult.addCallback(anEncryptFunction, 'trustno1', aString);
+ deferredResult.addCallback(function (aValue) {
+ end = new Date();
+ aTimer[aKey]['encrypt'] = end-start;
+ return aValue;
+ });
+ deferredResult.addCallback(function (aValue) { start = new Date(); return aValue});
+ deferredResult.addCallback(aDecryptFunction, 'trustno1');
+ deferredResult.addCallback(function (aValue) {
+ end = new Date();
+ aTimer[aKey]['decrypt'] = end-start;
+ return aValue;
+ });
+ deferredResult.addCallback(function (aValue) {
+ SimpleTest.is(aString, aValue, aDescription);
+ });
+
+ deferredResult.callback();
+
+ return deferredResult;
+}
+
+//=============================================================================
+
+function encryptUsingJSCrypto (aKey, aValue) {
+ var salt;
+ var key;
+ var cipher;
+ var iv;
+ var plaintext;
+ var ciphertext;
+ var tag;
+ var adata;
+
+ salt = [1,2,3,4,5,6,7,8];
+ key = generateKey(aKey, salt);
+
+ cipher = new aes(key, CCM);
+ iv = Random.random_words(4);
+
+ plaintext = aValue;
+ ciphertext = [];
+ tag = [];
+ adata = "";
+
+ cipher.encrypt(iv, plaintext, ciphertext, adata, tag);
+
+ return ciphertext;
+}
+
+//-----------------------------------------------------------------------------
+
+function decryptUsingJSCrypto (aKey, aValue) {
+ var salt;
+ var key;
+ var cipher;
+ var ciphertext;
+ var plaintext;
+ var tag;
+ var adata;
+
+ salt = [1,2,3,4,5,6,7,8];
+ key = generateKey(aKey, salt);
+ tag = [];
+ adata = "";
+
+ cipher = new aes(key, CCM);
+ ciphertext = aValue;
+ plaintext = cipher.decrypt(ciphertext, adata, tag);
+
+ return plaintext;
+}
+
+//=============================================================================
+
+function encryptUsingClipperz (aKey, aValue) {
+ var key;
+ var value;
+ var data;
+ var encryptedData;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = aValue;
+ data = new Clipperz.ByteArray(value);
+ encryptedData = Clipperz.Crypto.AES.encrypt(key, data);
+ return encryptedData.toBase64String();
+}
+
+//-----------------------------------------------------------------------------
+
+function decryptUsingClipperz (aKey, aValue) {
+ var key;
+ var value;
+ var decryptedData;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = new Clipperz.ByteArray().appendBase64String(aValue);
+
+ decryptedData = Clipperz.Crypto.AES.decrypt(key, value).asString();
+
+ return decryptedData;
+}
+
+//=============================================================================
+
+function encryptUsingClipperzAndJSON (aKey, aValue) {
+ var key;
+ var value;
+ var data;
+ var encryptedData;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = Clipperz.Base.serializeJSON(aValue);
+ data = new Clipperz.ByteArray(value);
+ encryptedData = Clipperz.Crypto.AES.encrypt(key, data);
+ return encryptedData.toBase64String();
+}
+
+//-----------------------------------------------------------------------------
+
+function decryptUsingClipperzAndJSON (aKey, aValue) {
+ var key;
+ var value;
+ var decryptedData;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = new Clipperz.ByteArray().appendBase64String(aValue);
+
+ decryptedData = Clipperz.Crypto.AES.decrypt(key, value).asString();
+
+ return Clipperz.Base.evalJSON(decryptedData);
+}
+
+//=============================================================================
+
+function deferredEncryptUsingClipperz (aKey, aValue) {
+ var deferredResult;
+ var key;
+ var data;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ data = new Clipperz.ByteArray(aValue);
+
+ deferredResult = new Clipperz.Async.Deferred("Clipperz.deferredEncrypt", {trace:false});
+ deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, data);
+ deferredResult.addCallback(function(aResult) {
+ return aResult.toBase64String();
+ })
+ deferredResult.callback();
+
+ return deferredResult;
+}
+
+//-----------------------------------------------------------------------------
+
+function deferredDecryptUsingClipperz (aKey, aValue) {
+ var key, value;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = new Clipperz.ByteArray().appendBase64String(aValue);
+
+ deferredResult = new Clipperz.Async.Deferred("Clipperz.deferredDecrypt", {trace:false});
+ deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value);
+ deferredResult.addCallback(function(aResult) {
+ return aResult.asString();
+ });
+ deferredResult.callback();
+
+ return deferredResult;
+}
+
+//=============================================================================
+
+var tests = {
+
+ //-------------------------------------------------------------------------
+
+ 'encryptMultipleStringsUsingClipperzFunctions': function (someTestArgs) {
+// timeRegularFunction(encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['Regular']);
+ times['Clipperz']['NO JSON'] = {};
+
+ timeRegularFunction("Clipperz - NO JSON - Ascii", asciiTestString, encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'ascii');
+ timeRegularFunction("Clipperz - NO JSON - ISO Latin 1", isoLatin1TestString, encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'isoLatin1');
+ timeRegularFunction("Clipperz - NO JSON - UTF-8", utf8TestString, encryptUsingClipperz, decryptUsingClipperz, times['Clipperz']['NO JSON'], 'utf8');
+
+ appendResults("Clipperz - NO JSON", times['Clipperz']['NO JSON']);
+ },
+
+ //-------------------------------------------------------------------------
+
+ 'encryptMultipleStringsUsingClipperzAndJSONFunctions': function (someTestArgs) {
+// timeRegularFunction(encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON']);
+ times['Clipperz']['JSON'] = {};
+
+ timeRegularFunction("Clipperz - JSON - Ascii", asciiTestString, encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'ascii');
+ timeRegularFunction("Clipperz - JSON - ISO Latin 1", isoLatin1TestString, encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'isoLatin1');
+ timeRegularFunction("Clipperz - JSON - UTF-8", utf8TestString, encryptUsingClipperzAndJSON, decryptUsingClipperzAndJSON, times['Clipperz']['JSON'], 'utf8');
+
+ appendResults("Clipperz - JSON", times['Clipperz']['JSON']);
+ },
+
+ //-------------------------------------------------------------------------
+
+ 'encryptMultipleStringsUsingClipperzDeferredFunctions': function (someTestArgs) {
+ times['Clipperz']['Deferred'] = {};
+ times['Clipperz']['Deferred [NO JSON]'] = {};
+
+ return Clipperz.Async.callbacks("encryptMultipleStringsUsingClipperzDeferredFunctions", [
+ MochiKit.Base.partial(timeDeferredFunction, "Deferred Ascii", asciiTestString, deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'ascii', someTestArgs),
+// MochiKit.Base.partial(timeDeferredFunction, "Deferred IsoLatin1", isoLatin1TestString, deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'isoLatin1', someTestArgs),
+// MochiKit.Base.partial(timeDeferredFunction, "Deferred UTF-8", utf8TestString, deferredEncryptUsingClipperz, deferredDecryptUsingClipperz, times['Clipperz']['Deferred [NO JSON]'], 'utf8', someTestArgs),
+
+ MochiKit.Base.partial(appendResults, "Clipperz - deferred [NO JSON]", times['Clipperz']['Deferred [NO JSON]']),
+
+ 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),
+// 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),
+// 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),
+
+ MochiKit.Base.partial(appendResults, "Clipperz - PM", times['Clipperz']['Deferred'])
+ ], someTestArgs);
+ },
+
+ //-------------------------------------------------------------------------
+
+ 'encryptMultipleStringsUsingJSCryptoFunctions': function (someTestArgs) {
+ timeRegularFunction("JSCrypto - Ascii", asciiTestString, encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'ascii');
+ timeRegularFunction("JSCrypto - ISO Latin 1", isoLatin1TestString, encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'isoLatin1');
+ timeRegularFunction("JSCrypto - UTF-8", utf8TestString, encryptUsingJSCrypto, decryptUsingJSCrypto, times['JSCrypto'], 'utf8');
+
+ appendResults("JSCrypto", times['JSCrypto']);
+ },
+
+ //-------------------------------------------------------------------------
+ 'syntaxFix': MochiKit.Base.noop
+};
+
+//#############################################################################
+
+SimpleTest.waitForExplicitFinish();
+Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
+Random.set_default_paranoia(0);
+
+//Random.addEventListener("seeded", MochiKit.Base.partial(SimpleTest.runDeferredTests, "Clipperz.Crypto.JSCrypto_vs_Clipperz", tests, {trace:false}));
+//Random.addEventListener("seeded", function () { console.log("SEEDED!")});
+
+
+MochiKit.DOM.appendChildNodes(MochiKit.DOM.currentDocument().body,
+ MochiKit.DOM.TABLE({border:'1', cellpadding:'4', cellspacing:'0'},
+ MochiKit.DOM.THEAD(),
+ MochiKit.DOM.TBODY({id:'timerTBODY'},
+ MochiKit.DOM.TR(null,
+ MochiKit.DOM.TH(null, "algorithm"),
+ MochiKit.DOM.TH(null, "ascii [" + asciiTestString.length + "]"),
+ MochiKit.DOM.TH(null, "ISO Latin 1 [" + isoLatin1TestString.length * 2 + "]"),
+ MochiKit.DOM.TH(null, "UTF 8 [" + utf8TestString.length * 3 + "]")
+ )
+ ),
+ MochiKit.DOM.TFOOT()
+ )//,
+// MochiKit.DOM.H4(null, "AES chunkSize: " + Clipperz.Crypto.AES.DeferredExecution.chunkSize),
+// MochiKit.DOM.H4(null, "AES pauseTime: " + Clipperz.Crypto.AES.DeferredExecution.pauseTime)
+);
+
+
+SimpleTest.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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script> jslog_config_enabled = true; </script>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/DOM.js'></script>
+
+<!--<script type='text/javascript' src='../../../../js/Clipperz/Crypto/Statistics.js'></script>-->
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+test_PRNG = function() {
+ var rand1, rand2;
+ var i,c;
+
+ c = 10;
+ for (i=0; i<c; i++) {
+// jslog.debug(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString());
+ }
+
+ rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
+ is(rand1.byteAtIndex(0) <= 255, true, "getRandomByte returns always a single byte");
+
+ rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(1);
+ is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
+
+
+ rand1 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
+ rand2 = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32);
+ is(rand1.equals(rand2), false, "getRandomByte should almost always return two different values when called into sequence");
+ is(rand1.split(0,1).equals(rand2.split(0,1)), false, "getRandomByte should almost always return two different values when called into sequence");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 1", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 2", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 3", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 4", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 5", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 6", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 7", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 8", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 9", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 10", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 11", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 12", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 13", "Value for random test");
+// is(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(10000).toHexString(), "rand 14", "Value for random test");
+//jslog.debug(rand1.toHexString());
+//jslog.debug(rand2.toHexString());
+
+ SimpleTest.finish();
+}
+
+try {
+ MochiKit.Signal.connect(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'readyToGenerateRandomBytes', test_PRNG);
+ Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
+ SimpleTest.waitForExplicitFinish();
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/DOM.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/RSA.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+try {
+ var rsaPublicKey;
+ var randomValue;
+ var publicEncryptedValue;
+ var privateEncryptedValue;
+
+ var startTime;
+ var endTime;
+
+
+startTime=new Date();
+ rsaPublicKey = Clipperz.Crypto.RSA.generatePublicKey(512);
+
+endTime=new Date();
+is(true, true, 'Time to generate the RSA public key (size 512 bit): '+(endTime.getTime()-startTime.getTime())/1000.0);
+
+ randomValue = Clipperz.Crypto.Base.generateRandomSeed();
+ publicEncryptedValue = Clipperz.Crypto.RSA.encryptUsingPublicKey(rsaPublicKey, randomValue);
+ privateEncryptedValue = Clipperz.Crypto.RSA.encryptUsingPrivateKey(rsaPublicKey, randomValue);
+
+ is(publicEncryptedValue == privateEncryptedValue, false);
+ is(Clipperz.Crypto.RSA.decryptUsingPrivateKey(rsaPublicKey, publicEncryptedValue), randomValue);
+ is(Clipperz.Crypto.RSA.decryptUsingPublicKey(rsaPublicKey, privateEncryptedValue), randomValue);
+
+ //-------------------------------------------------------------------------
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.Crypto.SHA - TEST</title>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../js/JSON/json2.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+
+
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript" src="SHA.test.js"></script>
+</pre>
+</body>
+</html>
+
+
+
+<!-- html>
+<head>
+ <script>
+ jslog_config_enabled = true;
+ clipperz_profiling_enabled = true;
+ </script>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+
+try {
+ var byteArray;
+ var hash;
+ var longText;
+ var startTime, endTime;
+
+ 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.";
+
+ //-------------------------------------------------------------------------
+ //
+ // Test of SHA-256 algorithm
+ //
+ //-------------------------------------------------------------------------
+
+ byteArray = new Clipperz.ByteArray();
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is(hash.toHexString(), "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "sha256('')");
+
+ byteArray = new Clipperz.ByteArray("0xbd");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is(hash.toHexString(), "0x68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b", "sha256('0xbd')");
+
+ byteArray = new Clipperz.ByteArray("0x5fd4");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is(hash.toHexString(), "0x7c4fbf484498d21b487b9d61de8914b2eadaf2698712936d47c3ada2558f6788", "sha256('0x5fd4')");
+
+ byteArray = new Clipperz.ByteArray("0xc98c8e55");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is(hash.toHexString(), "0x7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504", "sha256('0xc98c8e55')");
+
+ byteArray = new Clipperz.ByteArray("0x0df1cd526b5a4edd");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is(hash.toHexString(), "0x47f527210d6e8f940b5082fec01b7305908fa2b49ea3ae597c19a3986097153c", "sha256('0x0df1cd526b5a4edd')");
+
+ byteArray = new Clipperz.ByteArray("0xfdf4700984ee11b70af1880d0e0fefd4");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is( hash.toHexString(),
+ "0xb01ae16eed3b4a770f127b98469ba26fe3d8e9f59d8a2983214afe6cff0e6b6c",
+ "sha256('0xfdf4700984ee11b70af1880d0e0fefd4')");
+
+ byteArray = new Clipperz.ByteArray("0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is( hash.toHexString(),
+ "0x56059e8cb3c2978b198208bf5ca1e1ea5659b737a506324b7cec75b5ebaf057d",
+ "sha256('0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb')");
+
+ byteArray = new Clipperz.ByteArray("0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is( hash.toHexString(),
+ "0xc117b9dce689c399ec99008788cd5d24d8396fab7d96315c4f3fe6d56da63bb3",
+ "sha256('0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a')");
+
+ byteArray = new Clipperz.ByteArray("0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+ is( hash.toHexString(),
+ "0x105a60865830ac3a371d3843324d4bb5fa8ec0e02ddaa389ad8da4f10215c454",
+ "sha256('0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad')");
+
+
+ byteArray = new Clipperz.ByteArray(longText);
+startTime = new Date();
+//console.profile("SHA256");
+ hash = Clipperz.Crypto.SHA.sha256(byteArray);
+//console.profileEnd("SHA256");
+endTime = new Date();
+ is( hash.toHexString(),
+ "0xf6fac13c06784e0fbc61a3d25c41c9984840a8b617a2beb57cf6fa3e5e4a8949",
+ "sha256(longText)");
+ is((endTime - startTime) < 500, true, "Long text hash performance (" + (endTime - startTime) + ")");
+ MochiKit.Logging.logDebug("elapsed time: " + (endTime - startTime));
+
+//#############################################################################
+
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+/*
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+*/
+
+var testSHA = function (aValue, anExpectedResult) {
+ var byteArrayValue;
+
+ byteArrayValue = new Clipperz.ByteArray(aValue);
+ hash = Clipperz.Crypto.SHA.sha256(byteArrayValue);
+ is(hash.toHexString(), anExpectedResult, "sha256(' " + byteArrayValue.toHexString() + "')");
+
+}
+
+
+var tests = {
+
+ 'basic_tests': function (someTestArgs) {
+ testSHA('', '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
+ testSHA('0xbd', '0x68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b');
+ testSHA('0x5fd4', '0x7c4fbf484498d21b487b9d61de8914b2eadaf2698712936d47c3ada2558f6788');
+ testSHA('0xc98c8e55', '0x7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504');
+ testSHA('0x0df1cd526b5a4edd', '0x47f527210d6e8f940b5082fec01b7305908fa2b49ea3ae597c19a3986097153c');
+ testSHA('0xfdf4700984ee11b70af1880d0e0fefd4', '0xb01ae16eed3b4a770f127b98469ba26fe3d8e9f59d8a2983214afe6cff0e6b6c');
+ testSHA('0x8cf53d90077df9a043bf8d10b470b144784411c93a4d504556834dae3ea4a5bb', '0x56059e8cb3c2978b198208bf5ca1e1ea5659b737a506324b7cec75b5ebaf057d');
+ testSHA('0xeebcf5cd6b12c90db64ff71a0e08ccd956e170a50dad769480d6b1fb3eff4934cde90f9e9b930ee637a66285c10f4e8a', '0xc117b9dce689c399ec99008788cd5d24d8396fab7d96315c4f3fe6d56da63bb3');
+ testSHA('0x3592ecfd1eac618fd390e7a9c24b656532509367c21a0eac1212ac83c0b20cd896eb72b801c4d212c5452bbbf09317b50c5c9fb1997553d2bbc29bb42f5748ad', '0x105a60865830ac3a371d3843324d4bb5fa8ec0e02ddaa389ad8da4f10215c454');
+
+ },
+
+ //-------------------------------------------------------------------------
+
+ 'aldo_cortesi_tests': function (someTestArgs) {
+ testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', '0xa3f01b6939256127582ac8ae9fb47a382a244680806a3f613a118851c1ca1d47');
+ testSHA('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', '0xb35439a4ac6f0948b6d6f9e3c6af0f5f590ce20f1bde7090ef7970686ec6738a');
+ testSHA('0x79', '0xa1fce4363854ff888cff4b8e7875d600c2682390412a8cf79b37d0b11148b0fa');
+ testSHA('0x80', '0x76be8b528d0075f7aae98d6fa57a6d3c83ae480a8469e668d7b0af968995ac71');
+ },
+
+ //-------------------------------------------------------------------------
+
+ 'longTextPerformance_test': function (someTestArgs) {
+ var longText;
+ var startTime;
+ var endTime;
+
+ 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.";
+ startTime = new Date();
+ testSHA(longText, '0xf6fac13c06784e0fbc61a3d25c41c9984840a8b617a2beb57cf6fa3e5e4a8949');
+ endTime = new Date();
+
+ is((endTime - startTime) < 100, true, "Long text hash performance (" + (endTime - startTime) + ")");
+ },
+
+ //-------------------------------------------------------------------------
+ 'syntaxFix': MochiKit.Base.noop
+}
+
+//=============================================================================
+
+SimpleTest.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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SRP.js'></script>
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+hashString = function(aValue) {
+ return Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(aValue)).toHexString().substring(2)
+}
+try {
+ var username;
+ var passphrase;
+
+ var C;
+ var P;
+ var encryptedText_1;
+ var encryptedText_2;
+ var salt;
+ var x;
+ var v;
+ var v1;
+
+ username = "giulio.cesare";
+ passphrase = "trustno1";
+
+ C = hashString(username);
+ is (C, "bde3c7b5fdcd9d6ce72782ca1ae912fc4397d668fcb3a73a04e5d47852670c4a", "C");
+
+ P = hashString(passphrase + username);
+ is (P, "d79f5c5a04e91e1c85fb64cb6ee9481cb52c181047f69da02cd6c3ce6d058a76", "P");
+
+ salt = "cf1fa93393ade60318b8276f1f39420098419445005a7dc9117975fe1f8d9988";
+
+ x = hashString(salt + P);
+ is(x, "21fe88a158e420aade86e00b5eb12a4c19bf15482fa34c542c90b1afdbd5b5fd", "x");
+
+ v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n());
+ is(v.asString(10), "33816467430011076413789931449607305355248467973000153409872503376381719918118", "v");
+ is(v.asString(16), "4ac37139dbf32ebabd2c43f91dd085066d3c457d059efd5902d32ed247fcb626", "v (base 16)");
+
+// encryptedText_1 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
+// encryptedText_2 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
+// is (encryptedText_1 != encryptedText_2, true, "Two round of encryption (with random padding bits) should NOT produce the same result");
+
+ //-------------------------------------------------------------------------
+
+ username = "giulio.cesare.debug";
+ passphrase = "trustno1";
+
+ C = hashString(username);
+ is (C, "fa1af609123b97a10d676158ed538d4657a89ac33a102b22bd9a66712039e208", "C");
+
+ P = hashString(passphrase + username);
+ is (P, "e1bfba03dd626b12f29458a6ad63fb2c01b4765548504e1e2f6b1503c82e4253", "P");
+
+ salt = "cf1fa93393ade60318b8276f1f39420098419445005a7dc9117975fe1f8d9988";
+
+ x = hashString(salt + P);
+ is(x, "93d4af3cdcd2447a745d309826dff3161feed4b15f32db8e909ff032a2bc8fb8", "x");
+
+ v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n());
+ is(v.asString(10), "115049747015252903452664067168789229427785288458366249918596663144588656606556", "v");
+
+// encryptedText_1 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
+// encryptedText_2 = Clipperz.Crypto.Base.encryptUsingSecretKey(passphrase, username);
+// is (encryptedText_1 != encryptedText_2, true, "Two round of encryption (with random padding bits) should NOT produce the same result");
+
+ //-------------------------------------------------------------------------
+
+ var srpConnection;
+ var C, P, salt;
+
+ C = "da8602c2f847306f4eb9acdaad925277d1fad1408f173f128a078aea15e60b1e";
+ P = "77643559beca49dd21c1c31db10bb0a9009662cb504413dc3fa3b7303c7e02ba";
+ salt = "000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1";
+
+ srpConnection = new Clipperz.Crypto.SRP.Connection({C:C, P:P, hash:Clipperz.Crypto.SHA.sha_d256});
+ srpConnection._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10);
+ srpConnection.set_s(new Clipperz.Crypto.BigInt(salt, 16));
+ is (srpConnection.s().asString(16, 64), salt, "salt read/write is coherent");
+ srpConnection.set_B(new Clipperz.Crypto.BigInt("123541032067854367017620977654446651448957899464139861291542193929199957895435", 10));
+
+ is( srpConnection.serverSideCredentialsWithSalt(salt).v,
+ "c73169c8236d37bf9ef11a2349e3064b7dc6e883a58d64443ea9235677520030",
+ "server side credentials - v"
+ )
+ is(srpConnection.S(), "84134227508133659832466942692590826994401065200828529664948840490489960952050", "Server side 'S'");
+//MochiKit.Logging.logDebug("=== serverSideCredentials: " + MochiKit.Base.serializeJSON(srpConnection.serverSideCredentialsWithSalt(salt)));
+
+ srpConnection = new Clipperz.Crypto.SRP.Connection({C:C, P:P, hash:Clipperz.Crypto.SHA.sha_d256});
+ try {
+ srpConnection.set_B(new Clipperz.Crypto.BigInt("0", 10));
+ ok(false, "Setting B to 0 should raise an exception");
+ } catch(e) {
+ ok(true, "Setting B to 0 should raise an exception");
+ }
+ //-------------------------------------------------------------------------
+
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.Crypto.Usage - TEST</title>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript">
+Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
+
+MochiKit.Base.update(Clipperz, {
+ 'PM': {
+ 'Crypto': {
+ 'passwordEntropy': function(aValue) {
+ var result;
+ var bitPerChar;
+
+ bitPerChar = 4;
+ if (/[a-z]/.test(aValue)) {
+ bitPerChar ++;
+ }
+ if (/[A-Z]/.test(aValue)) {
+ bitPerChar ++;
+ }
+ if (/[^a-zA-Z0-9]/.test(aValue)) {
+ bitPerChar ++;
+ }
+ //MochiKit.Logging.logDebug("--- bitPerChar: " + bitPerChar);
+
+ result = aValue.length * bitPerChar;
+
+ return result;
+ }
+ }
+ }
+})
+
+try {
+ var keyValue;
+ var keyEntropy;
+ var key;
+ var plainText;
+ var cypherText;
+ var randomBytes;
+ var hashedValue;
+
+ key = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("This is my long and complex passphrase"));
+ keyEntropy = Clipperz.PM.Crypto.passwordEntropy(key);
+
+ cypherText = Clipperz.Crypto.AES.encrypt(key, new Clipperz.ByteArray("some text to encrypt"));
+ plainText = Clipperz.Crypto.AES.decrypt(key, cypherText).asString();
+ is(plainText, "some text to encrypt");
+
+ randomBytes = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(256/8);
+ hashedValue = Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray("text to hash"));
+
+//#############################################################################
+
+} catch (err) {
+
+ var s = "test suite failure!\n";
+ var o = {};
+ var k = null;
+ for (k in err) {
+ // ensure unique keys?!
+ if (!o[k]) {
+ s += k + ": " + err[k] + "\n";
+ o[k] = err[k];
+ }
+ }
+ ok ( false, s );
+}
+
+</script>
+</pre>
+</body>
+</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 @@
+<!--
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.Crypto.* - tests</title>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/TestRunner.js"></script>
+</head>
+<body>
+<script>
+TestRunner.runTests(
+ 'AES.html',
+ 'AES.performance.html',
+ 'Base.html',
+ 'BigInt.html',
+
+// 'ECC.B283.deferred.html',
+// 'ECC.BinaryField.FiniteField.html',
+// 'ECC.BinaryField.FiniteField.B283.html',
+// 'ECC.BinaryField.Value.html',
+//# 'ECC.K283.deferred.html',
+
+ 'PRNG.html',
+// 'RSA.html',
+ 'SHA.html',
+ 'SRP.html',
+ 'Usage.html'
+);
+</script>
+</body>
+</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 @@
+/*
+
+Copyright 2008-2011 Clipperz Srl
+
+This file is part of Clipperz's Javascript Crypto Library.
+Javascript Crypto Library provides web developers with an extensive
+and efficient set of cryptographic functions. The library aims to
+obtain maximum execution speed while preserving modularity and
+reusability.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com
+
+* Javascript Crypto Library is free software: you can redistribute
+ it and/or modify it under the terms of the GNU Affero General Public
+ License as published by the Free Software Foundation, either version
+ 3 of the License, or (at your option) any later version.
+
+* Javascript Crypto Library is distributed in the hope that it will
+ be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Javascript Crypto Library. If not, see
+ <http://www.gnu.org/licenses/>.
+
+*/
+
+/* jsCrypto
+Core AES
+
+Emily Stark (estark@stanford.edu)
+Mike Hamburg (mhamburg@stanford.edu)
+Dan Boneh (dabo@cs.stanford.edu)
+
+Symmetric AES in Javascript using precomputed lookup tables for round transformations rather for speed improvements
+and code size reduction. Provides authenticated encryption in OCB and CCM modes.
+Parts of this code are based on the OpenSSL implementation of AES: http://www.openssl.org
+
+Public domain, 2009.
+
+*/
+
+
+// CCM mode is the default
+var CCM = 1, OCB = 2;
+
+/* aes object constructor. Takes as arguments:
+- 16-byte key, or an array of 4 32-bit words
+- Optionally specify a mode (aes.OCB or aes.CCM). Defaults to CCM
+- Optionally specify a MAC tag length for integrity. Defaults to 16 bytes
+*/
+function aes(key, mode, Tlen) {
+ // initialize objects for CCM and OCB modes
+ this._CCM = new cipherCCM(this);
+ this._OCB = new cipherOCB(this);
+
+ this._decryptScheduled = false;
+
+ if (mode) this._mode = mode;
+ else this._mode = OCB;
+
+ // AES round constants
+ this._RCON = [
+ [0x00, 0x00, 0x00, 0x00],
+ [0x01, 0x00, 0x00, 0x00],
+ [0x02, 0x00, 0x00, 0x00],
+ [0x04, 0x00, 0x00, 0x00],
+ [0x08, 0x00, 0x00, 0x00],
+ [0x10, 0x00, 0x00, 0x00],
+ [0x20, 0x00, 0x00, 0x00],
+ [0x40, 0x00, 0x00, 0x00],
+ [0x80, 0x00, 0x00, 0x00],
+ [0x1b, 0x00, 0x00, 0x00],
+ [0x36, 0x00, 0x00, 0x00]
+ ];
+
+ this._key_len = 16;
+ if (key.length == 4) {
+ this._key = [];
+ aes.wordsToBytes(key, this._key);
+ }
+ else
+ this._key = key;
+
+ if (Tlen) this._Tlen = Tlen;
+ else this._Tlen = 16; // tag length in bytes
+
+ this._nr = 10;
+
+ // initialize tables that will be precomputed
+ this._SBOX = [];
+ this._INV_SBOX = [];
+ this._T = new Array(4);
+ this._Tin = new Array(4);
+ for (var i=0; i < 4; i++) {
+ this._T[i] = [];
+ this._Tin[i] = [];
+ }
+
+ this._precompute();
+ this.scheduleEncrypt();
+
+ // initialize encryption and decryption buffers
+ this._ctBuffer = [];
+ this._ptBuffer = [];
+}
+
+
+//////////////////
+// KEY SCHEDULING
+//////////////////
+
+aes.prototype.scheduleEncrypt = function () {
+ this._decryptScheduled = false;
+
+ this._w = new Array(this._nr+1);
+ this._w[0] = new Array(4);
+ for (var i=0; i < 4; i++)
+ this._w[0][i] = this._key[i];
+ var temp = new Array(4);
+ for (var i=1; i < this._nr+1; i++) {
+ temp[0] = this._w[i-1][3];
+ this._w[i] = new Array(4);
+ 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);
+ this._w[i][0] = this._w[i-1][0] ^ temp[0];
+ for (var j=1; j < 4; j++) {
+ temp[j] = this._w[i][j-1];
+ this._w[i][j] = this._w[i-1][j] ^ temp[j];
+ }
+ }
+};
+
+aes.prototype.scheduleDecrypt = function() {
+
+ if (!this._w) this.scheduleEncrypt();
+ this._decryptScheduled = true;
+ var temp = [];
+ var j = this._w.length-1;
+ for (var i=0; i<j; i++) {
+ temp[0] = this._w[i][0];
+ temp[1] = this._w[i][1];
+ temp[2] = this._w[i][2];
+ temp[3] = this._w[i][3];
+ this._w[i][0] = this._w[j][0];
+ this._w[i][1] = this._w[j][1];
+ this._w[i][2] = this._w[j][2];
+ this._w[i][3] = this._w[j][3];
+ this._w[j][0] = temp[0];
+ this._w[j][1] = temp[1];
+ this._w[j][2] = temp[2];
+ this._w[j][3] = temp[3];
+ j--;
+ }
+
+ var td0 = this._Tin[0], td1 = this._Tin[1], td2 = this._Tin[2], td3 = this._Tin[3], te1 = this._T[1];
+ for (var i=1; i < this._w.length-1; i++) {
+ this._w[i][0] = td0[te1[(this._w[i][0] >>> 24) ] & 0xff] ^
+ td1[te1[(this._w[i][0] >>> 16) & 0xff] & 0xff] ^
+ td2[te1[(this._w[i][0] >>> 8) & 0xff] & 0xff] ^
+ td3[te1[(this._w[i][0] ) & 0xff] & 0xff];
+ this._w[i][1] = td0[te1[(this._w[i][1] >>> 24) ] & 0xff] ^
+ td1[te1[(this._w[i][1] >>> 16) & 0xff] & 0xff] ^
+ td2[te1[(this._w[i][1] >>> 8) & 0xff] & 0xff] ^
+ td3[te1[(this._w[i][1] ) & 0xff] & 0xff];
+ this._w[i][2] = td0[te1[(this._w[i][2] >>> 24) ] & 0xff] ^
+ td1[te1[(this._w[i][2] >>> 16) & 0xff] & 0xff] ^
+ td2[te1[(this._w[i][2] >>> 8) & 0xff] & 0xff] ^
+ td3[te1[(this._w[i][2] ) & 0xff] & 0xff];
+ this._w[i][3] = td0[te1[(this._w[i][3] >>> 24) ] & 0xff] ^
+ td1[te1[(this._w[i][3] >>> 16) & 0xff] & 0xff] ^
+ td2[te1[(this._w[i][3] >>> 8) & 0xff] & 0xff] ^
+ td3[te1[(this._w[i][3] ) & 0xff] & 0xff];
+ }
+};
+
+
+/////////////////////////
+// ENCRYPTION/DECRYPTION
+/////////////////////////
+
+
+/* Authenticated encryption on a multi-block message in OCB or CCM mode.
+iv should be an array of 32-bit words - either 4 words for OCB mode or 1, 2, or 3 words for CCM.
+Use a unique IV for every message encrypted.
+The plaintext argument will be encrypted and MACed; adata will be sent in plaintext but MACed.
+Plaintext and adata are strings.
+ciphertext is an array of bytes. tag is an array of 32-bit words.
+*/
+aes.prototype.encrypt = function(iv, plaintext, ciphertext, adata, tag) {
+ var plaintextBytes = [], adataBytes = [];
+ aes.asciiToBytes(plaintext, plaintextBytes);
+ aes.asciiToBytes(adata, adataBytes);
+
+ this._iv = iv;
+ if (this._mode == CCM)
+ this._CCM.encrypt(plaintextBytes, ciphertext, adataBytes, tag);
+ else if (this._mode == OCB) {
+ this._OCB.encrypt(plaintextBytes, ciphertext, adataBytes, tag);
+ }
+
+ // prepend to the ciphertext the length of the iv (in bytes) and the iv
+ var ivbytes=[];
+ aes.wordsToBytes(iv, ivbytes);
+ var ct = [iv.length*4].concat(ivbytes, ciphertext);
+ for (var i=0; i < ct.length; i++) ciphertext[i] = ct[i];
+
+ for (var i=0; i < ciphertext.length; i++)
+ this._ctBuffer[this._ctBuffer.length] = ciphertext[i];
+
+};
+
+/* Authenticated decryption on a multi-block ciphertext in OCB or CCM mode.
+ciphertext is an array of bytes. tag is an array of 32-bit words.
+plaintext and adata are strings.
+*/
+aes.prototype.decrypt = function(ciphertext, adata, tag) {
+ var ivlen = ciphertext[0];
+ var ivbytes = ciphertext.slice(1, ivlen+1);
+ var iv = [];
+ aes.bytesToWords(ivbytes, iv);
+ this._iv = iv;
+ var ct = ciphertext.slice(ivlen+1);
+
+ var valid = false;
+ var plaintextBytes = [], adataBytes = [];
+ aes.asciiToBytes(adata, adataBytes);
+ if (this._mode == CCM)
+ valid = this._CCM.decrypt(ct, plaintextBytes, adataBytes);
+ else if (this._mode == OCB)
+ valid = this._OCB.decrypt(ct, plaintextBytes, adataBytes, tag);
+ if (valid) {
+ var plaintext = aes.bytesToAscii(plaintextBytes);
+ for (var i=0; i < plaintext.length; i++)
+ this._ptBuffer[this._ptBuffer.length] = plaintext.charAt(i);
+ return plaintext;
+ }
+ return "";
+};
+
+// MACs (but doesn't encrypt) data using CMAC (in CCM mode) or PMAC (in OCB mode)
+aes.prototype.sign = function(data, tag) {
+ if (this._mode == CCM)
+ this._CCM.CMAC(data, "", tag, this._Tlen, false);
+ else if (this._mode == OCB) {
+ this._OCB.PMAC(data, tag);
+ }
+};
+
+// Verifies a CMAC or PMAC tag
+aes.prototype.verify = function(data, tag) {
+ var validTag = [];
+ if (this._mode == CCM)
+ this._CCM.CMAC(data, "", validTag, this._Tlen, false);
+ else if (this._mode == OCB) {
+ this._OCB.PMAC(data, validTag);
+ }
+ if (validTag.length != tag.length) return false;
+ for (var i=0; i < tag.length; i++) {
+ if (tag[i] != validTag[i]) return false;
+ }
+ return true;
+};
+
+/* Encrypts a single block message in AES. Takes the plaintext, an array in which to dump
+the ciphertext, and a boolean decrypt argument. If set to true, this function acts as
+a decryption function.
+block and ciphertext are both arrays of 4 32-bit words.
+*/
+aes.prototype.encryptBlock = function(block, ciphertext, decrypt) {
+ if (!decrypt && this._decryptScheduled) this.scheduleEncrypt();
+
+ // get key schedule
+ var w = this._w;
+ // load round transformation tables
+ var te0, te1, te2, te3;
+ if (decrypt) {
+ te0 = this._Tin[0];
+ te1 = this._Tin[1];
+ te2 = this._Tin[2];
+ te3 = this._Tin[3];
+ } else {
+ te0 = this._T[0];
+ te1 = this._T[1];
+ te2 = this._T[2];
+ te3 = this._T[3];
+ }
+
+ // perform rounds
+ var rk = w[0];
+ var s0 = block[0] ^ rk[0];
+ var s1 = block[1] ^ rk[1];
+ var s2 = block[2] ^ rk[2];
+ var s3 = block[3] ^ rk[3];
+ var t0,t1,t2,t3;
+ rk = w[1];
+ var order = [];
+ for (var round = 1; round < w.length-1; round++) {
+ order = [s1, s2, s3, s0];
+ if (decrypt) order = [s3, s0, s1, s2];
+ t0 = te0[(s0>>>24)] ^ te1[(order[0]>>>16) & 0xff]^ te2[(s2>>>8)&0xff] ^ te3[order[2]&0xff] ^ rk[0];
+ t1 = te0[(s1>>>24)] ^ te1[(order[1]>>>16) & 0xff]^ te2[(s3>>>8)&0xff] ^ te3[order[3]&0xff] ^ rk[1];
+ t2 = te0[(s2>>>24)] ^ te1[(order[2]>>>16) & 0xff]^ te2[(s0>>>8)&0xff] ^ te3[order[0]&0xff] ^ rk[2];
+ t3 = te0[(s3>>>24)] ^ te1[(order[3]>>>16) & 0xff]^ te2[(s1>>>8)&0xff] ^ te3[order[1]&0xff] ^ rk[3];
+ s0 = t0;
+ s1 = t1;
+ s2 = t2;
+ s3 = t3;
+ rk = w[round+1];
+ }
+ if (decrypt) {
+ 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];
+ 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]
+ 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];
+ 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];
+ } else {
+ s0 = (te2[t0>>>24]&0xff000000) ^ (te3[(t1>>>16)&0xff]&0x00ff0000) ^ (te0[(t2>>>8)&0xff]&0x0000ff00) ^ (te1[(t3)&0xff]&0x000000ff) ^ rk[0];
+ s1 = (te2[t1>>>24]&0xff000000) ^ (te3[(t2>>>16)&0xff]&0x00ff0000) ^ (te0[(t3>>>8)&0xff]&0x0000ff00) ^ (te1[(t0)&0xff]&0x000000ff) ^ rk[1];
+ s2 = (te2[t2>>>24]&0xff000000) ^ (te3[(t3>>>16)&0xff]&0x00ff0000) ^ (te0[(t0>>>8)&0xff]&0x0000ff00) ^ (te1[(t1)&0xff]&0x000000ff) ^ rk[2];
+ s3 = (te2[t3>>>24]&0xff000000) ^ (te3[(t0>>>16)&0xff]&0x00ff0000) ^ (te0[(t1>>>8)&0xff]&0x0000ff00) ^ (te1[(t2)&0xff]&0x000000ff) ^ rk[3];
+ }
+ ciphertext[0] = s0;
+ ciphertext[1] = s1;
+ ciphertext[2] = s2;
+ ciphertext[3] = s3;
+};
+
+// As above, block and plaintext are arrays of 4 32-bit words.
+aes.prototype.decryptBlock = function(block, plaintext) {
+ if (!this._decryptScheduled) this.scheduleDecrypt();
+
+ this.encryptBlock(block, plaintext, true);
+};
+
+
+////////////////////
+// HELPER FUNCTIONS
+////////////////////
+
+aes._hex = function(n) {
+ var out = "",i,digits="0123456789ABCDEF";
+ for (i=0; i<8; i++) {
+ var digit = n&0xF;
+ out = digits.substring(digit,digit+1) + out;
+ n = n >>> 4;
+ }
+ return out;
+}
+
+aes._hexall = function(nn) {
+ var out = "",i;
+ for (i=0;i<nn.length;i++) {
+ if (i%4 == 0) out+= "<br/>\n";
+ else if (i) out += " ";
+ out += aes._hex(nn[i]);
+ }
+ return out;
+}
+
+aes.bytesToAscii = function(bytes) {
+ var ascii = "";
+ var len = bytes.length;
+ for (var i=0; i < len; i++) {
+ ascii = ascii + String.fromCharCode(bytes[i]);
+ }
+ return ascii;
+};
+
+aes.asciiToBytes = function(ascii, bytes) {
+ var len = ascii.length;
+ for (var i=0; i < len; i++)
+ bytes[i] = ascii.charCodeAt(i);
+};
+
+aes.wordsToBytes = function(words, bytes) {
+ var bitmask = 1;
+ for (var i=0; i < 7; i++) bitmask = (bitmask << 1) | 1;
+ for (var i=0; i < words.length; i++) {
+ var bstart = i*4;
+ for (var j=0; j < 4; j++) {
+ bytes[bstart+j] = (words[i] & (bitmask << (8*(3-j)))) >>> (8*(3-j));
+ }
+ }
+};
+
+aes.bytesToWords = function(bytes, words) {
+ var paddedBytes = bytes.slice();
+ while (paddedBytes.length % 4 != 0) paddedBytes.push(0);
+ var num_words = Math.floor(paddedBytes.length/4);
+ for (var j=0; j < num_words; j++)
+ words[j] = ((paddedBytes[(j<<2)+3]) | (paddedBytes[(j<<2)+2] << 8) | (paddedBytes[(j<<2)+1] << 16) | (paddedBytes[j<<2] << 24));
+};
+
+
+///////////////////////////////////////
+// KEY DERIVATION
+//////////////////////////////////////
+
+// password is a string, presumably a password entered by the user.
+// salt is eight random bytes associated with each user
+// This function returns an array of bytes of length 16
+function generateKey(password, salt) {
+ var pwBytes = [];
+ aes.asciiToBytes(password, pwBytes);
+ var pwWords = [], saltWords = [];
+ aes.bytesToWords(pwBytes, pwWords);
+ aes.bytesToWords(salt, saltWords);
+
+ var iterations = 1000;
+
+ var derivedKey = [];
+ var blockIndex = 1;
+
+ var xorHashes = function(h1, h2) {
+ var xor = [];
+ var i;
+ for (i=0; i < h1.length; i++) xor.push(h1[i] ^ h2[i]);
+ return xor;
+ };
+
+ while (derivedKey.length < 16) {
+ var hashBytes = pwWords.concat(saltWords);
+ hashBytes.push(blockIndex);
+ var T = SHA256.hash_words_big_endian(hashBytes);
+ var u = T;
+ for (var i=2; i < iterations; i++) {
+ var hash = SHA256.hash_words_big_endian(pwWords.concat(u));
+ u = xorHashes(T, hash);
+ }
+ var block = [];
+ aes.wordsToBytes(T, block);
+ for (var i=0; i < block.length; i++) derivedKey.push(block[i]);
+ }
+
+ if (derivedKey.length > 16) derivedKey.length = 16;
+ return derivedKey;
+}
+
+///////////////////////////////////////
+// ROUND TRANSFORMATION PRECOMPUTATION
+///////////////////////////////////////
+
+
+// Precomputation code by Mike Hamburg
+
+aes.prototype._precompute = function() {
+ var x,xi,sx,tx,tisx,i;
+ var d=[];
+
+ /* compute double table */
+ for (x=0;x<256;x++) {
+ d[x]= x&128 ? x<<1 ^ 0x11b : x<<1;
+ //d[x] = x<<1 ^ (x>>7)*0x11b; //but I think that's less clear.
+ }
+
+ /* Compute the round tables.
+ *
+ * We'll need access to x and x^-1, which we'll get by walking
+ * GF(2^8) as generated by (82,5).
+ */
+ for(x=xi=0;;) {
+ // compute sx := sbox(x)
+ sx = xi^ xi<<1 ^ xi<<2 ^ xi<<3 ^ xi<<4;
+ sx = sx>>8 ^ sx&0xFF ^ 0x63;
+
+ var dsx = d[sx], x2=d[x],x4=d[x2],x8=d[x4];
+
+ // te(x) = rotations of (2,1,1,3) * sx
+ tx = dsx<<24 ^ sx<<16 ^ sx<<8 ^ sx^dsx;
+
+ // similarly, td(sx) = (E,9,D,B) * x
+ tisx = (x8^x4^x2) <<24 ^
+ (x8^x ) <<16 ^
+ (x8^x4^x ) << 8 ^
+ (x8^x2^x );
+
+ // This can be done by multiplication instead but I think that's less clear
+ // tisx = x8*0x1010101 ^ x4*0x1000100 ^ x2*0x1000001 ^ x*0x10101;
+ // tx = dsx*0x1000001^sx*0x10101;
+
+ // rotate and load
+ for (i=0;i<4;i++) {
+ this._T[i][x] = tx;
+ this._Tin[i][sx] = tisx;
+ tx = tx<<24 | tx>>>8;
+ tisx = tisx<<24 | tisx>>>8;
+ }
+
+ // te[4] is the sbox; td[4] is its inverse
+ this._SBOX[ x] = sx;
+ this._INV_SBOX[sx] = x;
+
+
+ // wonky iteration goes through 0
+ if (x==5) {
+ break;
+ } else if (x) {
+ x = x2^d[d[d[x8^x2]]]; // x *= 82 = 0b1010010
+ xi ^= d[d[xi]]; // xi *= 5 = 0b101
+ } else {
+ x=xi=1;
+ }
+ }
+
+ // We computed the arrays out of order. On Firefox, this matters.
+ // Compact them.
+ for (i=0; i<4; i++) {
+ this._T[i] = this._T[i].slice(0);
+ this._Tin[i] = this._Tin[i].slice(0);
+ }
+ this._SBOX = this._SBOX.slice(0);
+ this._INV_SBOX = this._INV_SBOX.slice(0);
+
+
+};
+
+
+
+
+
+/* jsCrypto
+CCM mode
+
+Emily Stark (estark@stanford.edu)
+Mike Hamburg (mhamburg@stanford.edu)
+Dan Boneh (dabo@cs.stanford.edu)
+
+CCM mode for authenticated encryption of multiple 16-byte blocks. Uses AES as core cipher.
+
+Public domain, 2009.
+
+*/
+
+// Constructor takes an aes object as its core cipher
+function cipherCCM(cipher) {
+ this._cipher = cipher;
+}
+
+/* Formats plaintext and adata for MACing and encryption.
+adata and plaintext are arrays of bytes, B will be an array of arrays of 16 bytes
+Tlen specifies the number of bytes in the tag.
+Formatted according to the CCM specification.
+ */
+cipherCCM.prototype._formatInput = function(adata, plaintext, Tlen, B) {
+ // compute B[0]
+ var flags, nbytes=[];
+ aes.wordsToBytes(this._cipher._iv, nbytes);
+ if (adata) flags = 0x01<<6;
+ else flags = 0x00<<6;
+ flags = flags | (((Tlen-2)/2)<<3); // (t-2)/2
+ var q = 15-this._cipher._iv.length*4;
+ flags = flags | (q-1);
+ B[0] = new Array(16);
+ B[0][0] = flags;
+ for (var i=1; i <= 15-q; i++) B[0][i] = nbytes[i-1];
+ var Q = plaintext.length;
+
+ // make some bitmasks
+ var bitmask = 1;
+ for (var i=0; i < 7; i++) bitmask = (bitmask<<1) | 1;
+ for (var i=15; i > 15-q; i--) {
+ B[0][i] = Q & bitmask;
+ Q = Q>>>8;
+ }
+
+ // compute the blocks which identify adata
+ if (adata) {
+ var a = adata.length, Bind=1, BIind = 0, aind=0;
+ B[1] = new Array(16);
+ if (a < (2<<16 - 2<<8)) {
+ B[1][0] = a>>>8;
+ B[1][1] = a & bitmask;
+ BIind = 2;
+ } else if (a < (2<<32)) {
+ B[1][0] = 0xff;
+ B[1][1] = 0xfe;
+ for (var i=5; i >= 0; i--) {
+ B[1][2+i] = a & bitmask;
+ a = a>>>8;
+ }
+ BIind=8;
+ } else {
+ B[1][0] = 0xff;
+ B[1][0] = 0xff;
+ for (i=9; i >= 0; i--) {
+ B[1][2+i] = a & bitmask;
+ a = a >>> 8;
+ }
+ BIind = 12;
+ }
+ }
+
+ while (aind < adata.length) {
+ B[Bind][BIind] = adata[aind];
+ aind++;
+ if (BIind == 15) {
+ Bind++;
+ BIind = 0;
+ if (aind != adata.length) B[Bind] = new Array(16);
+ } else BIind++;
+ }
+ if (BIind != 0) {
+ while (BIind <= 15) {
+ B[Bind][BIind] = 0x00;
+ BIind++;
+ }
+ }
+
+ Bind++;
+ BIind=0;
+ B[Bind] = new Array(16);
+
+ // compute the payload blocks
+ var pind = 0;
+ while (pind < plaintext.length) {
+ B[Bind][BIind] = plaintext[pind];
+ pind++;
+ if (BIind == 15) {
+ Bind++;
+ BIind = 0;
+ if (pind != plaintext.length) B[Bind] = new Array(16);
+ } else BIind++;
+ }
+ if (BIind != 0) {
+ while (BIind <= 15) {
+ B[Bind][BIind] = 0x00;
+ BIind++;
+ }
+ }
+
+};
+
+/* Generate the blocks that will be used as counters.
+ctr will be an array of m+1 arrays of 16 bytes. */
+cipherCCM.prototype._generateCtrBlocks = function(m, ctr) {
+ var nbytes = [];
+ aes.wordsToBytes(this._cipher._iv, nbytes);
+ var flags = 15 - (this._cipher._iv.length*4) - 1;
+ var bitmask = 1;
+ for (var i=0; i < 7; i++) bitmask = (bitmask<<1) | 1;
+ for (var i=0; i <= m; i++) {
+ ctr[i] = new Array(16);
+ ctr[i][0] = flags;
+ for (var j=0; j < nbytes.length; j++) {
+ ctr[i][j+1] = nbytes[j];
+ }
+ for (var j=15; j > nbytes.length; j--) {
+ ctr[i][j] = (i>>>(8*(15-j))) & bitmask;
+ }
+ }
+
+};
+
+
+/* CBC-MAC adata and plaintext, and store the tag in tag.
+adata and plaintext are arrays of bytes
+tag will be an array of Tlen/4 32-bit words
+Tlen is an integer divisible by 4 that specifies the number of bytes in the tag.
+*/
+cipherCCM.prototype.CBCMAC = function(adata, plaintext, tag, Tlen, formatInput) {
+ var B = [];
+ if (formatInput)
+ this._formatInput(adata,plaintext,Tlen,B);
+ else {
+ var Sind = 0, SIind = 0, aind = 0, alen = adata.length;
+ B[0] = [];
+ while (aind < alen) {
+ B[Sind][SIind] = adata[aind];
+ SIind++;
+ if (SIind == 16) {
+ SIind = 0;
+ Sind++;
+ if (aind != alen-1) B[Sind] = [];
+ }
+ aind++;
+ }
+ }
+ var words = [];
+ var Yprev = [], Y = [];
+ aes.bytesToWords(B[0],words);
+ this._cipher.encryptBlock(words, Y);
+ var r = B.length, t = new Array(4);
+
+ for (var i=1; i < r; i++) {
+ for (var j=0; j < 4; j++) {
+ var bstart = j*4;
+ t[j] = Y[j] ^ ((B[i][bstart++]<<24) | (B[i][bstart++]<<16) | (B[i][bstart++]<<8) | (B[i][bstart++]));
+ Yprev[j] = Y[j];
+ }
+ this._cipher.encryptBlock(t, Y);
+ }
+ for (var i=0; i < Tlen/4; i++)
+ tag[i] = Y[i];
+};
+
+
+/* Provides authenticated encryption using CBCMAC and CTR-mode encryption on plaintext.
+adata is MACed but not encrypted.
+plaintext, adata, and tag are arrays of bytes
+Tlen is the number of bytes in the tag
+ciphertext will be an array of bytes. */
+cipherCCM.prototype.encrypt = function(plaintext, ciphertext, adata, tag) {
+ var Tlen = this._cipher._Tlen;
+ this.CBCMAC(adata, plaintext, tag, Tlen, true);
+ var ctr = [], m = Math.ceil(plaintext.length/16);
+ this._generateCtrBlocks(m, ctr);
+ var cblocks = [], S=[], t = new Array(4);
+ for (var i=0; i <= m; i++) {
+ S[i] = new Array(16);
+ aes.bytesToWords(ctr[i], cblocks);
+ this._cipher.encryptBlock(cblocks, t);
+ aes.wordsToBytes(t, S[i]);
+ }
+ var Sind = 1, SIind = 0;
+ for (var i=0; i < plaintext.length; i++) {
+ ciphertext[i] = plaintext[i] ^ S[Sind][SIind];
+ SIind++;
+ if (SIind == 16) {
+ Sind++;
+ SIind = 0;
+ }
+ }
+ var tbytes = [];
+ aes.wordsToBytes(tag, tbytes);
+ var cstart = plaintext.length;
+ for (var i=0; i < Tlen; i++)
+ ciphertext[cstart+i] = tbytes[i] ^ S[0][i];
+};
+
+
+/* Decrypt and verify the MAC on ciphertext and adata. The integrity of adata is verified, but isn't decrypted.
+ciphertext, adata are arrays of bytes
+plaintext will be an array of bytes
+Returns true if tag is valid, false otherwise.
+*/
+cipherCCM.prototype.decrypt = function(ciphertext, plaintext, adata) {
+ var Tlen = this._cipher._Tlen;
+ if (ciphertext.length <= Tlen) return false;
+ var ctr = [], tag = new Array(Tlen), m = Math.ceil(ciphertext.length/16);
+ this._generateCtrBlocks(m, ctr);
+ var S = [], t = new Array(4), cblocks=[];
+
+ for (var i=0; i <= m; i++) {
+ S[i] = new Array(16);
+ aes.bytesToWords(ctr[i], cblocks);
+ this._cipher.encryptBlock(cblocks, t);
+ aes.wordsToBytes(t, S[i]);
+ }
+
+ var Sind = 1, SIind = 0;
+ for (var i=0; i < (ciphertext.length-Tlen); i++) {
+ plaintext[i] = ciphertext[i] ^ S[Sind][SIind];
+ SIind++;
+ if (SIind == 16) {
+ SIind = 0;
+ Sind++;
+ }
+ }
+
+ for (var i=0; i < Tlen; i++)
+ tag[i] = ciphertext[ciphertext.length-Tlen+i] ^ S[0][i];
+
+ // verify integrity
+ var validTag = [], vtbytes = [];
+ this.CBCMAC(adata, plaintext, validTag, Tlen, true);
+ aes.wordsToBytes(validTag, vtbytes);
+ for (var i=0; i < Tlen; i++) {
+ if (vtbytes[i] != tag[i])
+ return false;
+ }
+ return true;
+
+};
+
+// Generate subkeys according to the CCM specification. */
+cipherCCM.prototype._generateSubkeys = function(k1,k2) {
+ var t = [0x00000000,0x00000000,0x00000000,0x00000000], t2 = new Array(4);
+ this._cipher.encryptBlock(t, t2);
+ for (var i=0; i < 3; i++)
+ k1[i] = t2[i]<<1 | t2[i+1]>>>31;
+ k1[3] = t2[3]<<1;
+ if (t2[0]>>>31 != 0)
+ k1[3] = k1[3] ^ 135;
+ for (var i=0; i < 3; i++)
+ k2[i] = k1[i]<<1 | k1[i+1]>>>31;
+ k2[3] = k1[3]<<1;
+ if (k1[0]>>>31 != 0)
+ k2[3] = k2[3] ^ 135;
+};
+
+
+/* CMAC used for integrity only (no encryption). */
+cipherCCM.prototype.CMAC = function(adata, plaintext, tag, Tlen, formatInput) {
+ var B = [], t = new Array(4); // will be an array of arrays of 16 bytes
+ if (formatInput)
+ this._formatInput(adata,plaintext,Tlen,B);
+ else {
+ var Sind = 0, SIind = 0, aind = 0, alen = adata.length;
+ B[0] = [];
+ while (aind < alen) {
+ B[Sind][SIind] = adata[aind];
+ SIind++;
+ if (SIind == 16) {
+ SIind = 0;
+ Sind++;
+ if (aind != alen-1) B[Sind] = [];
+ }
+ aind++;
+ }
+ }
+ var k1 = new Array(4), k2 = new Array(4);
+ this._generateSubkeys(k1,k2);
+ var last = B.length-1, kbytes = [];
+ if (alen % 16 == 0) {
+ aes.wordsToBytes(k1, kbytes);
+ } else {
+ aes.wordsToBytes(k2, kbytes);
+ B[last][B[last].length] = 1<<7;
+ while (B[last].length % 16 != 0)
+ B[last][B[last].length] = 0x00;
+ }
+ for (var i=0; i < 16; i++) B[last][i] = B[last][i] ^ kbytes[i];
+ var C = [0x00000000,0x00000000,0x00000000,0x00000000], Cprev = new Array(4), words = new Array(4);
+ for (var i=0; i < B.length; i++) {
+ aes.bytesToWords(B[i], words);
+ for (var j=0; j < 4; j++) {
+ Cprev[j] = C[j];
+ t[j] = C[j] ^ words[j];
+ }
+ this._cipher.encryptBlock(t, C);
+ }
+ var cbytes=[];
+ aes.wordsToBytes(C, cbytes);
+ for (var i=0; i < Tlen; i++)
+ tag[i] = cbytes[i];
+
+};
+
+
+
+/* jsCrypto
+OCB mode
+
+Emily Stark (estark@stanford.edu)
+Mike Hamburg (mhamburg@stanford.edu)
+Dan Boneh (dabo@cs.stanford.edu)
+
+OCB mode for authenticated encryption of multiple 16-byte blocks. Uses AES as core cipher.
+
+Public domain, 2009.
+*/
+
+/* Constructor takes an aes object as the core cipher. */
+function cipherOCB(cipher) {
+ this._cipher = cipher;
+}
+
+
+/* Provides integrity only, no encryption.
+header is an array of bytes, tag will be an array of 4 32-bit words */
+cipherOCB.prototype.PMAC = function(header, tag) {
+ var carry, t = new Array(4), t2 = new Array(4), Checksum = [0x00000000,0x00000000,0x00000000,0x00000000];
+ var Offset = new Array(4);
+ this._cipher.encryptBlock(Checksum, Offset);
+ this._times2(t, Offset);
+ for (var i=0; i < 4; i++) Offset[i] = t[i] ^ Offset[i];
+ this._times2(t, Offset);
+ for (var i=0; i < 4; i++) Offset[i] = t[i] ^ Offset[i];
+
+ // accumulate all but the last block
+ var num_blocks = Math.floor((header.length-1)/16);
+ for (var i=0; i < num_blocks; i++) {
+ this._times2(Offset,Offset);
+ var bstart = i*16; // start-of-block index
+ for (var j=0; j < 4; j++)
+ 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));
+ this._cipher.encryptBlock(t, t2);
+ for (var j=0; j < 4; j++) Checksum[j] = Checksum[j] ^ t2[j];
+ }
+
+ // accumulate the last block
+ this._times2(Offset,Offset);
+
+ if (header.length%16 == 0) {
+ var bstart = header.length-16;
+ for (var j=0; j < 4; j++)
+ 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));
+ this._times2(t, Offset);
+ for (var i=0; i < 4; i++) Offset[i] = Offset[i] ^ t[i];
+ } else {
+ var block_bytes = [], block = new Array(4), len = header.length, ind=0;
+ for (var i=(header.length-(header.length%16)); i < len; i++) {
+ block_bytes[ind] = header[i];
+ ind++;
+ }
+ block_bytes[ind] = 0x80;
+ ind++;
+ while (block_bytes.length%16 != 0) {
+ block_bytes[ind] = 0x00;
+ ind++;
+ }
+ aes.bytesToWords(block_bytes,block);
+ for (var j=0; j < 4; j++) {
+ var bstart = 4*j;
+ Checksum[j] = Checksum[j] ^ ((block_bytes[bstart++]<<24) | (block_bytes[bstart++]<<16) | (block_bytes[bstart++]<<8) | (block_bytes[bstart++]));
+ }
+ this._times2(t, Offset);
+ for (var i=0; i < 4; i++) Offset[i] = Offset[i] ^ t[i];
+ this._times2(t, Offset);
+ for (var i=0; i < 4; i++) Offset[i] = Offset[i] ^ t[i];
+ }
+
+ // compute result
+ for (var i=0; i < 4; i++) t[i] = Offset[i] ^ Checksum[i];
+ this._cipher.encryptBlock(t, tag);
+};
+
+
+/* Encrypts and MACs plaintext, only MACS header.
+plaintext, ciphertext and header are arrays of bytes. tag will be an array of 4 32-bit words. */
+cipherOCB.prototype.encrypt = function(plaintext, ciphertext, header, tag) {
+ var Checksum = [0x00000000,0x00000000,0x00000000,0x00000000];
+ var t = [0x00000000,0x00000000,0x00000000,0x00000000], t2 = new Array(4);
+ var Offset = new Array(4);
+ this._cipher.encryptBlock(this._cipher._iv, Offset);
+ var cbytes = [];
+
+ // encrypt and accumulate all but last block
+ var num_blocks = Math.floor((plaintext.length-1)/16), bstart=0, block = new Array(4);
+ for (var i=0; i < num_blocks; i++) {
+ this._times2(Offset,Offset);
+ bstart = 16*i;
+ for (var j=0; j < 4; j++)
+ block[j] = ((plaintext[bstart+(j<<2)+3]) | (plaintext[bstart+(j<<2)+2] << 8) | (plaintext[bstart+(j<<2)+1] << 16) | (plaintext[bstart+(j<<2)] << 24));
+ for (var j=0; j < 4; j++)
+ t[j] = Offset[j] ^ block[j];
+ this._cipher.encryptBlock(t,t2);
+ for (var j=0; j < 4; j++) t[j] = Offset[j] ^ t2[j];
+ aes.wordsToBytes(t, cbytes);
+ for (var j=0; j < 16; j++) ciphertext[bstart+j] = cbytes[j];
+ for (var j=0; j < 4; j++) Checksum[j] = Checksum[j] ^ block[j];
+ }
+
+ // encrypt and accumulate last block
+ var num_bytes = plaintext.length%16;
+ if ((num_bytes == 0) && (plaintext.length > 0)) num_bytes=16;
+ this._times2(Offset,Offset);
+ t = [0x00000000,0x00000000,0x00000000,0x00000000];
+ t[3] = num_bytes*8;
+ for (var i=0; i < 4; i++) t[i] = Offset[i] ^ t[i];
+ var Pad = new Array(4);
+ this._cipher.encryptBlock(t, Pad);
+ var pad_bytes = new Array(16);
+ aes.wordsToBytes(Pad, pad_bytes);
+ var tempbytes = [];
+ bstart = plaintext.length-num_bytes;
+ for (var i=0; i < num_bytes; i++) {
+ ciphertext[bstart+i] = plaintext[bstart+i] ^ pad_bytes[i];
+ tempbytes[tempbytes.length] = plaintext[bstart+i];
+ }
+ for (var i=num_bytes; i < 16; i++)
+ tempbytes[tempbytes.length] = pad_bytes[i];
+ aes.bytesToWords(tempbytes, t);
+ for (var i=0; i < 4; i++) Checksum[i] = Checksum[i] ^ t[i];
+
+ // compute authentication tag
+ this._times2(t,Offset);
+ for (var i=0; i < 4; i++) {
+ Offset[i] = t[i] ^ Offset[i];
+ t[i] = Checksum[i] ^ Offset[i];
+ }
+ this._cipher.encryptBlock(t,t2);
+ if (header.length > 0) {
+ this.PMAC(header, t);
+ for (var i=0; i < 4; i++) tag[i] = t[i] ^ t2[i];
+ } else {
+ for (var i=0; i < 4; i++) tag[i] = t2[i];
+ }
+};
+
+
+/* Decrypts and verifies integrity of ciphertext, only verifies integrity of header.
+ciphertext, plaintext, and header are arrays of bytes. tag is an array of 4 32-bit words.
+Returns true if tag is valid, false otherwise. */
+cipherOCB.prototype.decrypt = function(ciphertext, plaintext, header, tag) {
+ var Offset = new Array(4), Checksum = [0x00000000,0x00000000,0x00000000,0x00000000];
+ this._cipher.encryptBlock(this._cipher._iv, Offset);
+
+ var t = new Array(4), t2 = new Array(4), block = new Array(4);
+
+ // decrypt and accumulate first m-1 blocks
+ var num_blocks = Math.floor((ciphertext.length-1)/16);
+ var bstart = 0, pbytes = new Array(16);
+ this._cipher.scheduleDecrypt();
+ for (var i=0; i < num_blocks; i++) {
+ this._times2(Offset,Offset);
+ bstart = i*16;
+ for (var j=0; j < 4; j++)
+ 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));
+ this._cipher.decryptBlock(t,t2);
+ for (var j=0; j < 4; j++) {
+ block[j] = Offset[j] ^ t2[j];
+ Checksum[j] = block[j] ^ Checksum[j];
+ }
+ aes.wordsToBytes(block,pbytes);
+ for (var j=0; j < 16; j++)
+ plaintext[bstart+j] = pbytes[j];
+ }
+
+ // decrypt and accumulate final block
+ var Pad = new Array(4), padbytes=[];
+ this._cipher.scheduleEncrypt()
+ this._times2(Offset,Offset);
+ var num_bytes = ciphertext.length%16;
+ if ((num_bytes == 0) && (ciphertext.length > 0)) num_bytes=16;
+ t = [0x00000000,0x00000000,0x00000000,0x00000000];
+ t[3] = num_bytes*8;
+ for (var i=0; i < 4; i++) t[i] = t[i] ^ Offset[i]
+ this._cipher.encryptBlock(t,Pad);
+ aes.wordsToBytes(Pad, padbytes);
+ bstart = ciphertext.length - num_bytes;
+ for (var i=0; i < num_bytes; i++) {
+ plaintext[bstart+i] = ciphertext[bstart+i] ^ padbytes[i];
+ t[i] = plaintext[bstart+i];
+ }
+ for (var i = num_bytes; i < 16; i++)
+ t[i] = padbytes[i];
+ aes.bytesToWords(t,t2);
+ for (var i=0; i < 4; i++) Checksum[i] = Checksum[i] ^ t2[i];
+
+ // compute valid authentication tag
+ this._times2(t, Offset);
+ for (var i=0; i < 4; i++) {
+ Offset[i] = Offset[i] ^ t[i];
+ t[i] = Offset[i] ^ Checksum[i];
+ }
+ var validTag = new Array(4);
+ this._cipher.encryptBlock(t,validTag);
+ t = new Array(4);
+ if (header.length > 0) {
+ this.PMAC(header, t);
+ for (var i=0; i < 4; i++) validTag[i] = validTag[i] ^ t[i];
+ }
+ // compute results
+ for (var i=0; i < 4; i++) {
+ if (aes._hex(tag[i]) != aes._hex(validTag[i])) {
+ return false;
+ }
+ }
+ return true;
+};
+
+
+
+cipherOCB.prototype._times2 = function(dst, src) {
+ var carry = src[0]>>>31;
+ for (var i=0; i < 3; i++)
+ dst[i] = (src[i]<<1) | (src[i+1]>>>31);
+ dst[3] = (src[3]<<1) ^ (carry * 0x87);
+};
+
+
+
+
+
+
+
+
+/*
+jsCrypto
+
+sha256.js
+Mike Hamburg, 2008. Public domain.
+ */
+
+
+function SHA256() {
+ if (!this.k[0])
+ this.precompute();
+ this.initialize();
+}
+
+SHA256.prototype = {
+ /*
+ init:[0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19],
+
+ k:[0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2],
+ */
+
+ init:[], k:[],
+
+ precompute: function() {
+ var p=2,i=0,j;
+
+ function frac(x) { return (x-Math.floor(x)) * 4294967296 | 0 }
+
+ outer: for (;i<64;p++) {
+ for (j=2;j*j<=p;j++)
+ if (p % j == 0)
+ continue outer;
+
+ if (i<8) this.init[i] = frac(Math.pow(p,1/2));
+ this.k[i] = frac(Math.pow(p,1/3));
+ i++;
+ }
+ },
+
+ initialize:function() {
+ this.h = this.init.slice(0);
+ this.word_buffer = [];
+ this.bit_buffer = 0;
+ this.bits_buffered = 0;
+ this.length = 0;
+ this.length_upper = 0;
+ },
+
+ // one cycle of SHA256
+ block:function(words) {
+ var w=words.slice(0),i,h=this.h,tmp,k=this.k;
+
+ 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];
+
+ for (i=0;i<64;i++) {
+ if (i<16) {
+ tmp=w[i];
+ } else {
+ var a=w[(i+1)&15], b=w[(i+14)&15];
+ 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;
+ }
+
+ tmp += h7 + (h4>>>6^h4>>>11^h4>>>25^h4<<26^h4<<21^h4<<7) + (h6 ^ h4&(h5^h6)) + k[i];
+
+ h7=h6; h6=h5; h5=h4;
+ h4 = h3 + tmp | 0;
+
+ h3=h2; h2=h1; h1=h0;
+
+ h0 = (tmp + ((h1&h2)^(h3&(h1^h2))) + (h1>>>2^h1>>>13^h1>>>22^h1<<30^h1<<19^h1<<10)) | 0;
+ }
+
+ h[0]+=h0; h[1]+=h1; h[2]+=h2; h[3]+=h3;
+ h[4]+=h4; h[5]+=h5; h[6]+=h6; h[7]+=h7;
+ },
+
+ update_word_big_endian:function(word) {
+ var bb;
+ if ((bb = this.bits_buffered)) {
+ this.word_buffer.push(word>>>(32-bb) ^ this.bit_buffer);
+ this.bit_buffer = word << bb;
+ } else {
+ this.word_buffer.push(word);
+ }
+ this.length += 32;
+ if (this.length == 0) this.length_upper ++; // mmhm..
+ if (this.word_buffer.length == 16) {
+ this.block(this.word_buffer);
+ this.word_buffer = [];
+ }
+ },
+
+ update_word_little_endian:function(word) {
+ word = word >>> 16 ^ word << 16;
+ word = ((word>>>8) & 0xFF00FF) ^ ((word<<8) & 0xFF00FF00);
+ this.update_word_big_endian(word);
+ },
+
+ update_words_big_endian: function(words) {
+ for (var i=0; i<words.length; i++) this.update_word_big_endian(words[i]);
+ },
+
+ update_words_little_endian: function(words) {
+ for (var i=0; i<words.length; i++) this.update_word_little_endian(words[i]);
+ },
+
+ update_byte:function(byte) {
+ this.bit_buffer ^= (byte & 0xff) << (24 - (this.bits_buffered));
+ this.bits_buffered += 8;
+ if (this.bits_buffered == 32) {
+ this.bits_buffered = 0;
+ this.update_word_big_endian(this.bit_buffer);
+ this.bit_buffer = 0;
+ }
+ },
+
+ update_string:function(string) {
+ throw "not yet implemented";
+ },
+
+ finalize:function() {
+ var i, wb = this.word_buffer;
+
+ wb.push(this.bit_buffer ^ (0x1 << (31 - this.bits_buffered)));
+ for (i = (wb.length + 2) & 15; i<16; i++) {
+ wb.push(0);
+ }
+
+ wb.push(this.length_upper);
+ wb.push(this.length + this.bits_buffered);
+
+ this.block(wb.slice(0,16));
+ if (wb.length > 16) {
+ this.block(wb.slice(0,16));
+ }
+
+ var h = this.h;
+ this.initialize();
+ return h;
+ }
+}
+
+SHA256.hash_words_big_endian = function(words) {
+ var s = new SHA256();
+ for (var i=0; i<=words.length-16; i+=16) {
+ s.block(words.slice(i,i+16));
+ }
+ s.length = i << 5; // so don't pass this function more than 128M words
+ if (i<words.length)
+ s.update_words_little_endian(words.slice(i));
+ return s.finalize();
+}
+
+SHA256.hash_words_little_endian = function(words) {
+ var w = words.slice(0);
+ for (var i=0; i<w.length; i++) {
+ w[i] = w[i] >>> 16 ^ w[i] << 16;
+ w[i] = ((w[i]>>>8) & 0xFF00FF) ^ ((w[i]<<8) & 0xFF00FF00);
+ }
+ return SHA256.hash_words_big_endian(w);
+}
+
+
+
+
+
+
+
+/*
+
+ jsCrypto
+
+ * Random.js -- cryptographic random number generator
+ * Mike Hamburg, 2008. Public domain.
+ *
+ * This generator uses a modified version of Fortuna. Fortuna has
+ * excellent resilience to compromise, relies on a state file, and is
+ * intended to run for a long time. As such, it does not need an
+ * entropy estimator. Unfortunately, Fortuna's startup in low-entropy
+ * conditions leaves much to be desired.
+ *
+ * This generator features the following modifications. First, the
+ * generator does not create the n-th entropy pool until it exhausts
+ * the n-1-st. This means that entropy doesn't get "stuck" in pools
+ * 10-31, which will never be used on a typical webpage. It also
+ * means that the entropy will all go into a single pool until the
+ * generator is seeded.
+ *
+ * Second, there is a very crude entropy estimator. The primary goal
+ * of this estimator is to prevent the generator from being used in
+ * low-entropy situations. Corresponding to this entropy estimator,
+ * there is a "paranoia control". This controls how many bits of
+ * estimated entropy must be present before the generator is used.
+ * The generator cannot have more than 256 bits of actual entropy in
+ * the main pool; rather, the paranoia control is designed to deal
+ * with the fact that the entropy estimator is probably horrible.
+ *
+ * Third, the "statefile" is optional and stored in a cookie. As
+ * such, it is not protected from multiple simultaneous usage, and so
+ * is treated conservatively.
+ */
+
+Random = {
+ /* public */
+NOT_READY: 0,
+READY: 1,
+REQUIRES_RESEED: 2,
+
+ /* generate one random word */
+random_word: function(paranoia) {
+ return this.random_words(1, paranoia)[0];
+},
+
+ /* generate nwords random words, and return them in an array */
+random_words: function(nwords, paranoia) {
+ var out = [], i, readiness = this.is_ready(paranoia);
+
+ if (readiness == this.NOT_READY)
+ throw("Random: generator isn't seeded!");
+
+ else if (readiness && this.REQUIRES_RESEED)
+ this._reseed_from_pools(!(readiness & this.READY));
+
+ for (i=0; i<nwords; i+= 4) {
+ if ((i+1) % this._max_words_per_burst == 0)
+ this._gate();
+
+ var g = this._gen_4_words();
+ out.push(g[0],g[1],g[2],g[3]);
+ }
+ this._gate();
+
+ return out.slice(0,nwords);
+},
+
+set_default_paranoia: function(paranoia) {
+ this._default_paranoia = paranoia;
+},
+
+ /* Add entropy to the pools. Pass data as an array, number or
+ * string. Pass estimated_entropy in bits. Pass the source as a
+ * number or string.
+ */
+add_entropy: function(data, estimated_entropy, source) {
+ source = source || "user";
+
+ var id = this._collector_ids[source] ||
+ (this._collector_ids[source] = this._collector_id_next ++);
+
+ var i, ty = 0;
+
+ var t = new Date().valueOf();
+
+ var robin = this._robins[source];
+ if (robin == undefined) robin = this._robins[source] = 0;
+ this._robins[source] = ( this._robins[source] + 1 ) % this._pools.length;
+
+ switch(typeof(data)) {
+
+ case "number":
+ data=[data];
+ ty=1;
+ break;
+
+ case "object":
+ if (!estimated_entropy) {
+ /* horrible entropy estimator */
+ estimated_entropy = 0;
+ for (i=0; i<data.length; i++) {
+ var x = data[i];
+ while (x>0) {
+ estimated_entropy++;
+ x = x >>> 1;
+ }
+ }
+ }
+ this._pools[robin].update_words_big_endian([id,this._event_id++,ty||2,estimated_entropy,t,data.length].concat(data));
+ break;
+
+ case "string":
+ if (!estimated_entropy) {
+ /* English text has just over 1 bit per character of entropy.
+ * But this might be HTML or something, and have far less
+ * entropy than English... Oh well, let's just say one bit.
+ */
+ estimated_entropy = data.length;
+ }
+ this._pools[robin].update_words_big_endian([id,this._event_id++,3,estimated_entropy,t,data.length])
+ this._pools[robin].update_string(data);
+ break;
+
+ default:
+ throw "add_entropy: must give an array, number or string"
+ }
+
+ var old_ready = this.is_ready();
+
+ /* record the new strength */
+ this._pool_entropy[robin] += estimated_entropy;
+ this._pool_strength += estimated_entropy;
+
+ /* fire off events */
+ if (!old_ready && this.is_ready())
+ this._fire_event("seeded", Math.max(this._strength, this._pool_strength));
+
+ if (!old_ready)
+ this._fire_event("progress", this.get_progress());
+},
+
+ /* is the generator ready? */
+is_ready: function(paranoia) {
+ var entropy_required = this._PARANOIA_LEVELS[ paranoia ? paranoia : this._default_paranoia ];
+
+ if (this._strength >= entropy_required) {
+ return (this._pool_entropy[0] > this._BITS_PER_RESEED && new Date.valueOf() > this._next_reseed) ?
+ this.REQUIRES_RESEED | this.READY :
+ this.READY;
+ } else {
+ return (this._pool_strength > entropy_required) ?
+ this.REQUIRES_RESEED | this.NOT_READY :
+ this.NOT_READY;
+ }
+},
+
+ /* how close to ready is it? */
+get_progress: function(paranoia) {
+ var entropy_required = this._PARANOIA_LEVELS[ paranoia ? paranoia : this._default_paranoia ];
+
+ if (this._strength >= entropy_required) {
+ return 1.0;
+ } else {
+ return (this._pool_strength > entropy_required) ?
+ 1.0 :
+ this._pool_strength / entropy_required;
+ }
+},
+
+ /* start the built-in entropy collectors */
+start_collectors: function() {
+ if (this._collectors_started) return;
+
+ if (window.addEventListener) {
+ window.addEventListener("load", this._load_time_collector, false);
+ window.addEventListener("mousemove", this._mouse_collector, false);
+ } else if (document.attachEvent) {
+ document.attachEvent("onload", this._load_time_collector);
+ document.attachEvent("onmousemove", this._mouse_collector);
+ }
+ else throw("can't attach event");
+
+ this._collectors_started = true;
+},
+
+ /* stop the built-in entropy collectors */
+stop_collectors: function() {
+ if (!this._collectors_started) return;
+
+ if (window.removeEventListener) {
+ window.removeEventListener("load", this._load_time_collector);
+ window.removeEventListener("mousemove", this._mouse_collector);
+ } else if (window.detachEvent) {
+ window.detachEvent("onload", this._load_time_collector);
+ window.detachEvent("onmousemove", this._mouse_collector)
+ }
+ this._collectors_started = false;
+},
+
+use_cookie: function(all_cookies) {
+ throw "TODO: implement use_cookie";
+},
+
+ /* add an event listener for progress or seeded-ness */
+addEventListener: function(name, callback) {
+ this._callbacks[name][this._callback_i++] = callback;
+},
+
+ /* remove an event listener for progress or seeded-ness */
+removeEventListener: function(name, cb) {
+ var i, j, cbs=this._callbacks[name], js_temp=[];
+
+ /* I'm not sure if this is necessary; in C++, iterating over a
+ * collection and modifying it at the same time is a no-no.
+ */
+
+ for (j in cbs)
+ if (cbs.hasOwnProperty[j] && cbs[j] === cb)
+ js_temp.push(j);
+
+ for (i=0; i<js_temp.length; i++) {
+ j = js[i];
+ delete cbs[j];
+ }
+},
+
+ /* private */
+ _pools : [new SHA256()],
+ _pool_entropy : [0],
+ _reseed_count : 0,
+ _robins : {},
+ _event_id : 0,
+
+ _collector_ids : {},
+ _collector_id_next : 0,
+
+ _strength : 0,
+ _pool_strength : 0,
+ _next_reseed : 0,
+ _key : [0,0,0,0,0,0,0,0],
+ _counter : [0,0,0,0],
+ _cipher : undefined,
+ _default_paranoia : 6,
+
+ /* event listener stuff */
+ _collectors_started : false,
+ _callbacks : {progress: {}, seeded: {}},
+ _callback_i : 0,
+
+ /* constants */
+ _MAX_WORDS_PER_BURST : 65536,
+ _PARANOIA_LEVELS : [0,48,64,96,128,192,256,384,512,768,1024],
+ _MILLISECONDS_PER_RESEED : 100,
+ _BITS_PER_RESEED : 80,
+
+ /* generate 4 random words, no reseed, no gate */
+_gen_4_words: function() {
+ var words = [];
+ for (var i=0; i<3; i++) if (++this._counter[i]) break;
+ this._cipher.encryptBlock(this._counter, words);
+ return words;
+},
+
+ /* rekey the AES instance with itself after a request, or every _MAX_WORDS_PER_BURST words */
+_gate: function() {
+ this._key = this._gen_4_words().concat(this._gen_4_words());
+ this._cipher = new aes(this._key);
+},
+
+ /* reseed the generator with the given words */
+_reseed: function(seedWords) {
+ this._key = SHA256.hash_words_big_endian(this._key.concat(seedWords));
+ this._cipher = new aes(this._key);
+ for (var i=0; i<3; i++) if (++this._counter[i]) break;
+},
+
+ /* reseed the data from the entropy pools */
+_reseed_from_pools: function(full) {
+ var reseed_data = [], strength = 0;
+
+ this._next_reseed = new Date().valueOf() + this._MILLISECONDS_PER_RESEED;
+
+ for (i=0; i<this._pools.length; i++) {
+ reseed_data = reseed_data.concat(this._pools[i].finalize());
+ strength += this._pool_entropy[i];
+ this._pool_entropy[i] = 0;
+
+ if (!full && (this._reseed_count & (1<<i))) break;
+ }
+
+ /* if we used the last pool, push a new one onto the stack */
+ if (this._reseed_count >= 1 << this._pools.length) {
+ this._pools.push(new SHA256());
+ this._pool_entropy.push(0);
+ }
+
+ /* how strong was this reseed? */
+ this._pool_strength -= strength;
+ if (strength > this._strength) this._strength = strength;
+
+ this._reseed_count ++;
+ this._reseed(reseed_data);
+},
+
+_mouse_collector: function(ev) {
+ var x = ev.x || ev.clientX || ev.offsetX;
+ var y = ev.y || ev.clientY || ev.offsetY;
+ Random.add_entropy([x,y], 2, "mouse");
+},
+
+_load_time_collector: function(ev) {
+ var d = new Date();
+ Random.add_entropy(d, 2, "loadtime");
+},
+
+_fire_event: function(name, arg) {
+ var j, cbs=Random._callbacks[name], cbs_temp=[];
+
+ /* I'm not sure if this is necessary; in C++, iterating over a
+ * collection and modifying it at the same time is a no-no.
+ */
+
+ for (j in cbs) {
+ if (cbs.hasOwnProperty(j)) {
+ cbs_temp.push(cbs[j]);
+ }
+ }
+
+ for (j=0; j<cbs_temp.length; j++) {
+ cbs_temp[j](arg);
+ }
+}
+};
+