Skip to content

go/crypto/sha3 : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) #71900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paocalvi opened this issue Feb 22, 2025 · 3 comments
Closed
Labels
BugReport Issues describing a possible bug in the Go implementation.
Milestone

Comments

@paocalvi
Copy link

Go version

go1.24 all versions

Output of go env in your module/workspace:

C:\Users\paoca>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=[...]
set GOENV=C:\Users\[...]\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\[...]\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\[...]\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24
set GODEBUG=

What did you do?

I tried to use golang/x/crypto/sha3 (and shake) against the NIST bit-oriented test vectors, i.e.
https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/sha3/sha3vs.pdf
chapters 6.2.1.1, 6.2.2.1, 6.3.1.1, 6.3.2.1, that are no less important than the byte oriented cases and integrant part of the NIST standard.

What did you see happen?

The embedding of SHA3 and HKDF in golang/crypto is definitely a great thing, but there is a major drawback: the implementation always lacked the "non-byte-complete" feature, implementing partially the NIST specification.
As external x package is was not straight but relatively easy to complete the missing code, implementing correctly the padding function, which is currently compliant only if with the "entire number of bytes" subcase.
Personally I inserted a new primitive "WriteLastByteFractionAndSum" in SHA3, SHAKE, KMAC, HKDF, etc....
Now that the code is "inside", there is a big obstacle in releasing code doing that,

What did you expect to see?

The insertion of primitives to add BITS to the stream to hash or at least to complete the last byte fraction before summing.

@paocalvi paocalvi changed the title golang/x/crypto : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) x/crypto : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) Feb 22, 2025
@gopherbot gopherbot added this to the Unreleased milestone Feb 22, 2025
@paocalvi paocalvi changed the title x/crypto : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) crypto : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) Feb 22, 2025
@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 22, 2025
@seankhliao seankhliao changed the title crypto : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) x/crypto/sha3 : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) Feb 22, 2025
@seankhliao
Copy link
Member

Given how as a language Go operates on bytes, it doesn't look like the referenced sections "... Bit-Oriented Input Message Implementations" are really relevant to x/crypto/sha3.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2025
@paocalvi
Copy link
Author

Not understood how the way 'go operates on bytes' justifies not being able to interoperate with NIST standard at bit level. Why to embed half of a standard in the core libraries making impossible to use that library to calculate the sha3 of '001', for example? It may be needed to verify the output of non-go software....

@paocalvi paocalvi changed the title x/crypto/sha3 : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) go/crypto/sha3 : embedding SHA3 and HKDF drawbacks (NIST Standard not fulfilled) Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

4 participants