Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
pbkdf2 not needed for hash phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Nov 9, 2018
1 parent 1e6b3b4 commit b4fad20
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/services/crypto.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b4fad20

Please sign in to comment.