Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/PRNG.js | 124 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/SRP.js | 47 |
2 files changed, 82 insertions, 89 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/PRNG.js b/frontend/gamma/js/Clipperz/Crypto/PRNG.js index c539f06..80d972f 100644 --- a/frontend/gamma/js/Clipperz/Crypto/PRNG.js +++ b/frontend/gamma/js/Clipperz/Crypto/PRNG.js | |||
@@ -1,47 +1,49 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2013 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz, the online password manager. | 5 | This file is part of Clipperz, the online password manager. |
6 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
7 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
8 | 8 | ||
9 | * Clipperz is free software: you can redistribute it and/or modify it | 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 | 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 | 11 | by the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | 12 | (at your option) any later version. |
13 | 13 | ||
14 | * Clipperz is distributed in the hope that it will be useful, but | 14 | * Clipperz is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
18 | 18 | ||
19 | * 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 |
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
21 | 21 | ||
22 | */ | 22 | */ |
23 | 23 | ||
24 | "use strict"; | ||
25 | |||
24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | 26 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { |
25 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; | 27 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; |
26 | } | 28 | } |
27 | 29 | ||
28 | try { if (typeof(Clipperz.Crypto.SHA) == 'undefined') { throw ""; }} catch (e) { | 30 | try { if (typeof(Clipperz.Crypto.SHA) == 'undefined') { throw ""; }} catch (e) { |
29 | throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.SHA!"; | 31 | throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.SHA!"; |
30 | } | 32 | } |
31 | 33 | ||
32 | try { if (typeof(Clipperz.Crypto.AES) == 'undefined') { throw ""; }} catch (e) { | 34 | try { if (typeof(Clipperz.Crypto.AES) == 'undefined') { throw ""; }} catch (e) { |
33 | throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.AES!"; | 35 | throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.AES!"; |
34 | } | 36 | } |
35 | 37 | ||
36 | if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { Clipperz.Crypto.PRNG = {}; } | 38 | if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { Clipperz.Crypto.PRNG = {}; } |
37 | 39 | ||
38 | //############################################################################# | 40 | //############################################################################# |
39 | 41 | ||
40 | Clipperz.Crypto.PRNG.EntropyAccumulator = function(args) { | 42 | Clipperz.Crypto.PRNG.EntropyAccumulator = function(args) { |
41 | args = args || {}; | 43 | args = args || {}; |
42 | //MochiKit.Base.bindMethods(this); | 44 | //MochiKit.Base.bindMethods(this); |
43 | 45 | ||
44 | this._stack = new Clipperz.ByteArray(); | 46 | this._stack = new Clipperz.ByteArray(); |
45 | this._maxStackLengthBeforeHashing = args.maxStackLengthBeforeHashing || 256; | 47 | this._maxStackLengthBeforeHashing = args.maxStackLengthBeforeHashing || 256; |
46 | return this; | 48 | return this; |
47 | } | 49 | } |
@@ -176,227 +178,179 @@ Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new C | |||
176 | 178 | ||
177 | 'collectEntropy': function() { | 179 | 'collectEntropy': function() { |
178 | varnow; | 180 | varnow; |
179 | varentropyByte; | 181 | varentropyByte; |
180 | var intervalTime; | 182 | var intervalTime; |
181 | now = new Date(); | 183 | now = new Date(); |
182 | entropyByte = (now.getTime() & 0xff); | 184 | entropyByte = (now.getTime() & 0xff); |
183 | 185 | ||
184 | intervalTime = this.intervalTime(); | 186 | intervalTime = this.intervalTime(); |
185 | if (this.boostMode() == true) { | 187 | if (this.boostMode() == true) { |
186 | intervalTime = intervalTime / 9; | 188 | intervalTime = intervalTime / 9; |
187 | } | 189 | } |
188 | 190 | ||
189 | this.updateGeneratorWithValue(entropyByte); | 191 | this.updateGeneratorWithValue(entropyByte); |
190 | setTimeout(this.collectEntropy, intervalTime); | 192 | setTimeout(this.collectEntropy, intervalTime); |
191 | }, | 193 | }, |
192 | 194 | ||
193 | //------------------------------------------------------------------------- | 195 | //------------------------------------------------------------------------- |
194 | 196 | ||
195 | 'numberOfRandomBits': function() { | 197 | 'numberOfRandomBits': function() { |
196 | return 5; | 198 | return 5; |
197 | }, | 199 | }, |
198 | 200 | ||
199 | //------------------------------------------------------------------------- | 201 | //------------------------------------------------------------------------- |
200 | |||
201 | 'pollingFrequency': function() { | ||
202 | return 10; | ||
203 | }, | ||
204 | |||
205 | //------------------------------------------------------------------------- | ||
206 | __syntaxFix__: "syntax fix" | 202 | __syntaxFix__: "syntax fix" |
207 | }); | 203 | }); |
208 | 204 | ||
209 | //***************************************************************************** | 205 | //***************************************************************************** |
210 | 206 | ||
211 | Clipperz.Crypto.PRNG.MouseRandomnessSource = function(args) { | 207 | Clipperz.Crypto.PRNG.MouseRandomnessSource = function(args) { |
212 | args = args || {}; | 208 | args = args || {}; |
213 | 209 | ||
214 | Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); | 210 | Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); |
215 | 211 | ||
216 | this._numberOfBitsToCollectAtEachEvent = 4; | 212 | this._numberOfBitsToCollectAtEachEvent = 4; |
217 | this._randomBitsCollector = 0; | 213 | this._randomBitsCollector = 0; |
218 | this._numberOfRandomBitsCollected = 0; | 214 | this._numberOfRandomBitsCollected = 0; |
219 | 215 | ||
220 | MochiKit.Signal.connect(document, 'onmousemove', this, 'collectEntropy'); | 216 | MochiKit.Signal.connect(document, 'onmousemove', this, 'collectEntropy'); |
221 | 217 | ||
222 | return this; | 218 | return this; |
223 | } | 219 | } |
224 | 220 | ||
225 | Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, { | 221 | Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, { |
226 | 222 | ||
227 | //------------------------------------------------------------------------- | 223 | //------------------------------------------------------------------------- |
228 | 224 | ||
229 | 'numberOfBitsToCollectAtEachEvent': function() { | 225 | 'numberOfBitsToCollectAtEachEvent': function() { |
230 | return this._numberOfBitsToCollectAtEachEvent; | 226 | return this._numberOfBitsToCollectAtEachEvent; |
231 | }, | 227 | }, |
232 | 228 | ||
233 | //------------------------------------------------------------------------- | 229 | //------------------------------------------------------------------------- |
234 | 230 | ||
235 | 'randomBitsCollector': function() { | 231 | 'randomBitsCollector': function() { |
236 | return this._randomBitsCollector; | 232 | return this._randomBitsCollector; |
237 | }, | 233 | }, |
238 | 234 | ||
239 | 'setRandomBitsCollector': function(aValue) { | 235 | 'setRandomBitsCollector': function(aValue) { |
240 | this._randomBitsCollector = aValue; | 236 | this._randomBitsCollector = aValue; |
241 | }, | 237 | }, |
242 | 238 | ||
243 | 'appendRandomBitsToRandomBitsCollector': function(aValue) { | 239 | 'appendRandomBitsToRandomBitsCollector': function(aValue) { |
244 | var collectedBits; | 240 | var collectedBits; |
245 | var numberOfRandomBitsCollected; | 241 | var numberOfRandomBitsCollected; |
246 | 242 | ||
247 | numberOfRandomBitsCollected = this.numberOfRandomBitsCollected(); | 243 | numberOfRandomBitsCollected = this.numberOfRandomBitsCollected(); |
248 | collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected); | 244 | collectedBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected); |
249 | this.setRandomBitsCollector(collectetBits); | 245 | this.setRandomBitsCollector(collectedBits); |
250 | numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent(); | 246 | numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent(); |
251 | 247 | ||
252 | if (numberOfRandomBitsCollected == 8) { | 248 | if (numberOfRandomBitsCollected == 8) { |
253 | this.updateGeneratorWithValue(collectetBits); | 249 | this.updateGeneratorWithValue(collectedBits); |
254 | numberOfRandomBitsCollected = 0; | 250 | numberOfRandomBitsCollected = 0; |
255 | this.setRandomBitsCollector(0); | 251 | this.setRandomBitsCollector(0); |
256 | } | 252 | } |
257 | 253 | ||
258 | this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected) | 254 | this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected) |
259 | }, | 255 | }, |
260 | 256 | ||
261 | //------------------------------------------------------------------------- | 257 | //------------------------------------------------------------------------- |
262 | 258 | ||
263 | 'numberOfRandomBitsCollected': function() { | 259 | 'numberOfRandomBitsCollected': function() { |
264 | return this._numberOfRandomBitsCollected; | 260 | return this._numberOfRandomBitsCollected; |
265 | }, | 261 | }, |
266 | 262 | ||
267 | 'setNumberOfRandomBitsCollected': function(aValue) { | 263 | 'setNumberOfRandomBitsCollected': function(aValue) { |
268 | this._numberOfRandomBitsCollected = aValue; | 264 | this._numberOfRandomBitsCollected = aValue; |
269 | }, | 265 | }, |
270 | 266 | ||
271 | //------------------------------------------------------------------------- | 267 | //------------------------------------------------------------------------- |
272 | 268 | ||
273 | 'collectEntropy': function(anEvent) { | 269 | 'collectEntropy': function(anEvent) { |
274 | var mouseLocation; | 270 | var mouseLocation; |
275 | var randomBit; | 271 | var randomBit; |
276 | var mask; | 272 | var mask; |
277 | 273 | ||
278 | mask = 0xffffffff >>> (32 - this.numberOfBitsToCollectAtEachEvent()); | 274 | mask = 0xffffffff >>> (32 - this.numberOfBitsToCollectAtEachEvent()); |
279 | 275 | ||
280 | mouseLocation = anEvent.mouse().client; | 276 | mouseLocation = anEvent.mouse().client; |
281 | randomBit = ((mouseLocation.x ^ mouseLocation.y) & mask); | 277 | randomBit = ((mouseLocation.x ^ mouseLocation.y) & mask); |
282 | this.appendRandomBitsToRandomBitsCollector(randomBit) | 278 | this.appendRandomBitsToRandomBitsCollector(randomBit) |
283 | }, | 279 | }, |
284 | 280 | ||
285 | //------------------------------------------------------------------------- | 281 | //------------------------------------------------------------------------- |
286 | 282 | ||
287 | 'numberOfRandomBits': function() { | 283 | 'numberOfRandomBits': function() { |
288 | return 1; | 284 | return 1; |
289 | }, | 285 | }, |
290 | 286 | ||
291 | //------------------------------------------------------------------------- | 287 | //------------------------------------------------------------------------- |
292 | |||
293 | 'pollingFrequency': function() { | ||
294 | return 10; | ||
295 | }, | ||
296 | |||
297 | //------------------------------------------------------------------------- | ||
298 | __syntaxFix__: "syntax fix" | 288 | __syntaxFix__: "syntax fix" |
299 | }); | 289 | }); |
300 | 290 | ||
301 | //***************************************************************************** | 291 | //***************************************************************************** |
302 | 292 | ||
303 | Clipperz.Crypto.PRNG.KeyboardRandomnessSource = function(args) { | 293 | Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource = function(args) { |
304 | args = args || {}; | 294 | args = args || {}; |
305 | Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); | ||
306 | 295 | ||
307 | this._randomBitsCollector = 0; | 296 | this._intervalTime = args.intervalTime || 1000; |
308 | this._numberOfRandomBitsCollected = 0; | 297 | this._browserCrypto = args.browserCrypto; |
309 | 298 | ||
310 | MochiKit.Signal.connect(document, 'onkeypress', this, 'collectEntropy'); | 299 | Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); |
311 | 300 | ||
301 | this.collectEntropy(); | ||
312 | return this; | 302 | return this; |
313 | } | 303 | } |
314 | 304 | ||
315 | Clipperz.Crypto.PRNG.KeyboardRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, { | 305 | Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, { |
316 | |||
317 | //------------------------------------------------------------------------- | ||
318 | |||
319 | 'randomBitsCollector': function() { | ||
320 | return this._randomBitsCollector; | ||
321 | }, | ||
322 | |||
323 | 'setRandomBitsCollector': function(aValue) { | ||
324 | this._randomBitsCollector = aValue; | ||
325 | }, | ||
326 | |||
327 | 'appendRandomBitToRandomBitsCollector': function(aValue) { | ||
328 | var collectedBits; | ||
329 | var numberOfRandomBitsCollected; | ||
330 | |||
331 | numberOfRandomBitsCollected = this.numberOfRandomBitsCollected(); | ||
332 | collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected); | ||
333 | this.setRandomBitsCollector(collectetBits); | ||
334 | numberOfRandomBitsCollected ++; | ||
335 | |||
336 | if (numberOfRandomBitsCollected == 8) { | ||
337 | this.updateGeneratorWithValue(collectetBits); | ||
338 | numberOfRandomBitsCollected = 0; | ||
339 | this.setRandomBitsCollector(0); | ||
340 | } | ||
341 | |||
342 | this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected) | ||
343 | }, | ||
344 | 306 | ||
345 | //------------------------------------------------------------------------- | 307 | 'intervalTime': function() { |
346 | 308 | return this._intervalTime; | |
347 | 'numberOfRandomBitsCollected': function() { | ||
348 | return this._numberOfRandomBitsCollected; | ||
349 | }, | 309 | }, |
350 | 310 | ||
351 | 'setNumberOfRandomBitsCollected': function(aValue) { | 311 | 'browserCrypto': function () { |
352 | this._numberOfRandomBitsCollected = aValue; | 312 | return this._browserCrypto; |
353 | }, | 313 | }, |
354 | 314 | ||
355 | //------------------------------------------------------------------------- | 315 | //------------------------------------------------------------------------- |
356 | 316 | ||
357 | 'collectEntropy': function(anEvent) { | 317 | 'collectEntropy': function() { |
358 | /* | 318 | varbytesToCollect; |
359 | var mouseLocation; | ||
360 | var randomBit; | ||
361 | |||
362 | mouseLocation = anEvent.mouse().client; | ||
363 | |||
364 | randomBit = ((mouseLocation.x ^ mouseLocation.y) & 0x1); | ||
365 | this.appendRandomBitToRandomBitsCollector(randomBit); | ||
366 | */ | ||
367 | }, | ||
368 | |||
369 | //------------------------------------------------------------------------- | ||
370 | 319 | ||
371 | 'numberOfRandomBits': function() { | 320 | if (this.boostMode() == true) { |
372 | return 1; | 321 | bytesToCollect = 64; |
373 | }, | 322 | } else { |
323 | bytesToCollect = 8; | ||
324 | } | ||
374 | 325 | ||
375 | //------------------------------------------------------------------------- | 326 | var randomValuesArray = new Uint8Array(bytesToCollect); |
327 | this.browserCrypto().getRandomValues(randomValuesArray); | ||
328 | for (var i = 0; i < randomValuesArray.length; i++) { | ||
329 | this.updateGeneratorWithValue(randomValuesArray[i]); | ||
330 | } | ||
376 | 331 | ||
377 | 'pollingFrequency': function() { | 332 | setTimeout(this.collectEntropy, this.intervalTime()); |
378 | return 10; | ||
379 | }, | 333 | }, |
380 | 334 | ||
381 | //------------------------------------------------------------------------- | 335 | //------------------------------------------------------------------------- |
382 | __syntaxFix__: "syntax fix" | 336 | __syntaxFix__: "syntax fix" |
383 | }); | 337 | }); |
384 | 338 | ||
385 | //############################################################################# | 339 | //############################################################################# |
386 | 340 | ||
387 | Clipperz.Crypto.PRNG.Fortuna = function(args) { | 341 | Clipperz.Crypto.PRNG.Fortuna = function(args) { |
388 | vari,c; | 342 | vari,c; |
389 | 343 | ||
390 | args = args || {}; | 344 | args = args || {}; |
391 | 345 | ||
392 | this._key = args.seed || null; | 346 | this._key = args.seed || null; |
393 | if (this._key == null) { | 347 | if (this._key == null) { |
394 | this._counter = 0; | 348 | this._counter = 0; |
395 | this._key = new Clipperz.ByteArray(); | 349 | this._key = new Clipperz.ByteArray(); |
396 | } else { | 350 | } else { |
397 | this._counter = 1; | 351 | this._counter = 1; |
398 | } | 352 | } |
399 | 353 | ||
400 | this._aesKey = null; | 354 | this._aesKey = null; |
401 | 355 | ||
402 | this._firstPoolReseedLevel = args.firstPoolReseedLevel || 32 || 64; | 356 | this._firstPoolReseedLevel = args.firstPoolReseedLevel || 32 || 64; |
@@ -614,49 +568,49 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
614 | var deferredResult; | 568 | var deferredResult; |
615 | 569 | ||
616 | deferredResult = new Clipperz.Async.Deferred("PRNG.deferredEntropyCollection"); | 570 | deferredResult = new Clipperz.Async.Deferred("PRNG.deferredEntropyCollection"); |
617 | deferredResult.addCallback(MochiKit.Base.partial(MochiKit.Async.succeed, aValue)); | 571 | deferredResult.addCallback(MochiKit.Base.partial(MochiKit.Async.succeed, aValue)); |
618 | MochiKit.Signal.connect(this, | 572 | MochiKit.Signal.connect(this, |
619 | 'readyToGenerateRandomBytes', | 573 | 'readyToGenerateRandomBytes', |
620 | deferredResult, | 574 | deferredResult, |
621 | 'callback'); | 575 | 'callback'); |
622 | 576 | ||
623 | result = deferredResult; | 577 | result = deferredResult; |
624 | } | 578 | } |
625 | 579 | ||
626 | return result; | 580 | return result; |
627 | }, | 581 | }, |
628 | 582 | ||
629 | //------------------------------------------------------------------------- | 583 | //------------------------------------------------------------------------- |
630 | 584 | ||
631 | 'fastEntropyAccumulationForTestingPurpose': function() { | 585 | 'fastEntropyAccumulationForTestingPurpose': function() { |
632 | while (! this.isReadyToGenerateRandomValues()) { | 586 | while (! this.isReadyToGenerateRandomValues()) { |
633 | this.addRandomByte(Math.floor(Math.random() * 32), Math.floor(Math.random() * 32), Math.floor(Math.random() * 256)); | 587 | this.addRandomByte(Math.floor(Math.random() * 32), Math.floor(Math.random() * 32), Math.floor(Math.random() * 256)); |
634 | } | 588 | } |
635 | }, | 589 | }, |
636 | 590 | ||
637 | //------------------------------------------------------------------------- | 591 | //------------------------------------------------------------------------- |
638 | 592 | /* | |
639 | 'dump': function(appendToDoc) { | 593 | 'dump': function(appendToDoc) { |
640 | var tbl; | 594 | var tbl; |
641 | var i,c; | 595 | var i,c; |
642 | 596 | ||
643 | tbl = document.createElement("table"); | 597 | tbl = document.createElement("table"); |
644 | tbl.border = 0; | 598 | tbl.border = 0; |
645 | with (tbl.style) { | 599 | with (tbl.style) { |
646 | border = "1px solid lightgrey"; | 600 | border = "1px solid lightgrey"; |
647 | fontFamily = 'Helvetica, Arial, sans-serif'; | 601 | fontFamily = 'Helvetica, Arial, sans-serif'; |
648 | fontSize = '8pt'; | 602 | fontSize = '8pt'; |
649 | //borderCollapse = "collapse"; | 603 | //borderCollapse = "collapse"; |
650 | } | 604 | } |
651 | var hdr = tbl.createTHead(); | 605 | var hdr = tbl.createTHead(); |
652 | var hdrtr = hdr.insertRow(0); | 606 | var hdrtr = hdr.insertRow(0); |
653 | // document.createElement("tr"); | 607 | // document.createElement("tr"); |
654 | { | 608 | { |
655 | var ntd; | 609 | var ntd; |
656 | 610 | ||
657 | ntd = hdrtr.insertCell(0); | 611 | ntd = hdrtr.insertCell(0); |
658 | ntd.style.borderBottom = "1px solid lightgrey"; | 612 | ntd.style.borderBottom = "1px solid lightgrey"; |
659 | ntd.style.borderRight = "1px solid lightgrey"; | 613 | ntd.style.borderRight = "1px solid lightgrey"; |
660 | ntd.appendChild(document.createTextNode("#")); | 614 | ntd.appendChild(document.createTextNode("#")); |
661 | 615 | ||
662 | ntd = hdrtr.insertCell(1); | 616 | ntd = hdrtr.insertCell(1); |
@@ -720,122 +674,132 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
720 | 674 | ||
721 | } | 675 | } |
722 | 676 | ||
723 | 677 | ||
724 | if (appendToDoc) { | 678 | if (appendToDoc) { |
725 | var ne = document.createElement("div"); | 679 | var ne = document.createElement("div"); |
726 | ne.id = "entropyGeneratorStatus"; | 680 | ne.id = "entropyGeneratorStatus"; |
727 | with (ne.style) { | 681 | with (ne.style) { |
728 | fontFamily = "Courier New, monospace"; | 682 | fontFamily = "Courier New, monospace"; |
729 | fontSize = "12px"; | 683 | fontSize = "12px"; |
730 | lineHeight = "16px"; | 684 | lineHeight = "16px"; |
731 | borderTop = "1px solid black"; | 685 | borderTop = "1px solid black"; |
732 | padding = "10px"; | 686 | padding = "10px"; |
733 | } | 687 | } |
734 | if (document.getElementById(ne.id)) { | 688 | if (document.getElementById(ne.id)) { |
735 | MochiKit.DOM.swapDOM(ne.id, ne); | 689 | MochiKit.DOM.swapDOM(ne.id, ne); |
736 | } else { | 690 | } else { |
737 | document.body.appendChild(ne); | 691 | document.body.appendChild(ne); |
738 | } | 692 | } |
739 | ne.appendChild(tbl); | 693 | ne.appendChild(tbl); |
740 | } | 694 | } |
741 | 695 | ||
742 | return tbl; | 696 | return tbl; |
743 | }, | 697 | }, |
744 | 698 | */ | |
745 | //----------------------------------------------------------------------------- | 699 | //----------------------------------------------------------------------------- |
746 | __syntaxFix__: "syntax fix" | 700 | __syntaxFix__: "syntax fix" |
747 | }); | 701 | }); |
748 | 702 | ||
749 | //############################################################################# | 703 | //############################################################################# |
750 | 704 | ||
751 | Clipperz.Crypto.PRNG.Random = function(args) { | 705 | Clipperz.Crypto.PRNG.Random = function(args) { |
752 | args = args || {}; | 706 | args = args || {}; |
753 | //MochiKit.Base.bindMethods(this); | 707 | //MochiKit.Base.bindMethods(this); |
754 | 708 | ||
755 | return this; | 709 | return this; |
756 | } | 710 | } |
757 | 711 | ||
758 | Clipperz.Crypto.PRNG.Random.prototype = MochiKit.Base.update(null, { | 712 | Clipperz.Crypto.PRNG.Random.prototype = MochiKit.Base.update(null, { |
759 | 713 | ||
760 | 'toString': function() { | 714 | 'toString': function() { |
761 | return "Clipperz.Crypto.PRNG.Random"; | 715 | return "Clipperz.Crypto.PRNG.Random"; |
762 | }, | 716 | }, |
763 | 717 | ||
764 | //------------------------------------------------------------------------- | 718 | //------------------------------------------------------------------------- |
765 | 719 | ||
766 | 'getRandomBytes': function(aSize) { | 720 | 'getRandomBytes': function(aSize) { |
767 | //Clipperz.Profile.start("Clipperz.Crypto.PRNG.Random.getRandomBytes"); | 721 | //Clipperz.Profile.start("Clipperz.Crypto.PRNG.Random.getRandomBytes"); |
768 | varresult; | 722 | varresult; |
769 | var i,c; | 723 | var i,c; |
770 | 724 | ||
771 | result = new Clipperz.ByteArray() | 725 | result = new Clipperz.ByteArray() |
772 | c = aSize || 1; | 726 | c = aSize || 1; |
773 | for (i=0; i<c; i++) { | 727 | for (i=0; i<c; i++) { |
774 | result.appendByte((Math.random()*255) & 0xff); | 728 | result.appendByte((Math.random()*255) & 0xff); |
775 | } | 729 | } |
776 | 730 | ||
777 | //Clipperz.Profile.stop("Clipperz.Crypto.PRNG.Random.getRandomBytes"); | 731 | //Clipperz.Profile.stop("Clipperz.Crypto.PRNG.Random.getRandomBytes"); |
778 | return result; | 732 | return result; |
779 | }, | 733 | }, |
780 | 734 | ||
781 | //------------------------------------------------------------------------- | 735 | //------------------------------------------------------------------------- |
782 | __syntaxFix__: "syntax fix" | 736 | __syntaxFix__: "syntax fix" |
783 | }); | 737 | }); |
784 | 738 | ||
785 | //############################################################################# | 739 | //############################################################################# |
786 | 740 | ||
787 | _clipperz_crypt_prng_defaultPRNG = null; | 741 | var _clipperz_crypt_prng_defaultPRNG = null; |
788 | 742 | ||
789 | Clipperz.Crypto.PRNG.defaultRandomGenerator = function() { | 743 | Clipperz.Crypto.PRNG.defaultRandomGenerator = function() { |
790 | if (_clipperz_crypt_prng_defaultPRNG == null) { | 744 | if (_clipperz_crypt_prng_defaultPRNG == null) { |
791 | _clipperz_crypt_prng_defaultPRNG = new Clipperz.Crypto.PRNG.Fortuna(); | 745 | _clipperz_crypt_prng_defaultPRNG = new Clipperz.Crypto.PRNG.Fortuna(); |
792 | 746 | ||
793 | //............................................................. | 747 | //............................................................. |
794 | // | 748 | // |
795 | // TimeRandomnessSource | 749 | // TimeRandomnessSource |
796 | // | 750 | // |
797 | //............................................................. | 751 | //............................................................. |
798 | { | 752 | { |
799 | var newRandomnessSource; | 753 | var newRandomnessSource; |
800 | 754 | ||
801 | newRandomnessSource = new Clipperz.Crypto.PRNG.TimeRandomnessSource({intervalTime:111}); | 755 | newRandomnessSource = new Clipperz.Crypto.PRNG.TimeRandomnessSource({intervalTime:111}); |
802 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | 756 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); |
803 | } | 757 | } |
804 | 758 | ||
805 | //............................................................. | 759 | //............................................................. |
806 | // | 760 | // |
807 | // MouseRandomnessSource | 761 | // MouseRandomnessSource |
808 | // | 762 | // |
809 | //............................................................. | 763 | //............................................................. |
810 | { | 764 | { |
811 | varnewRandomnessSource; | 765 | varnewRandomnessSource; |
812 | 766 | ||
813 | newRandomnessSource = new Clipperz.Crypto.PRNG.MouseRandomnessSource(); | 767 | newRandomnessSource = new Clipperz.Crypto.PRNG.MouseRandomnessSource(); |
814 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | 768 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); |
815 | } | 769 | } |
816 | 770 | ||
817 | //............................................................. | 771 | //............................................................. |
818 | // | 772 | // |
819 | // KeyboardRandomnessSource | 773 | // CryptoRandomRandomnessSource |
820 | // | 774 | // |
821 | //............................................................. | 775 | //............................................................. |
822 | { | 776 | { |
823 | varnewRandomnessSource; | 777 | varnewRandomnessSource; |
778 | varbrowserCrypto; | ||
824 | 779 | ||
825 | newRandomnessSource = new Clipperz.Crypto.PRNG.KeyboardRandomnessSource(); | 780 | if (window.crypto && window.crypto.getRandomValues) { |
826 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | 781 | browserCrypto = window.crypto; |
782 | } else if (window.msCrypto && window.msCrypto.getRandomValues) { | ||
783 | browserCrypto = window.msCrypto; | ||
784 | } else { | ||
785 | browserCrypto = null; | ||
827 | } | 786 | } |
828 | 787 | ||
788 | if (browserCrypto != null) { | ||
789 | newRandomnessSource = new Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource({'browserCrypto':browserCrypto}); | ||
790 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | ||
791 | } | ||
792 | } | ||
829 | } | 793 | } |
830 | 794 | ||
831 | return _clipperz_crypt_prng_defaultPRNG; | 795 | return _clipperz_crypt_prng_defaultPRNG; |
832 | }; | 796 | }; |
833 | 797 | ||
834 | //############################################################################# | 798 | //############################################################################# |
835 | 799 | ||
836 | Clipperz.Crypto.PRNG.exception = { | 800 | Clipperz.Crypto.PRNG.exception = { |
837 | NotEnoughEntropy: new MochiKit.Base.NamedError("Clipperz.Crypto.PRNG.exception.NotEnoughEntropy") | 801 | NotEnoughEntropy: new MochiKit.Base.NamedError("Clipperz.Crypto.PRNG.exception.NotEnoughEntropy") |
838 | }; | 802 | }; |
839 | 803 | ||
840 | 804 | ||
841 | MochiKit.DOM.addLoadEvent(Clipperz.Crypto.PRNG.defaultRandomGenerator); | 805 | MochiKit.DOM.addLoadEvent(Clipperz.Crypto.PRNG.defaultRandomGenerator); |
diff --git a/frontend/gamma/js/Clipperz/Crypto/SRP.js b/frontend/gamma/js/Clipperz/Crypto/SRP.js index 597e72d..6898dfb 100644 --- a/frontend/gamma/js/Clipperz/Crypto/SRP.js +++ b/frontend/gamma/js/Clipperz/Crypto/SRP.js | |||
@@ -23,68 +23,79 @@ refer to http://www.clipperz.com. | |||
23 | 23 | ||
24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { |
25 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; | 25 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; |
26 | } | 26 | } |
27 | 27 | ||
28 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { | 28 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { |
29 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.BigInt!"; | 29 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.BigInt!"; |
30 | } | 30 | } |
31 | 31 | ||
32 | try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { | 32 | try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { |
33 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.PRNG!"; | 33 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.PRNG!"; |
34 | } | 34 | } |
35 | 35 | ||
36 | if (typeof(Clipperz.Crypto.SRP) == 'undefined') { Clipperz.Crypto.SRP = {}; } | 36 | if (typeof(Clipperz.Crypto.SRP) == 'undefined') { Clipperz.Crypto.SRP = {}; } |
37 | 37 | ||
38 | Clipperz.Crypto.SRP.VERSION = "0.1"; | 38 | Clipperz.Crypto.SRP.VERSION = "0.1"; |
39 | Clipperz.Crypto.SRP.NAME = "Clipperz.Crypto.SRP"; | 39 | Clipperz.Crypto.SRP.NAME = "Clipperz.Crypto.SRP"; |
40 | 40 | ||
41 | //############################################################################# | 41 | //############################################################################# |
42 | 42 | ||
43 | MochiKit.Base.update(Clipperz.Crypto.SRP, { | 43 | MochiKit.Base.update(Clipperz.Crypto.SRP, { |
44 | 44 | ||
45 | '_n': null, | 45 | '_n': null, |
46 | '_g': null, | 46 | '_g': null, |
47 | '_k': null, | ||
48 | |||
47 | //------------------------------------------------------------------------- | 49 | //------------------------------------------------------------------------- |
48 | 50 | ||
49 | 'n': function() { | 51 | 'n': function() { |
50 | if (Clipperz.Crypto.SRP._n == null) { | 52 | if (Clipperz.Crypto.SRP._n == null) { |
51 | Clipperz.Crypto.SRP._n = new Clipperz.Crypto.BigInt("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); | 53 | Clipperz.Crypto.SRP._n = new Clipperz.Crypto.BigInt("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); |
52 | } | 54 | } |
53 | 55 | ||
54 | return Clipperz.Crypto.SRP._n; | 56 | return Clipperz.Crypto.SRP._n; |
55 | }, | 57 | }, |
56 | 58 | ||
57 | //------------------------------------------------------------------------- | 59 | //------------------------------------------------------------------------- |
58 | 60 | ||
59 | 'g': function() { | 61 | 'g': function() { |
60 | if (Clipperz.Crypto.SRP._g == null) { | 62 | if (Clipperz.Crypto.SRP._g == null) { |
61 | Clipperz.Crypto.SRP._g = new Clipperz.Crypto.BigInt(2); //eventually 5 (as suggested on the Diffi-Helmann documentation) | 63 | Clipperz.Crypto.SRP._g = new Clipperz.Crypto.BigInt(2); //eventually 5 (as suggested on the Diffi-Helmann documentation) |
62 | } | 64 | } |
63 | 65 | ||
64 | return Clipperz.Crypto.SRP._g; | 66 | return Clipperz.Crypto.SRP._g; |
65 | }, | 67 | }, |
66 | 68 | ||
69 | 'k': function() { | ||
70 | if (Clipperz.Crypto.SRP._k == null) { | ||
71 | // Clipperz.Crypto.SRP._k = new Clipperz.Crypto.BigInt(this.stringHash(this.n().asString() + this.g().asString()), 16); | ||
72 | Clipperz.Crypto.SRP._k = new Clipperz.Crypto.BigInt("64398bff522814e306a97cb9bfc4364b7eed16a8c17c5208a40a2bad2933c8e", 16); | ||
73 | } | ||
74 | |||
75 | return Clipperz.Crypto.SRP._k; | ||
76 | }, | ||
77 | |||
67 | //----------------------------------------------------------------------------- | 78 | //----------------------------------------------------------------------------- |
68 | 79 | ||
69 | 'exception': { | 80 | 'exception': { |
70 | 'InvalidValue': new MochiKit.Base.NamedError("Clipperz.Crypto.SRP.exception.InvalidValue") | 81 | 'InvalidValue': new MochiKit.Base.NamedError("Clipperz.Crypto.SRP.exception.InvalidValue") |
71 | }, | 82 | }, |
72 | 83 | ||
73 | //------------------------------------------------------------------------- | 84 | //------------------------------------------------------------------------- |
74 | __syntaxFix__: "syntax fix" | 85 | __syntaxFix__: "syntax fix" |
75 | 86 | ||
76 | }); | 87 | }); |
77 | 88 | ||
78 | //############################################################################# | 89 | //############################################################################# |
79 | // | 90 | // |
80 | // S R P C o n n e c t i o n version 1.0 | 91 | // S R P C o n n e c t i o n version 1.0 |
81 | // | 92 | // |
82 | //============================================================================= | 93 | //============================================================================= |
83 | Clipperz.Crypto.SRP.Connection = function (args) { | 94 | Clipperz.Crypto.SRP.Connection = function (args) { |
84 | args = args || {}; | 95 | args = args || {}; |
85 | 96 | ||
86 | this._C = args.C; | 97 | this._C = args.C; |
87 | this._P = args.P; | 98 | this._P = args.P; |
88 | this.hash = args.hash; | 99 | this.hash = args.hash; |
89 | 100 | ||
90 | this._a = null; | 101 | this._a = null; |
@@ -117,151 +128,169 @@ Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, { | |||
117 | return this._C; | 128 | return this._C; |
118 | }, | 129 | }, |
119 | 130 | ||
120 | //------------------------------------------------------------------------- | 131 | //------------------------------------------------------------------------- |
121 | 132 | ||
122 | 'P': function () { | 133 | 'P': function () { |
123 | return this._P; | 134 | return this._P; |
124 | }, | 135 | }, |
125 | 136 | ||
126 | //------------------------------------------------------------------------- | 137 | //------------------------------------------------------------------------- |
127 | 138 | ||
128 | 'a': function () { | 139 | 'a': function () { |
129 | if (this._a == null) { | 140 | if (this._a == null) { |
130 | this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16); | 141 | this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16); |
131 | // this._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10); | 142 | // this._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10); |
132 | } | 143 | } |
133 | 144 | ||
134 | return this._a; | 145 | return this._a; |
135 | }, | 146 | }, |
136 | 147 | ||
137 | //------------------------------------------------------------------------- | 148 | //------------------------------------------------------------------------- |
138 | 149 | ||
139 | 'A': function () { | 150 | 'A': function () { |
140 | if (this._A == null) { | 151 | if (this._A == null) { |
141 | //Warning: this value should be strictly greater than zero: how should we perform this check? | 152 | //Warning: this value should be strictly greater than zero |
142 | this._A = Clipperz.Crypto.SRP.g().powerModule(this.a(), Clipperz.Crypto.SRP.n()); | 153 | this._A = Clipperz.Crypto.SRP.g().powerModule(this.a(), Clipperz.Crypto.SRP.n()); |
143 | 154 | if (this._A.equals(0) || negative(this._A)) { | |
144 | if (this._A.equals(0)) { | ||
145 | Clipperz.logError("Clipperz.Crypto.SRP.Connection: trying to set 'A' to 0."); | 155 | Clipperz.logError("Clipperz.Crypto.SRP.Connection: trying to set 'A' to 0."); |
146 | throw Clipperz.Crypto.SRP.exception.InvalidValue; | 156 | throw Clipperz.Crypto.SRP.exception.InvalidValue; |
147 | } | 157 | } |
148 | } | 158 | } |
149 | 159 | ||
150 | return this._A; | 160 | return this._A; |
151 | }, | 161 | }, |
152 | 162 | ||
153 | //------------------------------------------------------------------------- | 163 | //------------------------------------------------------------------------- |
154 | 164 | ||
155 | 's': function () { | 165 | 's': function () { |
156 | return this._s; | 166 | return this._s; |
157 | }, | 167 | }, |
158 | 168 | ||
159 | 'set_s': function(aValue) { | 169 | 'set_s': function(aValue) { |
160 | this._s = aValue; | 170 | this._s = aValue; |
161 | }, | 171 | }, |
162 | 172 | ||
163 | //------------------------------------------------------------------------- | 173 | //------------------------------------------------------------------------- |
164 | 174 | ||
165 | 'B': function () { | 175 | 'B': function () { |
166 | return this._B; | 176 | return this._B; |
167 | }, | 177 | }, |
168 | 178 | ||
169 | 'set_B': function(aValue) { | 179 | 'set_B': function(aValue) { |
170 | //Warning: this value should be strictly greater than zero: how should we perform this check? | 180 | //Warning: this value should be strictly greater than zero |
171 | if (! aValue.equals(0)) { | ||
172 | this._B = aValue; | 181 | this._B = aValue; |
173 | } else { | 182 | if (this._B.equals(0) || negative(this._B)) { |
174 | Clipperz.logError("Clipperz.Crypto.SRP.Connection: trying to set 'B' to 0."); | 183 | Clipperz.logError("Clipperz.Crypto.SRP.Connection: trying to set 'B' to 0."); |
175 | throw Clipperz.Crypto.SRP.exception.InvalidValue; | 184 | throw Clipperz.Crypto.SRP.exception.InvalidValue; |
176 | } | 185 | } |
177 | }, | 186 | }, |
178 | 187 | ||
179 | //------------------------------------------------------------------------- | 188 | //------------------------------------------------------------------------- |
180 | 189 | ||
181 | 'x': function () { | 190 | 'x': function () { |
182 | if (this._x == null) { | 191 | if (this._x == null) { |
183 | this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s().asString(16, 64) + this.P()), 16); | 192 | this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s().asString(16, 64) + this.P()), 16); |
184 | } | 193 | } |
185 | 194 | ||
186 | return this._x; | 195 | return this._x; |
187 | }, | 196 | }, |
188 | 197 | ||
189 | //------------------------------------------------------------------------- | 198 | //------------------------------------------------------------------------- |
190 | 199 | ||
191 | 'u': function () { | 200 | 'u': function () { |
192 | if (this._u == null) { | 201 | if (this._u == null) { |
193 | this._u = new Clipperz.Crypto.BigInt(this.stringHash(this.B().asString()), 16); | 202 | this._u = new Clipperz.Crypto.BigInt(this.stringHash(this.A().asString() + this.B().asString()), 16); |
194 | } | 203 | } |
195 | 204 | ||
196 | return this._u; | 205 | return this._u; |
197 | }, | 206 | }, |
198 | 207 | ||
199 | //------------------------------------------------------------------------- | 208 | //------------------------------------------------------------------------- |
200 | 209 | ||
201 | 'S': function () { | 210 | 'S': function () { |
202 | if (this._S == null) { | 211 | if (this._S == null) { |
203 | var bigint; | 212 | var bigint; |
204 | varsrp; | 213 | varsrp; |
205 | 214 | ||
206 | bigint = Clipperz.Crypto.BigInt; | 215 | bigint = Clipperz.Crypto.BigInt; |
207 | srp = Clipperz.Crypto.SRP; | 216 | srp = Clipperz.Crypto.SRP; |
208 | 217 | ||
209 | this._S =bigint.powerModule( | 218 | this._S =bigint.powerModule( |
210 | bigint.subtract(this.B(), bigint.powerModule(srp.g(), this.x(), srp.n())), | 219 | bigint.subtract( |
220 | this.B(), | ||
221 | bigint.multiply( | ||
222 | Clipperz.Crypto.SRP.k(), | ||
223 | bigint.powerModule(srp.g(), this.x(), srp.n()) | ||
224 | ) | ||
225 | ), | ||
211 | bigint.add(this.a(), bigint.multiply(this.u(), this.x())), | 226 | bigint.add(this.a(), bigint.multiply(this.u(), this.x())), |
212 | srp.n() | 227 | srp.n() |
213 | ) | 228 | ) |
214 | } | 229 | } |
215 | 230 | ||
216 | return this._S; | 231 | return this._S; |
217 | }, | 232 | }, |
218 | 233 | ||
219 | //------------------------------------------------------------------------- | 234 | //------------------------------------------------------------------------- |
220 | 235 | ||
221 | 'K': function () { | 236 | 'K': function () { |
222 | if (this._K == null) { | 237 | if (this._K == null) { |
223 | this._K = this.stringHash(this.S().asString()); | 238 | this._K = this.stringHash(this.S().asString()); |
224 | } | 239 | } |
225 | 240 | ||
226 | return this._K; | 241 | return this._K; |
227 | }, | 242 | }, |
228 | 243 | ||
229 | //------------------------------------------------------------------------- | 244 | //------------------------------------------------------------------------- |
230 | 245 | ||
231 | 'M1': function () { | 246 | 'M1': function () { |
232 | if (this._M1 == null) { | 247 | if (this._M1 == null) { |
233 | this._M1 = this.stringHash(this.A().asString(10) + this.B().asString(10) + this.K()); | 248 | // this._M1 = this.stringHash(this.A().asString(10) + this.B().asString(10) + this.K()); |
249 | |||
250 | //http://srp.stanford.edu/design.html | ||
251 | //User -> Host: M = H(H(N) xor H(g), H(I), s, A, B, K) | ||
252 | |||
253 | this._M1 = this.stringHash( | ||
254 | "597626870978286801440197562148588907434001483655788865609375806439877501869636875571920406529" + | ||
255 | this.stringHash(this.C()) + | ||
256 | this.s().asString() + | ||
257 | this.A().asString() + | ||
258 | this.B().asString() + | ||
259 | this.K() | ||
260 | ); | ||
261 | //console.log("M1", this._M1); | ||
234 | } | 262 | } |
235 | 263 | ||
236 | return this._M1; | 264 | return this._M1; |
237 | }, | 265 | }, |
238 | 266 | ||
239 | //------------------------------------------------------------------------- | 267 | //------------------------------------------------------------------------- |
240 | 268 | ||
241 | 'M2': function () { | 269 | 'M2': function () { |
242 | if (this._M2 == null) { | 270 | if (this._M2 == null) { |
243 | this._M2 = this.stringHash(this.A().asString(10) + this.M1() + this.K()); | 271 | this._M2 = this.stringHash(this.A().asString(10) + this.M1() + this.K()); |
272 | //console.log("M2", this._M2); | ||
244 | } | 273 | } |
245 | 274 | ||
246 | return this._M2; | 275 | return this._M2; |
247 | }, | 276 | }, |
248 | 277 | ||
249 | //========================================================================= | 278 | //========================================================================= |
250 | 279 | ||
251 | 'serverSideCredentialsWithSalt': function(aSalt) { | 280 | 'serverSideCredentialsWithSalt': function(aSalt) { |
252 | var result; | 281 | var result; |
253 | var s, x, v; | 282 | var s, x, v; |
254 | 283 | ||
255 | s = aSalt; | 284 | s = aSalt; |
256 | x = this.stringHash(s + this.P()); | 285 | x = this.stringHash(s + this.P()); |
257 | v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n()); | 286 | v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n()); |
258 | 287 | ||
259 | result = {}; | 288 | result = {}; |
260 | result['C'] = this.C(); | 289 | result['C'] = this.C(); |
261 | result['s'] = s; | 290 | result['s'] = s; |
262 | result['v'] = v.asString(16); | 291 | result['v'] = v.asString(16); |
263 | 292 | ||
264 | return result; | 293 | return result; |
265 | }, | 294 | }, |
266 | 295 | ||
267 | 'serverSideCredentials': function() { | 296 | 'serverSideCredentials': function() { |