crypto: add cleanse function.

This commit is contained in:
Christopher Jeffrey 2016-11-09 17:02:54 -08:00
parent c3a9b7378f
commit 53de684b4a
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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",