Caligatio / jsSHA

A JavaScript/TypeScript implementation of the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC.

Home Page:https://caligatio.github.io/jsSHA/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question : How to reset / clear for another hash?

z3dev opened this issue · comments

Describe the bug

Thanks for the nice library.

I'm working with an application that will create hashes for large array structures. And often times, there are several array structures to hash.

Instead of creating a new hash object, is there a way to reset / clear the hash object? I was hoping this might increase the performance by reusing the hash object.

Unfortunately there currently isn't any way to reset the internal state of a hash object.

Have you do any profiling to determine whether the object instantiation is actually a bottle neck? The constructor is relatively light - sets up a dozen-ish function pointers and small variables - so I would be surprised if that's the slowdown. The "heaviest" part of the constructor is making a copy of 64/128 integers (depends on your hashing function) which unfortunately is a core part of the algorithm.

OK. Thanks again.
I will continue on with creating a new instance.