1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-13 01:58:44 +02:00

pbkdf2 not needed for hash phrase

This commit is contained in:
Kyle Spearrin 2018-11-09 08:20:54 -05:00
parent 1e6b3b4aae
commit b4fad203b9

View File

@ -690,20 +690,18 @@ export class CryptoService implements CryptoServiceAbstraction {
return okm;
}
private async hashPhrase(data: ArrayBuffer, minimumEntropy: number = 64, hashIterations: number = 50000) {
private async hashPhrase(hash: ArrayBuffer, minimumEntropy: number = 64) {
const entropyPerWord = Math.log(EEFLongWordList.length) / Math.log(2);
let numWords = Math.ceil(minimumEntropy / entropyPerWord);
const hashBuffer = await this.cryptoFunctionService.pbkdf2(data, new Uint8Array([]).buffer,
'sha256', hashIterations);
const hash = Array.from(new Uint8Array(hashBuffer));
const entropyAvailable = hash.length * 4;
const hashArr = Array.from(new Uint8Array(hash));
const entropyAvailable = hashArr.length * 4;
if (numWords * entropyPerWord > entropyAvailable) {
throw new Error('Output entropy of hash function is too small');
}
const phrase: string[] = [];
let hashNumber = bigInt.fromArray(hash, 256);
let hashNumber = bigInt.fromArray(hashArr, 256);
while (numWords--) {
const remainder = hashNumber.mod(EEFLongWordList.length);
hashNumber = hashNumber.divide(EEFLongWordList.length);