crypto: always use buffers for hmacs.
This commit is contained in:
parent
8f0d74d563
commit
a52f239f3c
@ -126,14 +126,6 @@ crypto.checksum = function checksum(data) {
|
|||||||
crypto.hmac = function hmac(alg, data, salt) {
|
crypto.hmac = function hmac(alg, data, salt) {
|
||||||
var hmac;
|
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) {
|
if (!nativeCrypto) {
|
||||||
hmac = hash.hmac(hash[alg], salt);
|
hmac = hash.hmac(hash[alg], salt);
|
||||||
return new Buffer(hmac.update(data).digest());
|
return new Buffer(hmac.update(data).digest());
|
||||||
@ -143,6 +135,9 @@ crypto.hmac = function hmac(alg, data, salt) {
|
|||||||
return hmac.update(data).digest();
|
return hmac.update(data).digest();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (native)
|
||||||
|
crypto.hmac = native.hmac;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform key stretching using PBKDF2.
|
* Perform key stretching using PBKDF2.
|
||||||
* @param {Buffer} key
|
* @param {Buffer} key
|
||||||
|
|||||||
@ -23,6 +23,7 @@ var HD = require('./hd');
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var FINGER_PRINT = new Buffer('00000000', 'hex');
|
var FINGER_PRINT = new Buffer('00000000', 'hex');
|
||||||
|
var SEED_SALT = new Buffer('Bitcoin seed', 'ascii');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HDPrivateKey
|
* HDPrivateKey
|
||||||
@ -481,7 +482,7 @@ HDPrivateKey.prototype.fromSeed = function fromSeed(seed, network) {
|
|||||||
throw new Error('Entropy not in range.');
|
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);
|
left = hash.slice(0, 32);
|
||||||
right = hash.slice(32, 64);
|
right = hash.slice(32, 64);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user