Open emersion opened 7 months ago
This is a bug, the code shouldn't panic, but instead it should return an error. in #489 , code enforces to pass slices of the exact size for unmarshaling keys.
Not sure whether it's a bug to panic when the caller breaks the function contract. Not opposed to returning an error instead though.
I don't see where this function contract is defined? Nothing in https://pkg.go.dev/github.com/cloudflare/circl@v1.3.8/kem#Scheme
IMHO, panic'ing would be OK if it was documented and if it used an explicit check with a proper error message (instead of an out of bounds error).
However, please note that other functions with documented panics don't return an error
(so don't really have a choice). UnmarshalBinaryPrivateKey
does return an error. Moreover, "Unmarshal" is a kind of parsing step, and parsing deals with user-provided input. Panic'ing on bad user-provided input (such as fed from a network protocol) isn't super nice.
When passing a byte slice of size > 66 bytes to
shortKEM.UnmarshalBinaryPrivateKey
when using theDHKEM(P-521, HKDF-SHA512)
KEM, the following panic is triggered: