Skip to content
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

Support TLS PRF #44

Merged
merged 3 commits into from
Sep 8, 2023
Merged

Support TLS PRF #44

merged 3 commits into from
Sep 8, 2023

Conversation

qmuntal
Copy link
Member

@qmuntal qmuntal commented Aug 24, 2023

This PR is the CNG counterpart for golang-fips/openssl#103, golang-fips/openssl#109, and golang-fips/openssl#110.

Description taken from those PRs:

Go 1.21 implements TLS extended master secret (RFC 7627), which uses a different label ("extended master secret") than the original TLS 1.2 PRF ("master secret"). The use of EMS is now required by FIPS 140-3 IG D.Q., and thus the logic needs to be provided by a FIPS certified module (OpenSSL). This adds a new function openssl.TLS1PRF for that.

In other words, crypto/tls implements an algorithm (here that should be provided by OpenSSL/CNG.

cng/tls1prf.go Outdated
algID := bcrypt.TLS1_1_KDF_ALGORITHM
var hashID string
if h != nil {
// TLS 1.0/1.1 PRF doesn't allow to specify the hash function,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: might want to move this comment above, it was kind of confusing as its explaining what just happened vs what's about to happen (also possible I'm just being slow today, but it took me a minute to understand)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I would probably go further and negate it and split it up so it describes what's happening:

func TLS1PRF(secret, label, seed []byte, keyLen int, h func() hash.Hash) ([]byte, error) {
	// TLS 1.0/1.1 PRF uses MD5SHA1.
	algID := bcrypt.TLS1_1_KDF_ALGORITHM
	var hashID string
	if h != nil {
		// If h is specified, assume the caller wants to use TLS 1.2 PRF.
		// TLS 1.0/1.1 PRF doesn't allow specifying the hash function.
		if hashID = hashToID(h()); hashID == "" {
			return nil, errors.New("cng: unsupported hash function")
		}
		algID = bcrypt.TLS1_2_KDF_ALGORITHM
	}

@qmuntal qmuntal merged commit 71718e9 into main Sep 8, 2023
@qmuntal qmuntal deleted the tlsprf branch September 8, 2023 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants