Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/Base.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/Base.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/Base.js b/frontend/gamma/js/Clipperz/Crypto/Base.js index b69dcc8..d3a8e36 100644 --- a/frontend/gamma/js/Clipperz/Crypto/Base.js +++ b/frontend/gamma/js/Clipperz/Crypto/Base.js | |||
@@ -1,120 +1,117 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer to http://www.clipperz.com. |
12 | 9 | ||
13 | * Javascript Crypto Library is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
14 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
15 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
16 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
17 | 14 | ||
18 | * Javascript Crypto Library is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
22 | 19 | ||
23 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
24 | License along with Javascript Crypto Library. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
25 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
26 | 23 | ||
27 | */ | 24 | */ |
28 | 25 | ||
29 | try { if (typeof(Clipperz.Base) == 'undefined') { throw ""; }} catch (e) { | 26 | try { if (typeof(Clipperz.Base) == 'undefined') { throw ""; }} catch (e) { |
30 | throw "Clipperz.Crypto.Base depends on Clipperz.Base!"; | 27 | throw "Clipperz.Crypto.Base depends on Clipperz.Base!"; |
31 | } | 28 | } |
32 | 29 | ||
33 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } | 30 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } |
34 | if (typeof(Clipperz.Crypto.Base) == 'undefined') { Clipperz.Crypto.Base = {}; } | 31 | if (typeof(Clipperz.Crypto.Base) == 'undefined') { Clipperz.Crypto.Base = {}; } |
35 | 32 | ||
36 | Clipperz.Crypto.Base.VERSION = "0.1"; | 33 | Clipperz.Crypto.Base.VERSION = "0.1"; |
37 | Clipperz.Crypto.Base.NAME = "Clipperz.Crypto.Base"; | 34 | Clipperz.Crypto.Base.NAME = "Clipperz.Crypto.Base"; |
38 | 35 | ||
39 | //############################################################################# | 36 | //############################################################################# |
40 | //Downloaded on March 30, 2006 from http://anmar.eu.org/projects/jssha2/files/jssha2-0.3.zip (jsSha2/sha256.js) | 37 | //Downloaded on March 30, 2006 from http://anmar.eu.org/projects/jssha2/files/jssha2-0.3.zip (jsSha2/sha256.js) |
41 | //############################################################################# | 38 | //############################################################################# |
42 | 39 | ||
43 | /* A JavaScript implementation of the Secure Hash Algorithm, SHA-256 | 40 | /* A JavaScript implementation of the Secure Hash Algorithm, SHA-256 |
44 | * Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/ | 41 | * Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/ |
45 | * Distributed under the BSD License | 42 | * Distributed under the BSD License |
46 | * Some bits taken from Paul Johnston's SHA-1 implementation | 43 | * Some bits taken from Paul Johnston's SHA-1 implementation |
47 | */ | 44 | */ |
48 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ | 45 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ |
49 | function safe_add (x, y) { | 46 | function safe_add (x, y) { |
50 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); | 47 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); |
51 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); | 48 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); |
52 | return (msw << 16) | (lsw & 0xFFFF); | 49 | return (msw << 16) | (lsw & 0xFFFF); |
53 | } | 50 | } |
54 | function S (X, n) {return ( X >>> n ) | (X << (32 - n));} | 51 | function S (X, n) {return ( X >>> n ) | (X << (32 - n));} |
55 | function R (X, n) {return ( X >>> n );} | 52 | function R (X, n) {return ( X >>> n );} |
56 | function Ch(x, y, z) {return ((x & y) ^ ((~x) & z));} | 53 | function Ch(x, y, z) {return ((x & y) ^ ((~x) & z));} |
57 | function Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));} | 54 | function Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));} |
58 | function Sigma0256(x) {return (S(x, 2) ^ S(x, 13) ^ S(x, 22));} | 55 | function Sigma0256(x) {return (S(x, 2) ^ S(x, 13) ^ S(x, 22));} |
59 | function Sigma1256(x) {return (S(x, 6) ^ S(x, 11) ^ S(x, 25));} | 56 | function Sigma1256(x) {return (S(x, 6) ^ S(x, 11) ^ S(x, 25));} |
60 | function Gamma0256(x) {return (S(x, 7) ^ S(x, 18) ^ R(x, 3));} | 57 | function Gamma0256(x) {return (S(x, 7) ^ S(x, 18) ^ R(x, 3));} |
61 | function Gamma1256(x) {return (S(x, 17) ^ S(x, 19) ^ R(x, 10));} | 58 | function Gamma1256(x) {return (S(x, 17) ^ S(x, 19) ^ R(x, 10));} |
62 | function core_sha256 (m, l) { | 59 | function core_sha256 (m, l) { |
63 | var K = new Array(0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,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); | 60 | var K = new Array(0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,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); |
64 | var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19); | 61 | var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19); |
65 | var W = new Array(64); | 62 | var W = new Array(64); |
66 | var a, b, c, d, e, f, g, h, i, j; | 63 | var a, b, c, d, e, f, g, h, i, j; |
67 | var T1, T2; | 64 | var T1, T2; |
68 | /* append padding */ | 65 | /* append padding */ |
69 | m[l >> 5] |= 0x80 << (24 - l % 32); | 66 | m[l >> 5] |= 0x80 << (24 - l % 32); |
70 | m[((l + 64 >> 9) << 4) + 15] = l; | 67 | m[((l + 64 >> 9) << 4) + 15] = l; |
71 | for ( var i = 0; i<m.length; i+=16 ) { | 68 | for ( var i = 0; i<m.length; i+=16 ) { |
72 | a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7]; | 69 | a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7]; |
73 | for ( var j = 0; j<64; j++) { | 70 | for ( var j = 0; j<64; j++) { |
74 | if (j < 16) W[j] = m[j + i]; | 71 | if (j < 16) W[j] = m[j + i]; |
75 | else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]); | 72 | else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]); |
76 | T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]); | 73 | T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]); |
77 | T2 = safe_add(Sigma0256(a), Maj(a, b, c)); | 74 | T2 = safe_add(Sigma0256(a), Maj(a, b, c)); |
78 | h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2); | 75 | h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2); |
79 | } | 76 | } |
80 | HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]); HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]); HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]); HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]); | 77 | HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]); HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]); HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]); HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]); |
81 | } | 78 | } |
82 | return HASH; | 79 | return HASH; |
83 | } | 80 | } |
84 | function str2binb (str) { | 81 | function str2binb (str) { |
85 | var bin = Array(); | 82 | var bin = Array(); |
86 | var mask = (1 << chrsz) - 1; | 83 | var mask = (1 << chrsz) - 1; |
87 | for(var i = 0; i < str.length * chrsz; i += chrsz) | 84 | for(var i = 0; i < str.length * chrsz; i += chrsz) |
88 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32); | 85 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32); |
89 | return bin; | 86 | return bin; |
90 | } | 87 | } |
91 | function binb2hex (binarray) { | 88 | function binb2hex (binarray) { |
92 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ | 89 | var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ |
93 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; | 90 | var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; |
94 | var str = ""; | 91 | var str = ""; |
95 | for (var i = 0; i < binarray.length * 4; i++) { | 92 | for (var i = 0; i < binarray.length * 4; i++) { |
96 | str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF); | 93 | str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF); |
97 | } | 94 | } |
98 | return str; | 95 | return str; |
99 | } | 96 | } |
100 | function hex_sha256(s){return binb2hex(core_sha256(str2binb(s),s.length * chrsz));} | 97 | function hex_sha256(s){return binb2hex(core_sha256(str2binb(s),s.length * chrsz));} |
101 | 98 | ||
102 | 99 | ||
103 | 100 | ||
104 | //############################################################################# | 101 | //############################################################################# |
105 | //Downloaded on March 30, 2006 from http://www.fourmilab.ch/javascrypt/javascrypt.zip (entropy.js) | 102 | //Downloaded on March 30, 2006 from http://www.fourmilab.ch/javascrypt/javascrypt.zip (entropy.js) |
106 | //############################################################################# | 103 | //############################################################################# |
107 | 104 | ||
108 | // Entropy collection utilities | 105 | // Entropy collection utilities |
109 | 106 | ||
110 | /*Start by declaring static storage and initialise | 107 | /*Start by declaring static storage and initialise |
111 | the entropy vector from the time we come through | 108 | the entropy vector from the time we come through |
112 | here. */ | 109 | here. */ |
113 | 110 | ||
114 | var entropyData = new Array(); // Collected entropy data | 111 | var entropyData = new Array(); // Collected entropy data |
115 | var edlen = 0; // Keyboard array data length | 112 | var edlen = 0; // Keyboard array data length |
116 | 113 | ||
117 | addEntropyTime(); // Start entropy collection with page load time | 114 | addEntropyTime(); // Start entropy collection with page load time |
118 | ce(); // Roll milliseconds into initial entropy | 115 | ce(); // Roll milliseconds into initial entropy |
119 | 116 | ||
120 | //Add a byte to the entropy vector | 117 | //Add a byte to the entropy vector |