crypto: always use buffers for hmacs.

This commit is contained in:
Christopher Jeffrey 2016-09-12 22:33:24 -07:00
parent 8f0d74d563
commit a52f239f3c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 5 additions and 9 deletions

View File

@ -126,14 +126,6 @@ crypto.checksum = function checksum(data) {
crypto.hmac = function hmac(alg, data, salt) {
var hmac;
if (native) {
if (typeof data === 'string')
data = new Buffer(data, 'utf8');
if (typeof salt === 'string')
salt = new Buffer(salt, 'utf8');
return native.hmac(alg, data, salt);
}
if (!nativeCrypto) {
hmac = hash.hmac(hash[alg], salt);
return new Buffer(hmac.update(data).digest());
@ -143,6 +135,9 @@ crypto.hmac = function hmac(alg, data, salt) {
return hmac.update(data).digest();
};
if (native)
crypto.hmac = native.hmac;
/**
* Perform key stretching using PBKDF2.
* @param {Buffer} key

View File

@ -23,6 +23,7 @@ var HD = require('./hd');
*/
var FINGER_PRINT = new Buffer('00000000', 'hex');
var SEED_SALT = new Buffer('Bitcoin seed', 'ascii');
/**
* HDPrivateKey
@ -481,7 +482,7 @@ HDPrivateKey.prototype.fromSeed = function fromSeed(seed, network) {
throw new Error('Entropy not in range.');
}
hash = crypto.hmac('sha512', seed, 'Bitcoin seed');
hash = crypto.hmac('sha512', seed, SEED_SALT);
left = hash.slice(0, 32);
right = hash.slice(32, 64);