summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js
Unidiff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js
new file mode 100644
index 0000000..f753747
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js
@@ -0,0 +1,85 @@
1/*
2
3Copyright 2008-2013 Clipperz Srl
4
5This file is part of Clipperz, the online password manager.
6For further information about its features and functionalities please
7refer to http://www.clipperz.com.
8
9* Clipperz is free software: you can redistribute it and/or modify it
10 under the terms of the GNU Affero General Public License as published
11 by the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14* Clipperz is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU Affero General Public License for more details.
18
19* You should have received a copy of the GNU Affero General Public
20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
21
22*/
23
24function testEncryptedData (tool, keyValue, encryptedText, expectedCleanText, someTestArgs) {
25 key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(keyValue));
26 value = new Clipperz.ByteArray().appendBase64String(encryptedText);
27
28 deferredResult = new Clipperz.Async.Deferred("pythonCompatibility_test", someTestArgs);
29 deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value);
30 deferredResult.addCallback(function(aResult) {
31 return aResult.asString();
32 });
33 deferredResult.addTest(expectedCleanText, tool);
34 deferredResult.callback();
35
36 return deferredResult;
37}
38
39//=============================================================================
40
41var tests = {
42
43 'incrementNonce_test': function (someTestArgs) {
44 var nonce;
45
46 nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
47 Clipperz.Crypto.AES_2.incrementNonce(nonce)
48 SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "increment 0 based nonce");
49
50 nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
51 Clipperz.Crypto.AES_2.incrementNonce(nonce)
52 SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], "increment '1' nonce");
53
54 nonce = [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,89]
55 Clipperz.Crypto.AES_2.incrementNonce(nonce)
56 SimpleTest.eq(nonce, [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,90], "increment '1' nonce");
57 return
58 },
59
60 'pythonCompatibility_test': function (someTestArgs) {
61 var keyValue = "clipperz"
62 var cleanText = "Lorem īpsum dōlōr siÞ ǽmēt, stet voluptatum ei eum, quō pērfecto lobortis eā, vel ċu deserūisse comprehēƿsam. Eu sed cībō veniam effīciendi, Þe legere ðominġ est, ðuō ċu saperet inermis pērfeċto. Vim ei essent consetētūr, quo etīam saepē æpeirian in, et atqūi velīÞ sǣepe his? Æn porrō putanÞ sinġulis mei, ēx sonet noster mea, tē alterum praesent percipitur qūo. ViÞaē neċessitatibus ne vim, per ex communē sentēntiǣe! Qui stet ǽdhūċ uÞ."
63
64 // def testEncrypt (keyValue, cleanText):
65 // key = keyDerivation(keyValue)
66 // iv = random.getrandbits(128)
67 // ctr = Crypto.Util.Counter.new(128, initial_value=iv)
68 // cipher = AES.new(key, Crypto.Cipher.AES.MODE_CTR, counter=ctr)
69 // encryptedValue = cipher.encrypt(cleanText.encode('utf-8'))
70 // data = base64.b64encode(base64.b16decode(hex(iv).upper()[2:-1]) + encryptedValue)
71 //
72 // return data
73
74 var pythonEncryptedData = "9AFIXRO2nY0mkLJI6Xd4bd+Ov1g+kYUh73nICEVUM8OGt5FnfV/w2BfmTvdMGZjs+rF8w0ksrS9Ny8j2+2zPUUrKnVRXO6eGVPSN5VfuYFSHucV98msINH0FpOZHftuKCuJkB/orjQhoIbj9SXT0yUwB3b4R2bk48Br7R8G2bhxqrHRmnYQn22AQVA83UstNvCOdXT7ArfwJZbVSSMkdmvcziZ8ObMvaH+FXD/K8i7dzS1yP03MMBtIkYN8PnyUMS2uAHKiR11jGuha9QfXjLJlWUQWZgNB9NKyOKf7tN+OgtAoWmHmKlpTshfwbfFD8wBPR0kkhR0cC+7queIjpCDnBJ+Nod78zWgPDR8g64sph7OB686HkP03cO66aH/LNuAt03gxaVyE8ufvoStRjlIthOuys5xYWP+hTFYDC7OhCOLKvhZoY4Tr/FP+TjporX3ivCJUEEvwvXeftAxFVRl4JDin0ys0iPTQ7QlbtVa+iep2n9FUG1NOn5boD9y+iw64UJAcex4MqEIdpCHne9LjpiqshcwLmfEeLlFab28LHnvYPGkXDrSRjCujx8ZmmTw96sAIDqER8p1AqaSojwvONYBGrq+f5/f4xjzZJAknMmxYEN14Phbxc8WEhpe5omWdB80C1Kv6CLsoQnGAIshURSZryToXL"
75 return testEncryptedData("python", keyValue, pythonEncryptedData, cleanText, someTestArgs)
76 },
77
78 //-------------------------------------------------------------------------
79 'syntaxFix': MochiKit.Base.noop
80}
81
82//=============================================================================
83
84Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
85SimpleTest.runDeferredTests("Clipperz.Crypto.AES_2", tests, {trace:false});