crypto: add cleanse function.
This commit is contained in:
parent
c3a9b7378f
commit
53de684b4a
@ -514,6 +514,28 @@ crypto.ceq = function ceq(a, b) {
|
||||
return r === 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* A maybe-secure memzero.
|
||||
* @param {Buffer} data
|
||||
*/
|
||||
|
||||
crypto.cleanse = function cleanse(data) {
|
||||
var ctr = crypto._counter;
|
||||
var i;
|
||||
|
||||
for (i = 0; i < data.length; i++) {
|
||||
data[i] = ctr & 0xff;
|
||||
ctr += i;
|
||||
}
|
||||
|
||||
crypto._counter = ctr >>> 0;
|
||||
};
|
||||
|
||||
crypto._counter = 0;
|
||||
|
||||
if (native)
|
||||
crypto.cleanse = native.cleanse;
|
||||
|
||||
/**
|
||||
* Build a merkle tree from leaves.
|
||||
* @param {Buffer[]} leaves
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
"elliptic": "6.3.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"bcoin-native": "0.0.7",
|
||||
"bcoin-native": "0.0.8",
|
||||
"leveldown": "1.5.0",
|
||||
"secp256k1": "3.2.0",
|
||||
"socket.io": "1.4.8",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user