mirror of
http://git.whoc.org.uk/git/password-manager.git
synced 2025-01-10 12:30:02 +01:00
Mitigation for vulnerability CLP-01-018
This commit is contained in:
parent
0422224521
commit
a6852c9313
@ -196,12 +196,6 @@ Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new C
|
|||||||
return 5;
|
return 5;
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
@ -245,12 +239,12 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new
|
|||||||
var numberOfRandomBitsCollected;
|
var numberOfRandomBitsCollected;
|
||||||
|
|
||||||
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
||||||
collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
collectedBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
||||||
this.setRandomBitsCollector(collectetBits);
|
this.setRandomBitsCollector(collectedBits);
|
||||||
numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent();
|
numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent();
|
||||||
|
|
||||||
if (numberOfRandomBitsCollected == 8) {
|
if (numberOfRandomBitsCollected == 8) {
|
||||||
this.updateGeneratorWithValue(collectetBits);
|
this.updateGeneratorWithValue(collectedBits);
|
||||||
numberOfRandomBitsCollected = 0;
|
numberOfRandomBitsCollected = 0;
|
||||||
this.setRandomBitsCollector(0);
|
this.setRandomBitsCollector(0);
|
||||||
}
|
}
|
||||||
@ -288,94 +282,52 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new
|
|||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.KeyboardRandomnessSource = function(args) {
|
Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource = function(args) {
|
||||||
args = args || {};
|
args = args || {};
|
||||||
|
|
||||||
|
this._intervalTime = args.intervalTime || 1000;
|
||||||
|
this._browserCrypto = args.browserCrypto;
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
|
Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
|
||||||
|
|
||||||
this._randomBitsCollector = 0;
|
this.collectEntropy();
|
||||||
this._numberOfRandomBitsCollected = 0;
|
|
||||||
|
|
||||||
MochiKit.Signal.connect(document, 'onkeypress', this, 'collectEntropy');
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.KeyboardRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
|
Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
|
||||||
|
|
||||||
|
'intervalTime': function() {
|
||||||
|
return this._intervalTime;
|
||||||
|
},
|
||||||
|
|
||||||
|
'browserCrypto': function () {
|
||||||
|
return this._browserCrypto;
|
||||||
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
'randomBitsCollector': function() {
|
'collectEntropy': function() {
|
||||||
return this._randomBitsCollector;
|
var bytesToCollect;
|
||||||
},
|
|
||||||
|
|
||||||
'setRandomBitsCollector': function(aValue) {
|
if (this.boostMode() == true) {
|
||||||
this._randomBitsCollector = aValue;
|
bytesToCollect = 8;
|
||||||
},
|
} else {
|
||||||
|
bytesToCollect = 32;
|
||||||
'appendRandomBitToRandomBitsCollector': function(aValue) {
|
|
||||||
var collectedBits;
|
|
||||||
var numberOfRandomBitsCollected;
|
|
||||||
|
|
||||||
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
|
||||||
collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
|
||||||
this.setRandomBitsCollector(collectetBits);
|
|
||||||
numberOfRandomBitsCollected ++;
|
|
||||||
|
|
||||||
if (numberOfRandomBitsCollected == 8) {
|
|
||||||
this.updateGeneratorWithValue(collectetBits);
|
|
||||||
numberOfRandomBitsCollected = 0;
|
|
||||||
this.setRandomBitsCollector(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected)
|
var randomValuesArray = new Uint8Array(bytesToCollect);
|
||||||
},
|
this.browserCrypto().getRandomValues(randomValuesArray);
|
||||||
|
for (var i = 0; i < randomValuesArray.length; i++) {
|
||||||
|
this.updateGeneratorWithValue(randomValuesArray[i]);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
setTimeout(this.collectEntropy, this.intervalTime());
|
||||||
|
|
||||||
'numberOfRandomBitsCollected': function() {
|
|
||||||
return this._numberOfRandomBitsCollected;
|
|
||||||
},
|
|
||||||
|
|
||||||
'setNumberOfRandomBitsCollected': function(aValue) {
|
|
||||||
this._numberOfRandomBitsCollected = aValue;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'collectEntropy': function(anEvent) {
|
|
||||||
/*
|
|
||||||
var mouseLocation;
|
|
||||||
var randomBit;
|
|
||||||
|
|
||||||
mouseLocation = anEvent.mouse().client;
|
|
||||||
|
|
||||||
randomBit = ((mouseLocation.x ^ mouseLocation.y) & 0x1);
|
|
||||||
this.appendRandomBitToRandomBitsCollector(randomBit);
|
|
||||||
*/
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'numberOfRandomBits': function() {
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -607,21 +559,16 @@ MochiKit.Logging.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
'deferredEntropyCollection': function(aValue) {
|
'deferredEntropyCollection': function(aValue) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
//MochiKit.Logging.logDebug(">>> PRNG.deferredEntropyCollection");
|
|
||||||
|
|
||||||
if (this.isReadyToGenerateRandomValues()) {
|
if (this.isReadyToGenerateRandomValues()) {
|
||||||
//MochiKit.Logging.logDebug("--- PRNG.deferredEntropyCollection - 1");
|
|
||||||
result = aValue;
|
result = aValue;
|
||||||
} else {
|
} else {
|
||||||
//MochiKit.Logging.logDebug("--- PRNG.deferredEntropyCollection - 2");
|
|
||||||
var deferredResult;
|
var deferredResult;
|
||||||
|
|
||||||
Clipperz.NotificationCenter.notify(this, 'updatedProgressState', 'collectingEntropy', true);
|
Clipperz.NotificationCenter.notify(this, 'updatedProgressState', 'collectingEntropy', true);
|
||||||
|
|
||||||
deferredResult = new MochiKit.Async.Deferred();
|
deferredResult = new MochiKit.Async.Deferred();
|
||||||
// deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.1 - PRNG.deferredEntropyCollection - 1: " + res); return res;});
|
|
||||||
deferredResult.addCallback(MochiKit.Base.partial(MochiKit.Async.succeed, aValue));
|
deferredResult.addCallback(MochiKit.Base.partial(MochiKit.Async.succeed, aValue));
|
||||||
// deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("1.2.2 - PRNG.deferredEntropyCollection - 2: " + res); return res;});
|
|
||||||
MochiKit.Signal.connect(this,
|
MochiKit.Signal.connect(this,
|
||||||
'readyToGenerateRandomBytes',
|
'readyToGenerateRandomBytes',
|
||||||
deferredResult,
|
deferredResult,
|
||||||
@ -629,7 +576,6 @@ MochiKit.Logging.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
|
|
||||||
result = deferredResult;
|
result = deferredResult;
|
||||||
}
|
}
|
||||||
//MochiKit.Logging.logDebug("<<< PRNG.deferredEntropyCollection - result: " + result);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
@ -643,7 +589,7 @@ MochiKit.Logging.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
'dump': function(appendToDoc) {
|
'dump': function(appendToDoc) {
|
||||||
var tbl;
|
var tbl;
|
||||||
var i,c;
|
var i,c;
|
||||||
@ -749,7 +695,7 @@ MochiKit.Logging.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
|
|
||||||
return tbl;
|
return tbl;
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
@ -824,16 +770,26 @@ Clipperz.Crypto.PRNG.defaultRandomGenerator = function() {
|
|||||||
|
|
||||||
//.............................................................
|
//.............................................................
|
||||||
//
|
//
|
||||||
// KeyboardRandomnessSource
|
// CryptoRandomRandomnessSource
|
||||||
//
|
//
|
||||||
//.............................................................
|
//.............................................................
|
||||||
{
|
{
|
||||||
var newRandomnessSource;
|
var newRandomnessSource;
|
||||||
|
var browserCrypto;
|
||||||
|
|
||||||
newRandomnessSource = new Clipperz.Crypto.PRNG.KeyboardRandomnessSource();
|
if (window.crypto && window.crypto.getRandomValues) {
|
||||||
_clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource);
|
browserCrypto = window.crypto;
|
||||||
|
} else if (window.msCrypto && window.msCrypto.getRandomValues) {
|
||||||
|
browserCrypto = window.msCrypto;
|
||||||
|
} else {
|
||||||
|
browserCrypto = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (browserCrypto != null) {
|
||||||
|
newRandomnessSource = new Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource({'browserCrypto':browserCrypto});
|
||||||
|
_clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _clipperz_crypt_prng_defaultPRNG;
|
return _clipperz_crypt_prng_defaultPRNG;
|
||||||
|
@ -21,6 +21,8 @@ refer to http://www.clipperz.com.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
|
try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
|
||||||
throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!";
|
throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!";
|
||||||
}
|
}
|
||||||
@ -196,12 +198,6 @@ Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new C
|
|||||||
return 5;
|
return 5;
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
@ -245,12 +241,12 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new
|
|||||||
var numberOfRandomBitsCollected;
|
var numberOfRandomBitsCollected;
|
||||||
|
|
||||||
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
||||||
collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
collectedBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
||||||
this.setRandomBitsCollector(collectetBits);
|
this.setRandomBitsCollector(collectedBits);
|
||||||
numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent();
|
numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent();
|
||||||
|
|
||||||
if (numberOfRandomBitsCollected == 8) {
|
if (numberOfRandomBitsCollected == 8) {
|
||||||
this.updateGeneratorWithValue(collectetBits);
|
this.updateGeneratorWithValue(collectedBits);
|
||||||
numberOfRandomBitsCollected = 0;
|
numberOfRandomBitsCollected = 0;
|
||||||
this.setRandomBitsCollector(0);
|
this.setRandomBitsCollector(0);
|
||||||
}
|
}
|
||||||
@ -288,94 +284,52 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new
|
|||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.KeyboardRandomnessSource = function(args) {
|
Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource = function(args) {
|
||||||
args = args || {};
|
args = args || {};
|
||||||
|
|
||||||
|
this._intervalTime = args.intervalTime || 1000;
|
||||||
|
this._browserCrypto = args.browserCrypto;
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
|
Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
|
||||||
|
|
||||||
this._randomBitsCollector = 0;
|
this.collectEntropy();
|
||||||
this._numberOfRandomBitsCollected = 0;
|
|
||||||
|
|
||||||
MochiKit.Signal.connect(document, 'onkeypress', this, 'collectEntropy');
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.KeyboardRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
|
Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
|
||||||
|
|
||||||
|
'intervalTime': function() {
|
||||||
|
return this._intervalTime;
|
||||||
|
},
|
||||||
|
|
||||||
|
'browserCrypto': function () {
|
||||||
|
return this._browserCrypto;
|
||||||
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
'randomBitsCollector': function() {
|
'collectEntropy': function() {
|
||||||
return this._randomBitsCollector;
|
var bytesToCollect;
|
||||||
},
|
|
||||||
|
|
||||||
'setRandomBitsCollector': function(aValue) {
|
if (this.boostMode() == true) {
|
||||||
this._randomBitsCollector = aValue;
|
bytesToCollect = 8;
|
||||||
},
|
} else {
|
||||||
|
bytesToCollect = 32;
|
||||||
'appendRandomBitToRandomBitsCollector': function(aValue) {
|
|
||||||
var collectedBits;
|
|
||||||
var numberOfRandomBitsCollected;
|
|
||||||
|
|
||||||
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
|
||||||
collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
|
||||||
this.setRandomBitsCollector(collectetBits);
|
|
||||||
numberOfRandomBitsCollected ++;
|
|
||||||
|
|
||||||
if (numberOfRandomBitsCollected == 8) {
|
|
||||||
this.updateGeneratorWithValue(collectetBits);
|
|
||||||
numberOfRandomBitsCollected = 0;
|
|
||||||
this.setRandomBitsCollector(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected)
|
var randomValuesArray = new Uint8Array(bytesToCollect);
|
||||||
},
|
this.browserCrypto().getRandomValues(randomValuesArray);
|
||||||
|
for (var i = 0; i < randomValuesArray.length; i++) {
|
||||||
|
this.updateGeneratorWithValue(randomValuesArray[i]);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
setTimeout(this.collectEntropy, this.intervalTime());
|
||||||
|
|
||||||
'numberOfRandomBitsCollected': function() {
|
|
||||||
return this._numberOfRandomBitsCollected;
|
|
||||||
},
|
|
||||||
|
|
||||||
'setNumberOfRandomBitsCollected': function(aValue) {
|
|
||||||
this._numberOfRandomBitsCollected = aValue;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'collectEntropy': function(anEvent) {
|
|
||||||
/*
|
|
||||||
var mouseLocation;
|
|
||||||
var randomBit;
|
|
||||||
|
|
||||||
mouseLocation = anEvent.mouse().client;
|
|
||||||
|
|
||||||
randomBit = ((mouseLocation.x ^ mouseLocation.y) & 0x1);
|
|
||||||
this.appendRandomBitToRandomBitsCollector(randomBit);
|
|
||||||
*/
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'numberOfRandomBits': function() {
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -635,7 +589,7 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
'dump': function(appendToDoc) {
|
'dump': function(appendToDoc) {
|
||||||
var tbl;
|
var tbl;
|
||||||
var i,c;
|
var i,c;
|
||||||
@ -741,7 +695,7 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
|
|
||||||
return tbl;
|
return tbl;
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
@ -784,7 +738,7 @@ Clipperz.Crypto.PRNG.Random.prototype = MochiKit.Base.update(null, {
|
|||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
|
|
||||||
_clipperz_crypt_prng_defaultPRNG = null;
|
var _clipperz_crypt_prng_defaultPRNG = null;
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.defaultRandomGenerator = function() {
|
Clipperz.Crypto.PRNG.defaultRandomGenerator = function() {
|
||||||
if (_clipperz_crypt_prng_defaultPRNG == null) {
|
if (_clipperz_crypt_prng_defaultPRNG == null) {
|
||||||
@ -816,16 +770,26 @@ Clipperz.Crypto.PRNG.defaultRandomGenerator = function() {
|
|||||||
|
|
||||||
//.............................................................
|
//.............................................................
|
||||||
//
|
//
|
||||||
// KeyboardRandomnessSource
|
// CryptoRandomRandomnessSource
|
||||||
//
|
//
|
||||||
//.............................................................
|
//.............................................................
|
||||||
{
|
{
|
||||||
var newRandomnessSource;
|
var newRandomnessSource;
|
||||||
|
var browserCrypto;
|
||||||
|
|
||||||
newRandomnessSource = new Clipperz.Crypto.PRNG.KeyboardRandomnessSource();
|
if (window.crypto && window.crypto.getRandomValues) {
|
||||||
_clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource);
|
browserCrypto = window.crypto;
|
||||||
|
} else if (window.msCrypto && window.msCrypto.getRandomValues) {
|
||||||
|
browserCrypto = window.msCrypto;
|
||||||
|
} else {
|
||||||
|
browserCrypto = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (browserCrypto != null) {
|
||||||
|
newRandomnessSource = new Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource({'browserCrypto':browserCrypto});
|
||||||
|
_clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _clipperz_crypt_prng_defaultPRNG;
|
return _clipperz_crypt_prng_defaultPRNG;
|
||||||
|
@ -21,6 +21,8 @@ refer to http://www.clipperz.com.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
|
try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
|
||||||
throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!";
|
throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!";
|
||||||
}
|
}
|
||||||
@ -196,12 +198,6 @@ Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new C
|
|||||||
return 5;
|
return 5;
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
@ -245,12 +241,12 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new
|
|||||||
var numberOfRandomBitsCollected;
|
var numberOfRandomBitsCollected;
|
||||||
|
|
||||||
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
||||||
collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
collectedBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
||||||
this.setRandomBitsCollector(collectetBits);
|
this.setRandomBitsCollector(collectedBits);
|
||||||
numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent();
|
numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent();
|
||||||
|
|
||||||
if (numberOfRandomBitsCollected == 8) {
|
if (numberOfRandomBitsCollected == 8) {
|
||||||
this.updateGeneratorWithValue(collectetBits);
|
this.updateGeneratorWithValue(collectedBits);
|
||||||
numberOfRandomBitsCollected = 0;
|
numberOfRandomBitsCollected = 0;
|
||||||
this.setRandomBitsCollector(0);
|
this.setRandomBitsCollector(0);
|
||||||
}
|
}
|
||||||
@ -288,94 +284,52 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new
|
|||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.KeyboardRandomnessSource = function(args) {
|
Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource = function(args) {
|
||||||
args = args || {};
|
args = args || {};
|
||||||
|
|
||||||
|
this._intervalTime = args.intervalTime || 1000;
|
||||||
|
this._browserCrypto = args.browserCrypto;
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
|
Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
|
||||||
|
|
||||||
this._randomBitsCollector = 0;
|
this.collectEntropy();
|
||||||
this._numberOfRandomBitsCollected = 0;
|
|
||||||
|
|
||||||
MochiKit.Signal.connect(document, 'onkeypress', this, 'collectEntropy');
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.KeyboardRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
|
Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
|
||||||
|
|
||||||
|
'intervalTime': function() {
|
||||||
|
return this._intervalTime;
|
||||||
|
},
|
||||||
|
|
||||||
|
'browserCrypto': function () {
|
||||||
|
return this._browserCrypto;
|
||||||
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
'randomBitsCollector': function() {
|
'collectEntropy': function() {
|
||||||
return this._randomBitsCollector;
|
var bytesToCollect;
|
||||||
},
|
|
||||||
|
|
||||||
'setRandomBitsCollector': function(aValue) {
|
if (this.boostMode() == true) {
|
||||||
this._randomBitsCollector = aValue;
|
bytesToCollect = 8;
|
||||||
},
|
} else {
|
||||||
|
bytesToCollect = 32;
|
||||||
'appendRandomBitToRandomBitsCollector': function(aValue) {
|
|
||||||
var collectedBits;
|
|
||||||
var numberOfRandomBitsCollected;
|
|
||||||
|
|
||||||
numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
|
|
||||||
collectetBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
|
|
||||||
this.setRandomBitsCollector(collectetBits);
|
|
||||||
numberOfRandomBitsCollected ++;
|
|
||||||
|
|
||||||
if (numberOfRandomBitsCollected == 8) {
|
|
||||||
this.updateGeneratorWithValue(collectetBits);
|
|
||||||
numberOfRandomBitsCollected = 0;
|
|
||||||
this.setRandomBitsCollector(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected)
|
var randomValuesArray = new Uint8Array(bytesToCollect);
|
||||||
},
|
this.browserCrypto().getRandomValues(randomValuesArray);
|
||||||
|
for (var i = 0; i < randomValuesArray.length; i++) {
|
||||||
|
this.updateGeneratorWithValue(randomValuesArray[i]);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
setTimeout(this.collectEntropy, this.intervalTime());
|
||||||
|
|
||||||
'numberOfRandomBitsCollected': function() {
|
|
||||||
return this._numberOfRandomBitsCollected;
|
|
||||||
},
|
|
||||||
|
|
||||||
'setNumberOfRandomBitsCollected': function(aValue) {
|
|
||||||
this._numberOfRandomBitsCollected = aValue;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'collectEntropy': function(anEvent) {
|
|
||||||
/*
|
|
||||||
var mouseLocation;
|
|
||||||
var randomBit;
|
|
||||||
|
|
||||||
mouseLocation = anEvent.mouse().client;
|
|
||||||
|
|
||||||
randomBit = ((mouseLocation.x ^ mouseLocation.y) & 0x1);
|
|
||||||
this.appendRandomBitToRandomBitsCollector(randomBit);
|
|
||||||
*/
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'numberOfRandomBits': function() {
|
|
||||||
return 1;
|
|
||||||
},
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
'pollingFrequency': function() {
|
|
||||||
return 10;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -635,7 +589,7 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
},
|
},
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
'dump': function(appendToDoc) {
|
'dump': function(appendToDoc) {
|
||||||
var tbl;
|
var tbl;
|
||||||
var i,c;
|
var i,c;
|
||||||
@ -741,7 +695,7 @@ Clipperz.logWarning("Fortuna generator has not enough entropy, yet!");
|
|||||||
|
|
||||||
return tbl;
|
return tbl;
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
__syntaxFix__: "syntax fix"
|
__syntaxFix__: "syntax fix"
|
||||||
});
|
});
|
||||||
@ -784,7 +738,7 @@ Clipperz.Crypto.PRNG.Random.prototype = MochiKit.Base.update(null, {
|
|||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
|
|
||||||
_clipperz_crypt_prng_defaultPRNG = null;
|
var _clipperz_crypt_prng_defaultPRNG = null;
|
||||||
|
|
||||||
Clipperz.Crypto.PRNG.defaultRandomGenerator = function() {
|
Clipperz.Crypto.PRNG.defaultRandomGenerator = function() {
|
||||||
if (_clipperz_crypt_prng_defaultPRNG == null) {
|
if (_clipperz_crypt_prng_defaultPRNG == null) {
|
||||||
@ -816,16 +770,26 @@ Clipperz.Crypto.PRNG.defaultRandomGenerator = function() {
|
|||||||
|
|
||||||
//.............................................................
|
//.............................................................
|
||||||
//
|
//
|
||||||
// KeyboardRandomnessSource
|
// CryptoRandomRandomnessSource
|
||||||
//
|
//
|
||||||
//.............................................................
|
//.............................................................
|
||||||
{
|
{
|
||||||
var newRandomnessSource;
|
var newRandomnessSource;
|
||||||
|
var browserCrypto;
|
||||||
|
|
||||||
newRandomnessSource = new Clipperz.Crypto.PRNG.KeyboardRandomnessSource();
|
if (window.crypto && window.crypto.getRandomValues) {
|
||||||
_clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource);
|
browserCrypto = window.crypto;
|
||||||
|
} else if (window.msCrypto && window.msCrypto.getRandomValues) {
|
||||||
|
browserCrypto = window.msCrypto;
|
||||||
|
} else {
|
||||||
|
browserCrypto = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (browserCrypto != null) {
|
||||||
|
newRandomnessSource = new Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource({'browserCrypto':browserCrypto});
|
||||||
|
_clipperz_crypt_prng_defaultPRNG.addRandomnessSource(newRandomnessSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _clipperz_crypt_prng_defaultPRNG;
|
return _clipperz_crypt_prng_defaultPRNG;
|
||||||
|
Loading…
Reference in New Issue
Block a user