Skip to content

Commit

Permalink
kdf: reduce duplicated hash computing
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun committed May 14, 2024
1 parent 765d9ec commit f8bc54f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/kdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ function bindKDF (sjcl) {
z = sjcl.codec.utf8String.toBits(z)
}
let count = 1
const hash = new Hash()
hash.update(z)
const basehash = new Hash()
basehash.update(z)
let hash = new Hash(basehash)
hash.update([count])
let ret = hash.finalize()
const hashLen = sjcl.bitArray.bitLength(ret)
Expand All @@ -27,7 +28,7 @@ function bindKDF (sjcl) {
}
for (let i = 1; i < loops; i++) {
count++
hash.update(z)
hash = new Hash(basehash)
hash.update([count])
ret = sjcl.bitArray.concat(ret, hash.finalize())
}
Expand Down

0 comments on commit f8bc54f

Please sign in to comment.