motoko-base icon indicating copy to clipboard operation
motoko-base copied to clipboard

Class `SHA224` in `Principal.mo` contains dead data

Open ggreif opened this issue 1 year ago • 1 comments

let ivs : [[Nat32]] = [

should be a one-dimensional array for only the first 8 values. This also implies simplifying the func reset(). Furthermore the iv in let (sum_bytes, iv) = (28, 0); can be eliminated (probably).

ggreif avatar Oct 23 '23 19:10 ggreif

Yes, iv and sum_bytes can both be eliminated from the code and their values hardcoded in the single place where they are used (e.g. iv in the reset() function).

Btw, I also noticed that the SHA224 class does not use the latest code from https://github.com/research-ag/sha2. The difference being that the current code there uses direct conversion between Nat8 <-> Nat16 <-> Nat32 and eliminates heap allocations. Anyway, probably not worth touching the whole code again.

timohanke avatar Oct 27 '23 07:10 timohanke