|
| 1 | +Backport github.com/golang-fips/openssl@0ec829d1b13eeb598f2de7b3278fe7138d24c1e6 |
| 2 | + |
| 3 | +diff --git a/src/vendor/github.com/golang-fips/openssl/v2/hkdf.go b/src/vendor/github.com/golang-fips/openssl/v2/hkdf.go |
| 4 | +diff --git a/src/vendor/github.com/golang-fips/openssl/v2/hkdf.go b/src/vendor/github.com/golang-fips/openssl/v2/hkdf.go |
| 5 | +index 61cf483fed..9708b5b016 100644 |
| 6 | +--- a/src/vendor/github.com/golang-fips/openssl/v2/hkdf.go |
| 7 | ++++ b/src/vendor/github.com/golang-fips/openssl/v2/hkdf.go |
| 8 | +@@ -105,11 +105,31 @@ func (c *hkdf) Read(p []byte) (int, error) { |
| 9 | + return n, nil |
| 10 | + } |
| 11 | + |
| 12 | ++// hkdfAllZerosSalt is a preallocated buffer of zeros used in ExtractHKDF(). |
| 13 | ++// The size should be kept as large as the output length of any hash algorithm |
| 14 | ++// used with HKDF. |
| 15 | ++var hkdfAllZerosSalt [64]byte |
| 16 | ++ |
| 17 | + func ExtractHKDF(h func() hash.Hash, secret, salt []byte) ([]byte, error) { |
| 18 | + c, err := newHKDF(h, C.GO_EVP_KDF_HKDF_MODE_EXTRACT_ONLY) |
| 19 | + if err != nil { |
| 20 | + return nil, err |
| 21 | + } |
| 22 | ++ |
| 23 | ++ // If calling code specifies nil salt, replace it with a buffer of hashLen |
| 24 | ++ // zeros, as specified in RFC 5896 and as OpenSSL EVP_KDF-HKDF documentation |
| 25 | ++ // instructs. Take a slice of a preallocated buffer to avoid allocating new |
| 26 | ++ // buffer per call, but fall back to allocating a buffer if preallocated |
| 27 | ++ // buffer is not large enough. |
| 28 | ++ if salt == nil { |
| 29 | ++ hlen := h().Size() |
| 30 | ++ if hlen > len(hkdfAllZerosSalt) { |
| 31 | ++ salt = make([]byte, hlen) |
| 32 | ++ } else { |
| 33 | ++ salt = hkdfAllZerosSalt[:hlen] |
| 34 | ++ } |
| 35 | ++ } |
| 36 | ++ |
| 37 | + switch vMajor { |
| 38 | + case 3: |
| 39 | + if C.go_openssl_EVP_PKEY_CTX_set1_hkdf_key(c.ctx, |
0 commit comments