Skip to content

Commit

Permalink
Fix sha2 check, can be dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Dec 2, 2022
1 parent 0d37cca commit 770f8a3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/_sha2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export abstract class SHA2<T extends SHA2<T>> extends Hash<T> {
super();
this.buffer = new Uint8Array(blockLen);
this.view = createView(this.buffer);
if (this.outputLen % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');
}
update(data: Input): this {
assert.exists(this);
Expand Down Expand Up @@ -90,7 +89,9 @@ export abstract class SHA2<T extends SHA2<T>> extends Hash<T> {
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
this.process(view, 0);
const oview = createView(out);
const outLen = this.outputLen / 4;
const oLen = this.outputLen;
if (oLen % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');
const outLen = oLen / 4;
const state = this.get();
if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
Expand Down

0 comments on commit 770f8a3

Please sign in to comment.