Skip to content

crypto: only partial validation of Hash argument in RegisterHash #60548

@Baselkh

Description

@Baselkh

What version of Go are you using (go version)?

$ go version
go version go1.19.1 darwin/amd64
# but please note that it's not relevant, since I'm providing references and links to go1.20.4 below.

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOOS="darwin"
# other values are irrelevant in this case

What did you do?

Browsing src/crypto/crypto.go, I've noticed that RegisterHash doesn't not validate the Hash argument in the same fashion as the rest of the package.

What did you expect to see?

I expected RegisterHash to validate that the Hash argument is bigger than 0, as the smallest Hash value defined in the package is uint 1 (MD4, which is defined with 1 + iota).
I though it's this way intentionally ...

What did you see instead?

Digging in a bit more, and trying to find an explanation or a legit use, I failed, leading me to believe that it's not intentional.
I might be wrong, since I'm not super experienced with the package, but I expect to see a comment addressing the exceptional check if it was by design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions