Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 1x 1x 48x 48x 1x 47x 48x 48x 48x 1x | /**
* Copyright (c) Benjamin Ansbach - all rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
const Sha = require('@pascalcoin-sbx/common').Sha;
const BC = require('@pascalcoin-sbx/common').BC;
/**
* Key derivation function(s).
*/
class KDF {
/**
* Gets the key and iv for pascalcoin.
*
* @param {BC|Buffer|Uint8Array|String} password
* @param {Buffer|Uint8Array|BC|String} salt
* @returns {{iv: BC, key: BC}}
* @constructor
*/
static PascalCoin(password, salt = null) {
password = BC.from(password, 'string');
if (salt === null) {
salt = new BC([]);
} else {
salt = BC.from(salt);
}
// Key = sha256 (password + salt);
let key = Sha.sha256(password, salt);
// iv = sha256 (KEY + password + salt);
let iv = Sha.sha256(key, password, salt);
return { key, iv };
}
}
module.exports = KDF;
|