Skip to content

Commit

Permalink
fallback to SupportsHash
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Dec 13, 2024
1 parent 3284129 commit 41bb6ef
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import (

var testRSAPkey C.GO_EVP_PKEY_PTR

// Use sync.OnceFunc instead of sync.OnceValue to avoid the
// memory sanitizer from incorrectly reporting the result as a leak.
var initTestRSAKey = sync.OnceFunc(func() {
testRSAPkey, _ = generateEVPPKey(C.GO_EVP_PKEY_RSA, 512, "")
if testRSAPkey == nil {
// Try with a larger key.
testRSAPkey, _ = generateEVPPKey(C.GO_EVP_PKEY_RSA, 1024, "")
}
testRSAPkey, _ = generateEVPPKey(C.GO_EVP_PKEY_RSA, 1024, "")
})

var cachePKCS1Supported sync.Map
Expand All @@ -41,7 +39,9 @@ func SupportsSignatureRSAPKCS1v15(ch crypto.Hash) (supported bool) {
}
initTestRSAKey()
if testRSAPkey == nil {
return false
// The test key is not available, so we cannot determine if PKCS1 signatures are supported.
// Use SupportsHash instead as a fallback.
return SupportsHash(ch)
}
ctx := C.go_openssl_EVP_PKEY_CTX_new(testRSAPkey, nil)
if ctx == nil {
Expand Down

0 comments on commit 41bb6ef

Please sign in to comment.