mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-03-22 13:10:41 +08:00
sjcl.random.addEntropy():
* Fixed bug: when data is a number, it is now added to this._pools * Fixed bug: throws an exception when data is an object but not an array of numbers * Removed unused variable "ty" sjcl.random._loadTimeCollector(): * Fixed bug: now passes a number into sjcl.random.addEntropy() instead of an object
This commit is contained in:
parent
ec303b26ef
commit
8bf8bbbf3c
|
@ -79,10 +79,10 @@ sjcl.random = {
|
||||||
source = source || "user";
|
source = source || "user";
|
||||||
|
|
||||||
var id,
|
var id,
|
||||||
i, ty = 0, tmp,
|
i, tmp,
|
||||||
t = (new Date()).valueOf(),
|
t = (new Date()).valueOf(),
|
||||||
robin = this._robins[source],
|
robin = this._robins[source],
|
||||||
oldReady = this.isReady();
|
oldReady = this.isReady(), err = 0;
|
||||||
|
|
||||||
id = this._collectorIds[source];
|
id = this._collectorIds[source];
|
||||||
if (id === undefined) { id = this._collectorIds[source] = this._collectorIdNext ++; }
|
if (id === undefined) { id = this._collectorIds[source] = this._collectorIdNext ++; }
|
||||||
|
@ -93,11 +93,22 @@ sjcl.random = {
|
||||||
switch(typeof(data)) {
|
switch(typeof(data)) {
|
||||||
|
|
||||||
case "number":
|
case "number":
|
||||||
data=[data];
|
if (estimatedEntropy === undefined) {
|
||||||
ty=1;
|
estimatedEntropy = 1;
|
||||||
|
}
|
||||||
|
this._pools[robin].update([id,this._eventId++,1,estimatedEntropy,t,1,data|0]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "object":
|
case "object":
|
||||||
|
if (Object.prototype.toString.call(data) !== "[object Array]") {
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
for (i=0; i<data.length && !err; i++) {
|
||||||
|
if (typeof(data[i]) != "number") {
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!err) {
|
||||||
if (estimatedEntropy === undefined) {
|
if (estimatedEntropy === undefined) {
|
||||||
/* horrible entropy estimator */
|
/* horrible entropy estimator */
|
||||||
estimatedEntropy = 0;
|
estimatedEntropy = 0;
|
||||||
|
@ -109,7 +120,8 @@ sjcl.random = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._pools[robin].update([id,this._eventId++,ty||2,estimatedEntropy,t,data.length].concat(data));
|
this._pools[robin].update([id,this._eventId++,2,estimatedEntropy,t,data.length].concat(data));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "string":
|
case "string":
|
||||||
|
@ -125,8 +137,10 @@ sjcl.random = {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
err=1;
|
||||||
throw new sjcl.exception.bug("random: addEntropy only supports number, array or string");
|
}
|
||||||
|
if (err) {
|
||||||
|
throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* record the new strength */
|
/* record the new strength */
|
||||||
|
@ -342,8 +356,7 @@ sjcl.random = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_loadTimeCollector: function (ev) {
|
_loadTimeCollector: function (ev) {
|
||||||
var d = new Date();
|
sjcl.random.addEntropy((new Date()).valueOf(), 2, "loadtime");
|
||||||
sjcl.random.addEntropy(d, 2, "loadtime");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_fireEvent: function (name, arg) {
|
_fireEvent: function (name, arg) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user