Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/AES.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/Crypto/AES.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/AES.js b/frontend/beta/js/Clipperz/Crypto/AES.js index a60df5c..7ddda3e 100644 --- a/frontend/beta/js/Clipperz/Crypto/AES.js +++ b/frontend/beta/js/Clipperz/Crypto/AES.js | |||
@@ -1,216 +1,213 @@ | |||
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.ByteArray) == 'undefined') { throw ""; }} catch (e) { | 26 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { |
30 | throw "Clipperz.Crypto.AES depends on Clipperz.ByteArray!"; | 27 | throw "Clipperz.Crypto.AES depends on Clipperz.ByteArray!"; |
31 | } | 28 | } |
32 | 29 | ||
33 | //Dependency commented to avoid a circular reference | 30 | //Dependency commented to avoid a circular reference |
34 | //try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { | 31 | //try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { |
35 | //throw "Clipperz.Crypto.AES depends on Clipperz.Crypto.PRNG!"; | 32 | //throw "Clipperz.Crypto.AES depends on Clipperz.Crypto.PRNG!"; |
36 | //} | 33 | //} |
37 | 34 | ||
38 | if (typeof(Clipperz.Crypto.AES) == 'undefined') { Clipperz.Crypto.AES = {}; } | 35 | if (typeof(Clipperz.Crypto.AES) == 'undefined') { Clipperz.Crypto.AES = {}; } |
39 | 36 | ||
40 | //############################################################################# | 37 | //############################################################################# |
41 | 38 | ||
42 | Clipperz.Crypto.AES.DeferredExecutionContext = function(args) { | 39 | Clipperz.Crypto.AES.DeferredExecutionContext = function(args) { |
43 | args = args || {}; | 40 | args = args || {}; |
44 | 41 | ||
45 | this._key = args.key; | 42 | this._key = args.key; |
46 | this._message = args.message; | 43 | this._message = args.message; |
47 | this._result = args.message.clone(); | 44 | this._result = args.message.clone(); |
48 | this._nonce = args.nonce; | 45 | this._nonce = args.nonce; |
49 | this._messageLength = this._message.length(); | 46 | this._messageLength = this._message.length(); |
50 | 47 | ||
51 | this._messageArray = this._message.arrayValues(); | 48 | this._messageArray = this._message.arrayValues(); |
52 | this._resultArray = this._result.arrayValues(); | 49 | this._resultArray = this._result.arrayValues(); |
53 | this._nonceArray = this._nonce.arrayValues(); | 50 | this._nonceArray = this._nonce.arrayValues(); |
54 | 51 | ||
55 | this._executionStep = 0; | 52 | this._executionStep = 0; |
56 | 53 | ||
57 | return this; | 54 | return this; |
58 | } | 55 | } |
59 | 56 | ||
60 | Clipperz.Crypto.AES.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { | 57 | Clipperz.Crypto.AES.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { |
61 | 58 | ||
62 | 'key': function() { | 59 | 'key': function() { |
63 | return this._key; | 60 | return this._key; |
64 | }, | 61 | }, |
65 | 62 | ||
66 | 'message': function() { | 63 | 'message': function() { |
67 | return this._message; | 64 | return this._message; |
68 | }, | 65 | }, |
69 | 66 | ||
70 | 'messageLength': function() { | 67 | 'messageLength': function() { |
71 | return this._messageLength; | 68 | return this._messageLength; |
72 | }, | 69 | }, |
73 | 70 | ||
74 | 'result': function() { | 71 | 'result': function() { |
75 | return new Clipperz.ByteArray(this.resultArray()); | 72 | return new Clipperz.ByteArray(this.resultArray()); |
76 | }, | 73 | }, |
77 | 74 | ||
78 | 'nonce': function() { | 75 | 'nonce': function() { |
79 | return this._nonce; | 76 | return this._nonce; |
80 | }, | 77 | }, |
81 | 78 | ||
82 | 'messageArray': function() { | 79 | 'messageArray': function() { |
83 | return this._messageArray; | 80 | return this._messageArray; |
84 | }, | 81 | }, |
85 | 82 | ||
86 | 'resultArray': function() { | 83 | 'resultArray': function() { |
87 | return this._resultArray; | 84 | return this._resultArray; |
88 | }, | 85 | }, |
89 | 86 | ||
90 | 'nonceArray': function() { | 87 | 'nonceArray': function() { |
91 | return this._nonceArray; | 88 | return this._nonceArray; |
92 | }, | 89 | }, |
93 | 90 | ||
94 | 'elaborationChunkSize': function() { | 91 | 'elaborationChunkSize': function() { |
95 | return Clipperz.Crypto.AES.DeferredExecution.chunkSize; | 92 | return Clipperz.Crypto.AES.DeferredExecution.chunkSize; |
96 | }, | 93 | }, |
97 | 94 | ||
98 | 'executionStep': function() { | 95 | 'executionStep': function() { |
99 | return this._executionStep; | 96 | return this._executionStep; |
100 | }, | 97 | }, |
101 | 98 | ||
102 | 'setExecutionStep': function(aValue) { | 99 | 'setExecutionStep': function(aValue) { |
103 | this._executionStep = aValue; | 100 | this._executionStep = aValue; |
104 | }, | 101 | }, |
105 | 102 | ||
106 | 'pause': function(aValue) { | 103 | 'pause': function(aValue) { |
107 | return MochiKit.Async.wait(Clipperz.Crypto.AES.DeferredExecution.pauseTime, aValue); | 104 | return MochiKit.Async.wait(Clipperz.Crypto.AES.DeferredExecution.pauseTime, aValue); |
108 | }, | 105 | }, |
109 | 106 | ||
110 | //----------------------------------------------------------------------------- | 107 | //----------------------------------------------------------------------------- |
111 | __syntaxFix__: "syntax fix" | 108 | __syntaxFix__: "syntax fix" |
112 | 109 | ||
113 | }); | 110 | }); |
114 | 111 | ||
115 | //############################################################################# | 112 | //############################################################################# |
116 | 113 | ||
117 | Clipperz.Crypto.AES.Key = function(args) { | 114 | Clipperz.Crypto.AES.Key = function(args) { |
118 | args = args || {}; | 115 | args = args || {}; |
119 | 116 | ||
120 | this._key = args.key; | 117 | this._key = args.key; |
121 | this._keySize = args.keySize || this.key().length(); | 118 | this._keySize = args.keySize || this.key().length(); |
122 | 119 | ||
123 | if (this.keySize() == 128/8) { | 120 | if (this.keySize() == 128/8) { |
124 | this._b = 176; | 121 | this._b = 176; |
125 | this._numberOfRounds = 10; | 122 | this._numberOfRounds = 10; |
126 | } else if (this.keySize() == 256/8) { | 123 | } else if (this.keySize() == 256/8) { |
127 | this._b = 240; | 124 | this._b = 240; |
128 | this._numberOfRounds = 14; | 125 | this._numberOfRounds = 14; |
129 | } else { | 126 | } else { |
130 | MochiKit.Logging.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); | 127 | MochiKit.Logging.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); |
131 | throw Clipperz.Crypto.AES.exception.UnsupportedKeySize; | 128 | throw Clipperz.Crypto.AES.exception.UnsupportedKeySize; |
132 | } | 129 | } |
133 | 130 | ||
134 | this._stretchedKey = null; | 131 | this._stretchedKey = null; |
135 | 132 | ||
136 | return this; | 133 | return this; |
137 | } | 134 | } |
138 | 135 | ||
139 | Clipperz.Crypto.AES.Key.prototype = MochiKit.Base.update(null, { | 136 | Clipperz.Crypto.AES.Key.prototype = MochiKit.Base.update(null, { |
140 | 137 | ||
141 | 'asString': function() { | 138 | 'asString': function() { |
142 | return "Clipperz.Crypto.AES.Key (" + this.key().toHexString() + ")"; | 139 | return "Clipperz.Crypto.AES.Key (" + this.key().toHexString() + ")"; |
143 | }, | 140 | }, |
144 | 141 | ||
145 | //----------------------------------------------------------------------------- | 142 | //----------------------------------------------------------------------------- |
146 | 143 | ||
147 | 'key': function() { | 144 | 'key': function() { |
148 | return this._key; | 145 | return this._key; |
149 | }, | 146 | }, |
150 | 147 | ||
151 | 'keySize': function() { | 148 | 'keySize': function() { |
152 | return this._keySize; | 149 | return this._keySize; |
153 | }, | 150 | }, |
154 | 151 | ||
155 | 'b': function() { | 152 | 'b': function() { |
156 | return this._b; | 153 | return this._b; |
157 | }, | 154 | }, |
158 | 155 | ||
159 | 'numberOfRounds': function() { | 156 | 'numberOfRounds': function() { |
160 | return this._numberOfRounds; | 157 | return this._numberOfRounds; |
161 | }, | 158 | }, |
162 | //========================================================================= | 159 | //========================================================================= |
163 | 160 | ||
164 | 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { | 161 | 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { |
165 | varresult; | 162 | varresult; |
166 | var sbox; | 163 | var sbox; |
167 | 164 | ||
168 | sbox = Clipperz.Crypto.AES.sbox(); | 165 | sbox = Clipperz.Crypto.AES.sbox(); |
169 | 166 | ||
170 | result = [sbox[aWord[1]] ^ Clipperz.Crypto.AES.roundConstants()[aRoundConstantsIndex], | 167 | result = [sbox[aWord[1]] ^ Clipperz.Crypto.AES.roundConstants()[aRoundConstantsIndex], |
171 | sbox[aWord[2]], | 168 | sbox[aWord[2]], |
172 | sbox[aWord[3]], | 169 | sbox[aWord[3]], |
173 | sbox[aWord[0]]]; | 170 | sbox[aWord[0]]]; |
174 | 171 | ||
175 | return result; | 172 | return result; |
176 | }, | 173 | }, |
177 | 174 | ||
178 | //----------------------------------------------------------------------------- | 175 | //----------------------------------------------------------------------------- |
179 | 176 | ||
180 | 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { | 177 | 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { |
181 | varresult; | 178 | varresult; |
182 | var i,c; | 179 | var i,c; |
183 | 180 | ||
184 | result = []; | 181 | result = []; |
185 | c = 4; | 182 | c = 4; |
186 | for (i=0; i<c; i++) { | 183 | for (i=0; i<c; i++) { |
187 | result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); | 184 | result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); |
188 | } | 185 | } |
189 | 186 | ||
190 | return result; | 187 | return result; |
191 | }, | 188 | }, |
192 | 189 | ||
193 | //----------------------------------------------------------------------------- | 190 | //----------------------------------------------------------------------------- |
194 | 191 | ||
195 | 'sboxShakeup': function(aWord) { | 192 | 'sboxShakeup': function(aWord) { |
196 | var result; | 193 | var result; |
197 | var sbox; | 194 | var sbox; |
198 | var i,c; | 195 | var i,c; |
199 | 196 | ||
200 | result = []; | 197 | result = []; |
201 | sbox = Clipperz.Crypto.AES.sbox(); | 198 | sbox = Clipperz.Crypto.AES.sbox(); |
202 | c =4; | 199 | c =4; |
203 | for (i=0; i<c; i++) { | 200 | for (i=0; i<c; i++) { |
204 | result[i] = sbox[aWord[i]]; | 201 | result[i] = sbox[aWord[i]]; |
205 | } | 202 | } |
206 | 203 | ||
207 | return result; | 204 | return result; |
208 | }, | 205 | }, |
209 | 206 | ||
210 | //----------------------------------------------------------------------------- | 207 | //----------------------------------------------------------------------------- |
211 | 208 | ||
212 | 'stretchKey': function(aKey) { | 209 | 'stretchKey': function(aKey) { |
213 | varcurrentWord; | 210 | varcurrentWord; |
214 | varkeyLength; | 211 | varkeyLength; |
215 | varpreviousStretchIndex; | 212 | varpreviousStretchIndex; |
216 | var i,c; | 213 | var i,c; |