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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue