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

Reading custom amount of bytes with SHAKE

NayamAmarshe opened this issue · comments

Hi, I'm having trouble with understanding how the SHAKE function works.
So, I have an input of 64 bytes, and I'm calling shaObj.update(input) with input as a uint8array, when I do shaObj.getHash("UINT8ARRAY", { outputLen: 256 });, I get a 64 bytes of uint8array as an output.

All of this is fine but the issue is, I want to read the next 64 bytes of the output the next time shaObj.getHash() is called. Is this possible?
Currently, whenever I call the getHash() function, it gives a fixed output. I'd like for it to read the first 64 bytes of the input on first call, the next 64 bytes on the next call and so on.

Any help is appreciated.

Hi @NayamAmarshe

I'm currently in the middle of yet another international move so my ability to work on coding projects is greatly reduced. I should be able to give this some attention beginning in September.

To be clear, are you calling update with some input between getHash calls?

Hi @NayamAmarshe

I'm currently in the middle of yet another international move so my ability to work on coding projects is greatly reduced. I should be able to give this some attention beginning in September.

To be clear, are you calling update with some input between getHash calls?

Sorry for not updating the post, I've fixed the issue since then. I also have a mistake in the post where I mention 64 bytes, it should be 32 bytes instead.

So the way I fixed it is by only reading the first 8 8-bit characters from the array, so I got 64 bits and then I sliced the first 8 elements away from the array. This way, I was able to read 64 bits one by one from the input.

One question I currently have, does update append the input? For example, if I do update and then getHash, and then do an update again, does the shaObj have the previous input or does it have the current value of getHash?