-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: x/crypto: kbkdf #50136
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
Comments
cc @FiloSottile |
I sent a PR containing a proposed implementation at https://go-review.googlesource.com/c/crypto/+/371315 |
Change https://golang.org/cl/371315 mentions this issue: |
This proposal has been added to the active column of the proposals project |
For what it's worth, looks like the entirety of the public API is
In contrast, x/crypto/pbkdf2 calls the equivalent function just 'Key', and the arguments are in approximately the reverse order. (See https://pkg.go.dev/golang.org/x/crypto/pbkdf2.) It seems like at the least we should try to make kbkdf's API look as close to pbkdf2's as possible. That would mean:
unless the existing API is trying to match something else. |
Thanks, Russ. I agree, we could reorder the parameters to more closely match pbkdf's ordering. The ordering of parameters I've suggested is more based on https://pkg.go.dev/golang.org/x/crypto/hkdf. (hkdf is the newer, better PRF based KDF that TPM missed the boat on by a couple of years, it seems). KBKDF can be based on HMAC or CMAC (though I don't think the Go crypto libraries support CMAC yet - see https://pkg.go.dev/github.com/aead/cmac for what looks like a reasonable implementation). I wanted to leave room for growth, either CMAC based or other-modes. We could also implement something like func Counter(h func() hash.Hash, keyLen int, label, context []byte) []byte but this would require callers to write something like key := Counter(func() hash.Hash {return hmac.New(sha256.New, "secret")}, 32, []byte("label"), []byte("context")) and while flexible (supports bring-your-own-CMAC implementation) it seems more finnicky to use. It's also unintuitive, we would be asking for a parameter of a type called |
/cc @golang/security |
Discussed with @chrisfenner offline and I believe this does not clear the bar for addition to x/crypto:
|
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
KBKDF aka SP800-108 is a pre-HKDF NIST KDF recommentation using a PRF (e.g. HMAC).
Where used
kbkdf is used (in the HMAC-CTR mode) by TPM 2.0, which calls it KDFa. This leads Go TPM caller code to roll its own implementation of this KDF. Though the KDF is simple, it would be nice to have a cryptographer-reviewed, shared implementation at
x/crypto
.openssl has support for HMAC- and CMAC-based, counter- and feedback-mode flavors. It implements the counter-mode KDF as TPM does (i.e., with 32-bit big-endian counter and length fields, and all fields included as recommended in the NIST paper).
I will link a Gerrit code review containing a proposed implementation.
The text was updated successfully, but these errors were encountered: