Skip to content

Commit

Permalink
fix SupportsHKDF (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal authored Sep 16, 2024
1 parent ca2d3b7 commit 3bd2326
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions hkdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ import (
"unsafe"
)

// SupprtHKDF reports whether the current OpenSSL version supports HKDF.
func SupportsHKDF() bool {
ctx := C.go_openssl_EVP_PKEY_CTX_new_id(C.GO_EVP_PKEY_HKDF, nil)
if ctx == nil {
return false
switch vMajor {
case 1:
return versionAtOrAbove(1, 1, 1)
case 3:
// Some OpenSSL 3 providers don't support HKDF or don't support it via
// the EVP_PKEY API, which is the one we use.
// See https://github.com/golang-fips/openssl/issues/189.
ctx := C.go_openssl_EVP_PKEY_CTX_new_id(C.GO_EVP_PKEY_HKDF, nil)
if ctx == nil {
return false
}
C.go_openssl_EVP_PKEY_CTX_free(ctx)
return true
default:
panic(errUnsupportedVersion())
}
C.go_openssl_EVP_PKEY_CTX_free(ctx)
return false
}

func newHKDF(h func() hash.Hash, mode C.int) (*hkdf, error) {
Expand Down

0 comments on commit 3bd2326

Please sign in to comment.