Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/Base.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/Crypto/Base.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/Base.js b/frontend/beta/js/Clipperz/Crypto/Base.js index d3a8e36..9acfc49 100644 --- a/frontend/beta/js/Clipperz/Crypto/Base.js +++ b/frontend/beta/js/Clipperz/Crypto/Base.js | |||
@@ -1,86 +1,84 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | try { if (typeof(Clipperz.Base) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.Base) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.Crypto.Base depends on Clipperz.Base!"; | 25 | throw "Clipperz.Crypto.Base depends on Clipperz.Base!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } | 28 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } |
31 | if (typeof(Clipperz.Crypto.Base) == 'undefined') { Clipperz.Crypto.Base = {}; } | 29 | if (typeof(Clipperz.Crypto.Base) == 'undefined') { Clipperz.Crypto.Base = {}; } |
32 | 30 | ||
33 | Clipperz.Crypto.Base.VERSION = "0.1"; | 31 | Clipperz.Crypto.Base.VERSION = "0.1"; |
34 | Clipperz.Crypto.Base.NAME = "Clipperz.Crypto.Base"; | 32 | Clipperz.Crypto.Base.NAME = "Clipperz.Crypto.Base"; |
35 | 33 | ||
36 | //############################################################################# | 34 | //############################################################################# |
37 | //Downloaded on March 30, 2006 from http://anmar.eu.org/projects/jssha2/files/jssha2-0.3.zip (jsSha2/sha256.js) | 35 | //Downloaded on March 30, 2006 from http://anmar.eu.org/projects/jssha2/files/jssha2-0.3.zip (jsSha2/sha256.js) |
38 | //############################################################################# | 36 | //############################################################################# |
39 | 37 | ||
40 | /* A JavaScript implementation of the Secure Hash Algorithm, SHA-256 | 38 | /* A JavaScript implementation of the Secure Hash Algorithm, SHA-256 |
41 | * Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/ | 39 | * Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/ |
42 | * Distributed under the BSD License | 40 | * Distributed under the BSD License |
43 | * Some bits taken from Paul Johnston's SHA-1 implementation | 41 | * Some bits taken from Paul Johnston's SHA-1 implementation |
44 | */ | 42 | */ |
45 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ | 43 | var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ |
46 | function safe_add (x, y) { | 44 | function safe_add (x, y) { |
47 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); | 45 | var lsw = (x & 0xFFFF) + (y & 0xFFFF); |
48 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); | 46 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16); |
49 | return (msw << 16) | (lsw & 0xFFFF); | 47 | return (msw << 16) | (lsw & 0xFFFF); |
50 | } | 48 | } |
51 | function S (X, n) {return ( X >>> n ) | (X << (32 - n));} | 49 | function S (X, n) {return ( X >>> n ) | (X << (32 - n));} |
52 | function R (X, n) {return ( X >>> n );} | 50 | function R (X, n) {return ( X >>> n );} |
53 | function Ch(x, y, z) {return ((x & y) ^ ((~x) & z));} | 51 | function Ch(x, y, z) {return ((x & y) ^ ((~x) & z));} |
54 | function Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));} | 52 | function Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));} |
55 | function Sigma0256(x) {return (S(x, 2) ^ S(x, 13) ^ S(x, 22));} | 53 | function Sigma0256(x) {return (S(x, 2) ^ S(x, 13) ^ S(x, 22));} |
56 | function Sigma1256(x) {return (S(x, 6) ^ S(x, 11) ^ S(x, 25));} | 54 | function Sigma1256(x) {return (S(x, 6) ^ S(x, 11) ^ S(x, 25));} |
57 | function Gamma0256(x) {return (S(x, 7) ^ S(x, 18) ^ R(x, 3));} | 55 | function Gamma0256(x) {return (S(x, 7) ^ S(x, 18) ^ R(x, 3));} |
58 | function Gamma1256(x) {return (S(x, 17) ^ S(x, 19) ^ R(x, 10));} | 56 | function Gamma1256(x) {return (S(x, 17) ^ S(x, 19) ^ R(x, 10));} |
59 | function core_sha256 (m, l) { | 57 | function core_sha256 (m, l) { |
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); | 58 | 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); |
61 | var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19); | 59 | var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19); |
62 | var W = new Array(64); | 60 | var W = new Array(64); |
63 | var a, b, c, d, e, f, g, h, i, j; | 61 | var a, b, c, d, e, f, g, h, i, j; |
64 | var T1, T2; | 62 | var T1, T2; |
65 | /* append padding */ | 63 | /* append padding */ |
66 | m[l >> 5] |= 0x80 << (24 - l % 32); | 64 | m[l >> 5] |= 0x80 << (24 - l % 32); |
67 | m[((l + 64 >> 9) << 4) + 15] = l; | 65 | m[((l + 64 >> 9) << 4) + 15] = l; |
68 | for ( var i = 0; i<m.length; i+=16 ) { | 66 | for ( var i = 0; i<m.length; i+=16 ) { |
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]; | 67 | a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7]; |
70 | for ( var j = 0; j<64; j++) { | 68 | for ( var j = 0; j<64; j++) { |
71 | if (j < 16) W[j] = m[j + i]; | 69 | if (j < 16) W[j] = m[j + i]; |
72 | else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]); | 70 | else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]); |
73 | T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]); | 71 | T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]); |
74 | T2 = safe_add(Sigma0256(a), Maj(a, b, c)); | 72 | T2 = safe_add(Sigma0256(a), Maj(a, b, c)); |
75 | h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2); | 73 | h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2); |
76 | } | 74 | } |
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]); | 75 | 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]); |
78 | } | 76 | } |
79 | return HASH; | 77 | return HASH; |
80 | } | 78 | } |
81 | function str2binb (str) { | 79 | function str2binb (str) { |
82 | var bin = Array(); | 80 | var bin = Array(); |
83 | var mask = (1 << chrsz) - 1; | 81 | var mask = (1 << chrsz) - 1; |
84 | for(var i = 0; i < str.length * chrsz; i += chrsz) | 82 | for(var i = 0; i < str.length * chrsz; i += chrsz) |
85 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32); | 83 | bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32); |
86 | return bin; | 84 | return bin; |