summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Crypto/AES.html
Side-by-side diff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto/AES.html') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/AES.html292
1 files changed, 292 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES.html b/frontend/gamma/tests/tests/Clipperz/Crypto/AES.html
new file mode 100644
index 0000000..93089b7
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES.html
@@ -0,0 +1,292 @@
+<!--
+
+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>