mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
pbkdf2 not needed for hash phrase
This commit is contained in:
parent
1e6b3b4aae
commit
b4fad203b9
@ -690,20 +690,18 @@ export class CryptoService implements CryptoServiceAbstraction {
|
|||||||
return okm;
|
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);
|
const entropyPerWord = Math.log(EEFLongWordList.length) / Math.log(2);
|
||||||
let numWords = Math.ceil(minimumEntropy / entropyPerWord);
|
let numWords = Math.ceil(minimumEntropy / entropyPerWord);
|
||||||
|
|
||||||
const hashBuffer = await this.cryptoFunctionService.pbkdf2(data, new Uint8Array([]).buffer,
|
const hashArr = Array.from(new Uint8Array(hash));
|
||||||
'sha256', hashIterations);
|
const entropyAvailable = hashArr.length * 4;
|
||||||
const hash = Array.from(new Uint8Array(hashBuffer));
|
|
||||||
const entropyAvailable = hash.length * 4;
|
|
||||||
if (numWords * entropyPerWord > entropyAvailable) {
|
if (numWords * entropyPerWord > entropyAvailable) {
|
||||||
throw new Error('Output entropy of hash function is too small');
|
throw new Error('Output entropy of hash function is too small');
|
||||||
}
|
}
|
||||||
|
|
||||||
const phrase: string[] = [];
|
const phrase: string[] = [];
|
||||||
let hashNumber = bigInt.fromArray(hash, 256);
|
let hashNumber = bigInt.fromArray(hashArr, 256);
|
||||||
while (numWords--) {
|
while (numWords--) {
|
||||||
const remainder = hashNumber.mod(EEFLongWordList.length);
|
const remainder = hashNumber.mod(EEFLongWordList.length);
|
||||||
hashNumber = hashNumber.divide(EEFLongWordList.length);
|
hashNumber = hashNumber.divide(EEFLongWordList.length);
|
||||||
|
Loading…
Reference in New Issue
Block a user