author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2014-06-19 10:32:07 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2014-06-19 10:51:21 (UTC) |
commit | a6852c93138f3c4596fb4df8bce5b7d19ef50478 (patch) (unidiff) | |
tree | 6a8cfda52d54ae8990a0c51447980d06408ac6cc /frontend | |
parent | 0422224521f62da210d1ae6ee15ecdf09f47f1f8 (diff) | |
download | clipperz-a6852c93138f3c4596fb4df8bce5b7d19ef50478.zip clipperz-a6852c93138f3c4596fb4df8bce5b7d19ef50478.tar.gz clipperz-a6852c93138f3c4596fb4df8bce5b7d19ef50478.tar.bz2 |
Mitigation for vulnerability CLP-01-018
-rw-r--r-- | frontend/beta/js/Clipperz/Crypto/PRNG.js | 130 | ||||
-rw-r--r-- | frontend/delta/js/Clipperz/Crypto/PRNG.js | 128 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/PRNG.js | 128 |
3 files changed, 135 insertions, 251 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/PRNG.js b/frontend/beta/js/Clipperz/Crypto/PRNG.js index b5c3f8a..92966d0 100644 --- a/frontend/beta/js/Clipperz/Crypto/PRNG.js +++ b/frontend/beta/js/Clipperz/Crypto/PRNG.js | |||
@@ -192,22 +192,16 @@ Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new C | |||
192 | 192 | ||
193 | //------------------------------------------------------------------------- | 193 | //------------------------------------------------------------------------- |
194 | 194 | ||
195 | 'numberOfRandomBits': function() { | 195 | 'numberOfRandomBits': function() { |
196 | return 5; | 196 | return 5; |
197 | }, | 197 | }, |
198 | 198 | ||
199 | //------------------------------------------------------------------------- | 199 | //------------------------------------------------------------------------- |
200 | |||
201 | 'pollingFrequency': function() { | ||
202 | return 10; | ||
203 | }, | ||
204 | |||
205 | //------------------------------------------------------------------------- | ||
206 | __syntaxFix__: "syntax fix" | 200 | __syntaxFix__: "syntax fix" |
207 | }); | 201 | }); |
208 | 202 | ||
209 | //***************************************************************************** | 203 | //***************************************************************************** |
210 | 204 | ||
211 | Clipperz.Crypto.PRNG.MouseRandomnessSource = function(args) { | 205 | Clipperz.Crypto.PRNG.MouseRandomnessSource = function(args) { |
212 | args = args || {}; | 206 | args = args || {}; |
213 | 207 | ||
@@ -240,22 +234,22 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new | |||
240 | this._randomBitsCollector = aValue; | 234 | this._randomBitsCollector = aValue; |
241 | }, | 235 | }, |
242 | 236 | ||
243 | 'appendRandomBitsToRandomBitsCollector': function(aValue) { | 237 | 'appendRandomBitsToRandomBitsCollector': function(aValue) { |
244 | var collectedBits; | 238 | var collectedBits; |
245 | var numberOfRandomBitsCollected; | 239 | var numberOfRandomBitsCollected; |
246 | 240 | ||
247 | numberOfRandomBitsCollected = this.numberOfRandomBitsCollected(); | 241 | numberOfRandomBitsCollected = this.numberOfRandomBitsCollected(); |
248 | collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected); | 242 | collectedBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected); |
249 | this.setRandomBitsCollector(collectetBits); | 243 | this.setRandomBitsCollector(collectedBits); |
250 | numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent(); | 244 | numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent(); |
251 | 245 | ||
252 | if (numberOfRandomBitsCollected == 8) { | 246 | if (numberOfRandomBitsCollected == 8) { |
253 | this.updateGeneratorWithValue(collectetBits); | 247 | this.updateGeneratorWithValue(collectedBits); |
254 | numberOfRandomBitsCollected = 0; | 248 | numberOfRandomBitsCollected = 0; |
255 | this.setRandomBitsCollector(0); | 249 | this.setRandomBitsCollector(0); |
256 | } | 250 | } |
257 | 251 | ||
258 | this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected) | 252 | this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected) |
259 | }, | 253 | }, |
260 | 254 | ||
261 | //------------------------------------------------------------------------- | 255 | //------------------------------------------------------------------------- |
@@ -284,106 +278,64 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new | |||
284 | 278 | ||
285 | //------------------------------------------------------------------------- | 279 | //------------------------------------------------------------------------- |
286 | 280 | ||
287 | 'numberOfRandomBits': function() { | 281 | 'numberOfRandomBits': function() { |
288 | return 1; | 282 | return 1; |
289 | }, | 283 | }, |
290 | 284 | ||
291 | //------------------------------------------------------------------------- | 285 | //------------------------------------------------------------------------- |
292 | |||
293 | 'pollingFrequency': function() { | ||
294 | return 10; | ||
295 | }, | ||
296 | |||
297 | //------------------------------------------------------------------------- | ||
298 | __syntaxFix__: "syntax fix" | 286 | __syntaxFix__: "syntax fix" |
299 | }); | 287 | }); |
300 | 288 | ||
301 | //***************************************************************************** | 289 | //***************************************************************************** |
302 | 290 | ||
303 | Clipperz.Crypto.PRNG.KeyboardRandomnessSource = function(args) { | 291 | Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource = function(args) { |
304 | args = args || {}; | 292 | args = args || {}; |
305 | Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); | ||
306 | 293 | ||
307 | this._randomBitsCollector = 0; | 294 | this._intervalTime = args.intervalTime || 1000; |
308 | this._numberOfRandomBitsCollected = 0; | 295 | this._browserCrypto = args.browserCrypto; |
309 | 296 | ||
310 | MochiKit.Signal.connect(document, 'onkeypress', this, 'collectEntropy'); | 297 | Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); |
311 | 298 | ||
299 | this.collectEntropy(); | ||
312 | return this; | 300 | return this; |
313 | } | 301 | } |
314 | 302 | ||
315 | Clipperz.Crypto.PRNG.KeyboardRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, { | 303 | 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 | 304 | ||
323 | 'setRandomBitsCollector': function(aValue) { | 305 | 'intervalTime': function() { |
324 | this._randomBitsCollector = aValue; | 306 | return this._intervalTime; |
325 | }, | 307 | }, |
326 | 308 | ||
327 | 'appendRandomBitToRandomBitsCollector': function(aValue) { | 309 | 'browserCrypto': function () { |
328 | var collectedBits; | 310 | return this._browserCrypto; |
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 | }, | 311 | }, |
344 | 312 | ||
345 | //------------------------------------------------------------------------- | 313 | //------------------------------------------------------------------------- |
346 | 314 | ||
347 | 'numberOfRandomBitsCollected': function() { | 315 | 'collectEntropy': function() { |
348 | return this._numberOfRandomBitsCollected; | 316 | varbytesToCollect; |
349 | }, | ||
350 | |||
351 | 'setNumberOfRandomBitsCollected': function(aValue) { | ||
352 | this._numberOfRandomBitsCollected = aValue; | ||
353 | }, | ||
354 | 317 | ||
355 | //------------------------------------------------------------------------- | 318 | if (this.boostMode() == true) { |
319 | bytesToCollect = 8; | ||
320 | } else { | ||
321 | bytesToCollect = 32; | ||
322 | } | ||
356 | 323 | ||
357 | 'collectEntropy': function(anEvent) { | 324 | var randomValuesArray = new Uint8Array(bytesToCollect); |
358 | /* | 325 | this.browserCrypto().getRandomValues(randomValuesArray); |
359 | var mouseLocation; | 326 | for (var i = 0; i < randomValuesArray.length; i++) { |
360 | var randomBit; | 327 | this.updateGeneratorWithValue(randomValuesArray[i]); |
361 | 328 | } | |
362 | mouseLocation = anEvent.mouse().client; | ||
363 | |||
364 | randomBit = ((mouseLocation.x ^ mouseLocation.y) & 0x1); | ||
365 | this.appendRandomBitToRandomBitsCollector(randomBit); | ||
366 | */ | ||
367 | }, | ||
368 | |||
369 | //------------------------------------------------------------------------- | ||
370 | 329 | ||
371 | 'numberOfRandomBits': function() { | 330 | setTimeout(this.collectEntropy, this.intervalTime()); |
372 | return 1; | ||
373 | }, | 331 | }, |
374 | 332 | ||
375 | //------------------------------------------------------------------------- | 333 | //------------------------------------------------------------------------- |
376 | |||
377 | 'pollingFrequency': function() { | ||
378 | return 10; | ||
379 | }, | ||
380 | |||
381 | //------------------------------------------------------------------------- | ||
382 | __syntaxFix__: "syntax fix" | 334 | __syntaxFix__: "syntax fix" |
383 | }); | 335 | }); |
384 | 336 | ||
385 | //############################################################################# | 337 | //############################################################################# |
386 | 338 | ||
387 | Clipperz.Crypto.PRNG.Fortuna = function(args) { | 339 | Clipperz.Crypto.PRNG.Fortuna = function(args) { |
388 | vari,c; | 340 | vari,c; |
389 | 341 | ||
@@ -602,53 +554,47 @@ MochiKit.Logging.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
602 | } | 554 | } |
603 | }, | 555 | }, |
604 | 556 | ||
605 | //------------------------------------------------------------------------- | 557 | //------------------------------------------------------------------------- |
606 | 558 | ||
607 | 'deferredEntropyCollection': function(aValue) { | 559 | 'deferredEntropyCollection': function(aValue) { |
608 | var result; | 560 | var result; |
609 | 561 | ||
610 | //MochiKit.Logging.logDebug(">>> PRNG.deferredEntropyCollection"); | ||
611 | 562 | ||
612 | if (this.isReadyToGenerateRandomValues()) { | 563 | if (this.isReadyToGenerateRandomValues()) { |
613 | //MochiKit.Logging.logDebug("--- PRNG.deferredEntropyCollection - 1"); | ||
614 | result = aValue; | 564 | result = aValue; |
615 | } else { | 565 | } else { |
616 | //MochiKit.Logging.logDebug("--- PRNG.deferredEntropyCollection - 2"); | ||
617 | var deferredResult; | 566 | var deferredResult; |
618 | 567 | ||
619 | Clipperz.NotificationCenter.notify(this, 'updatedProgressState', 'collectingEntropy', true); | 568 | Clipperz.NotificationCenter.notify(this, 'updatedProgressState', 'collectingEntropy', true); |
620 | 569 | ||
621 | deferredResult = new MochiKit.Async.Deferred(); | 570 | deferredResult = new MochiKit.Async.Deferred(); |
622 | // deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.1 - PRNG.deferredEntropyCollection - 1: " + res); return res;}); | ||
623 | deferredResult.addCallback(MochiKit.Base.partial(MochiKit.Async.succeed, aValue)); | 571 | deferredResult.addCallback(MochiKit.Base.partial(MochiKit.Async.succeed, aValue)); |
624 | // deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.2 - PRNG.deferredEntropyCollection - 2: " + res); return res;}); | ||
625 | MochiKit.Signal.connect(this, | 572 | MochiKit.Signal.connect(this, |
626 | 'readyToGenerateRandomBytes', | 573 | 'readyToGenerateRandomBytes', |
627 | deferredResult, | 574 | deferredResult, |
628 | 'callback'); | 575 | 'callback'); |
629 | 576 | ||
630 | result = deferredResult; | 577 | result = deferredResult; |
631 | } | 578 | } |
632 | //MochiKit.Logging.logDebug("<<< PRNG.deferredEntropyCollection - result: " + result); | ||
633 | 579 | ||
634 | return result; | 580 | return result; |
635 | }, | 581 | }, |
636 | 582 | ||
637 | //------------------------------------------------------------------------- | 583 | //------------------------------------------------------------------------- |
638 | 584 | ||
639 | 'fastEntropyAccumulationForTestingPurpose': function() { | 585 | 'fastEntropyAccumulationForTestingPurpose': function() { |
640 | while (! this.isReadyToGenerateRandomValues()) { | 586 | while (! this.isReadyToGenerateRandomValues()) { |
641 | 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)); |
642 | } | 588 | } |
643 | }, | 589 | }, |
644 | 590 | ||
645 | //------------------------------------------------------------------------- | 591 | //------------------------------------------------------------------------- |
646 | 592 | /* | |
647 | 'dump': function(appendToDoc) { | 593 | 'dump': function(appendToDoc) { |
648 | var tbl; | 594 | var tbl; |
649 | var i,c; | 595 | var i,c; |
650 | 596 | ||
651 | tbl = document.createElement("table"); | 597 | tbl = document.createElement("table"); |
652 | tbl.border = 0; | 598 | tbl.border = 0; |
653 | with (tbl.style) { | 599 | with (tbl.style) { |
654 | border = "1px solid lightgrey"; | 600 | border = "1px solid lightgrey"; |
@@ -744,17 +690,17 @@ MochiKit.Logging.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
744 | } else { | 690 | } else { |
745 | document.body.appendChild(ne); | 691 | document.body.appendChild(ne); |
746 | } | 692 | } |
747 | ne.appendChild(tbl); | 693 | ne.appendChild(tbl); |
748 | } | 694 | } |
749 | 695 | ||
750 | return tbl; | 696 | return tbl; |
751 | }, | 697 | }, |
752 | 698 | */ | |
753 | //----------------------------------------------------------------------------- | 699 | //----------------------------------------------------------------------------- |
754 | __syntaxFix__: "syntax fix" | 700 | __syntaxFix__: "syntax fix" |
755 | }); | 701 | }); |
756 | 702 | ||
757 | //############################################################################# | 703 | //############################################################################# |
758 | 704 | ||
759 | Clipperz.Crypto.PRNG.Random = function(args) { | 705 | Clipperz.Crypto.PRNG.Random = function(args) { |
760 | args = args || {}; | 706 | args = args || {}; |
@@ -819,26 +765,36 @@ Clipperz.Crypto.PRNG.defaultRandomGenerator = function() { | |||
819 | varnewRandomnessSource; | 765 | varnewRandomnessSource; |
820 | 766 | ||
821 | newRandomnessSource = new Clipperz.Crypto.PRNG.MouseRandomnessSource(); | 767 | newRandomnessSource = new Clipperz.Crypto.PRNG.MouseRandomnessSource(); |
822 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | 768 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); |
823 | } | 769 | } |
824 | 770 | ||
825 | //............................................................. | 771 | //............................................................. |
826 | // | 772 | // |
827 | // KeyboardRandomnessSource | 773 | // CryptoRandomRandomnessSource |
828 | // | 774 | // |
829 | //............................................................. | 775 | //............................................................. |
830 | { | 776 | { |
831 | varnewRandomnessSource; | 777 | varnewRandomnessSource; |
778 | varbrowserCrypto; | ||
832 | 779 | ||
833 | newRandomnessSource = new Clipperz.Crypto.PRNG.KeyboardRandomnessSource(); | 780 | if (window.crypto && window.crypto.getRandomValues) { |
834 | _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; | ||
786 | } | ||
787 | |||
788 | if (browserCrypto != null) { | ||
789 | newRandomnessSource = new Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource({'browserCrypto':browserCrypto}); | ||
790 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | ||
791 | } | ||
835 | } | 792 | } |
836 | |||
837 | } | 793 | } |
838 | 794 | ||
839 | return _clipperz_crypt_prng_defaultPRNG; | 795 | return _clipperz_crypt_prng_defaultPRNG; |
840 | }; | 796 | }; |
841 | 797 | ||
842 | //############################################################################# | 798 | //############################################################################# |
843 | 799 | ||
844 | Clipperz.Crypto.PRNG.exception = { | 800 | Clipperz.Crypto.PRNG.exception = { |
diff --git a/frontend/delta/js/Clipperz/Crypto/PRNG.js b/frontend/delta/js/Clipperz/Crypto/PRNG.js index c539f06..7885429 100644 --- a/frontend/delta/js/Clipperz/Crypto/PRNG.js +++ b/frontend/delta/js/Clipperz/Crypto/PRNG.js | |||
@@ -16,16 +16,18 @@ refer to http://www.clipperz.com. | |||
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 | ||
@@ -192,22 +194,16 @@ Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new C | |||
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 | ||
@@ -240,22 +236,22 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new | |||
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 | //------------------------------------------------------------------------- |
@@ -284,106 +280,64 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new | |||
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 | 306 | ||
317 | //------------------------------------------------------------------------- | 307 | 'intervalTime': function() { |
318 | 308 | return this._intervalTime; | |
319 | 'randomBitsCollector': function() { | ||
320 | return this._randomBitsCollector; | ||
321 | }, | ||
322 | |||
323 | 'setRandomBitsCollector': function(aValue) { | ||
324 | this._randomBitsCollector = aValue; | ||
325 | }, | 309 | }, |
326 | 310 | ||
327 | 'appendRandomBitToRandomBitsCollector': function(aValue) { | 311 | 'browserCrypto': function () { |
328 | var collectedBits; | 312 | return this._browserCrypto; |
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 | }, | 313 | }, |
344 | 314 | ||
345 | //------------------------------------------------------------------------- | 315 | //------------------------------------------------------------------------- |
346 | 316 | ||
347 | 'numberOfRandomBitsCollected': function() { | 317 | 'collectEntropy': function() { |
348 | return this._numberOfRandomBitsCollected; | 318 | varbytesToCollect; |
349 | }, | ||
350 | |||
351 | 'setNumberOfRandomBitsCollected': function(aValue) { | ||
352 | this._numberOfRandomBitsCollected = aValue; | ||
353 | }, | ||
354 | 319 | ||
355 | //------------------------------------------------------------------------- | 320 | if (this.boostMode() == true) { |
321 | bytesToCollect = 8; | ||
322 | } else { | ||
323 | bytesToCollect = 32; | ||
324 | } | ||
356 | 325 | ||
357 | 'collectEntropy': function(anEvent) { | 326 | var randomValuesArray = new Uint8Array(bytesToCollect); |
358 | /* | 327 | this.browserCrypto().getRandomValues(randomValuesArray); |
359 | var mouseLocation; | 328 | for (var i = 0; i < randomValuesArray.length; i++) { |
360 | var randomBit; | 329 | this.updateGeneratorWithValue(randomValuesArray[i]); |
361 | 330 | } | |
362 | mouseLocation = anEvent.mouse().client; | ||
363 | |||
364 | randomBit = ((mouseLocation.x ^ mouseLocation.y) & 0x1); | ||
365 | this.appendRandomBitToRandomBitsCollector(randomBit); | ||
366 | */ | ||
367 | }, | ||
368 | |||
369 | //------------------------------------------------------------------------- | ||
370 | 331 | ||
371 | 'numberOfRandomBits': function() { | 332 | setTimeout(this.collectEntropy, this.intervalTime()); |
372 | return 1; | ||
373 | }, | 333 | }, |
374 | 334 | ||
375 | //------------------------------------------------------------------------- | 335 | //------------------------------------------------------------------------- |
376 | |||
377 | 'pollingFrequency': function() { | ||
378 | return 10; | ||
379 | }, | ||
380 | |||
381 | //------------------------------------------------------------------------- | ||
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 | ||
@@ -630,17 +584,17 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
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"; |
@@ -736,17 +690,17 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
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 || {}; |
@@ -779,17 +733,17 @@ Clipperz.Crypto.PRNG.Random.prototype = MochiKit.Base.update(null, { | |||
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 |
@@ -811,26 +765,36 @@ Clipperz.Crypto.PRNG.defaultRandomGenerator = function() { | |||
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; | ||
786 | } | ||
787 | |||
788 | if (browserCrypto != null) { | ||
789 | newRandomnessSource = new Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource({'browserCrypto':browserCrypto}); | ||
790 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | ||
791 | } | ||
827 | } | 792 | } |
828 | |||
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 = { |
diff --git a/frontend/gamma/js/Clipperz/Crypto/PRNG.js b/frontend/gamma/js/Clipperz/Crypto/PRNG.js index c539f06..7885429 100644 --- a/frontend/gamma/js/Clipperz/Crypto/PRNG.js +++ b/frontend/gamma/js/Clipperz/Crypto/PRNG.js | |||
@@ -16,16 +16,18 @@ refer to http://www.clipperz.com. | |||
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 | ||
@@ -192,22 +194,16 @@ Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new C | |||
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 | ||
@@ -240,22 +236,22 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new | |||
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 | //------------------------------------------------------------------------- |
@@ -284,106 +280,64 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new | |||
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 | 306 | ||
317 | //------------------------------------------------------------------------- | 307 | 'intervalTime': function() { |
318 | 308 | return this._intervalTime; | |
319 | 'randomBitsCollector': function() { | ||
320 | return this._randomBitsCollector; | ||
321 | }, | ||
322 | |||
323 | 'setRandomBitsCollector': function(aValue) { | ||
324 | this._randomBitsCollector = aValue; | ||
325 | }, | 309 | }, |
326 | 310 | ||
327 | 'appendRandomBitToRandomBitsCollector': function(aValue) { | 311 | 'browserCrypto': function () { |
328 | var collectedBits; | 312 | return this._browserCrypto; |
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 | }, | 313 | }, |
344 | 314 | ||
345 | //------------------------------------------------------------------------- | 315 | //------------------------------------------------------------------------- |
346 | 316 | ||
347 | 'numberOfRandomBitsCollected': function() { | 317 | 'collectEntropy': function() { |
348 | return this._numberOfRandomBitsCollected; | 318 | varbytesToCollect; |
349 | }, | ||
350 | |||
351 | 'setNumberOfRandomBitsCollected': function(aValue) { | ||
352 | this._numberOfRandomBitsCollected = aValue; | ||
353 | }, | ||
354 | 319 | ||
355 | //------------------------------------------------------------------------- | 320 | if (this.boostMode() == true) { |
321 | bytesToCollect = 8; | ||
322 | } else { | ||
323 | bytesToCollect = 32; | ||
324 | } | ||
356 | 325 | ||
357 | 'collectEntropy': function(anEvent) { | 326 | var randomValuesArray = new Uint8Array(bytesToCollect); |
358 | /* | 327 | this.browserCrypto().getRandomValues(randomValuesArray); |
359 | var mouseLocation; | 328 | for (var i = 0; i < randomValuesArray.length; i++) { |
360 | var randomBit; | 329 | this.updateGeneratorWithValue(randomValuesArray[i]); |
361 | 330 | } | |
362 | mouseLocation = anEvent.mouse().client; | ||
363 | |||
364 | randomBit = ((mouseLocation.x ^ mouseLocation.y) & 0x1); | ||
365 | this.appendRandomBitToRandomBitsCollector(randomBit); | ||
366 | */ | ||
367 | }, | ||
368 | |||
369 | //------------------------------------------------------------------------- | ||
370 | 331 | ||
371 | 'numberOfRandomBits': function() { | 332 | setTimeout(this.collectEntropy, this.intervalTime()); |
372 | return 1; | ||
373 | }, | 333 | }, |
374 | 334 | ||
375 | //------------------------------------------------------------------------- | 335 | //------------------------------------------------------------------------- |
376 | |||
377 | 'pollingFrequency': function() { | ||
378 | return 10; | ||
379 | }, | ||
380 | |||
381 | //------------------------------------------------------------------------- | ||
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 | ||
@@ -630,17 +584,17 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
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"; |
@@ -736,17 +690,17 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!"); | |||
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 || {}; |
@@ -779,17 +733,17 @@ Clipperz.Crypto.PRNG.Random.prototype = MochiKit.Base.update(null, { | |||
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 |
@@ -811,26 +765,36 @@ Clipperz.Crypto.PRNG.defaultRandomGenerator = function() { | |||
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; | ||
786 | } | ||
787 | |||
788 | if (browserCrypto != null) { | ||
789 | newRandomnessSource = new Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource({'browserCrypto':browserCrypto}); | ||
790 | _clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource); | ||
791 | } | ||
827 | } | 792 | } |
828 | |||
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 = { |