golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.18k stars 17.37k forks source link

x/crypto/blake2b: provide reset that allows specifying a new key #35633

Open josharian opened 4 years ago

josharian commented 4 years ago

blake2b digests are pretty large. They account for 60% of allocated space in my benchmark, so they're a good candidate for re-use, except that (at least in my case, PASETO), I need to use a new key every time. It'd be nice if there was a reset function that let me specify a new key.

The API options for this aren't particularly nice, since the blake2b functions all return hash.Hash instead of a concrete type. The two options I see are: (1) provide a package-level ResetKey function that accepts a hash.Hash and panics if given the wrong kind of hash, and (2) provide a package-level ResetKey interface and promise that blake2b hash.Hashes can be type-asserted to that interface. (Or some other name. The reset should perhaps also accept a new size.)

If there's API consensus, I can try my hand at implementing.

cc the three people who have touched that file: @aead @rasa @ValarDragon

aead commented 4 years ago

/cc @FiloSottile

josharian commented 4 years ago

ping @FiloSottile