diff --git a/rsa.go b/rsa.go index 8ac910a..a027ced 100644 --- a/rsa.go +++ b/rsa.go @@ -33,31 +33,26 @@ func SupportsSignatureRSAPKCS1v15(ch crypto.Hash) (supported bool) { defer func() { cachePKCS1Supported.Store(ch, supported) }() - md := cryptoHashToMD(ch) - if ch != 0 && md == nil { - return false + var md C.GO_EVP_MD_PTR + if ch != 0 { + md = cryptoHashToMD(ch) + if md == nil { + return false + } } initTestRSAKey() if testRSAPkey == nil { - // The test key is not available, so we cannot determine if PKCS1 signatures are supported. - // Use SupportsHash instead as a fallback. - return SupportsHash(ch) + return false } ctx := C.go_openssl_EVP_PKEY_CTX_new(testRSAPkey, nil) if ctx == nil { return false } defer C.go_openssl_EVP_PKEY_CTX_free(ctx) - if C.go_openssl_EVP_PKEY_sign_init(ctx) != 1 { - return false - } - if C.go_openssl_EVP_PKEY_CTX_ctrl(ctx, -1, -1, C.GO_EVP_PKEY_CTRL_MD, 0, unsafe.Pointer(md)) != 1 { - return false - } - if setRSAPAdding(ctx, C.GO_RSA_PKCS1_PADDING) != nil { - return false - } - return true + + return C.go_openssl_EVP_PKEY_sign_init(ctx) == 1 && + C.go_openssl_EVP_PKEY_CTX_ctrl(ctx, -1, -1, C.GO_EVP_PKEY_CTRL_MD, 0, unsafe.Pointer(md)) == 1 && + setRSAPAdding(ctx, C.GO_RSA_PKCS1_PADDING) == nil } func GenerateKeyRSA(bits int) (N, E, D, P, Q, Dp, Dq, Qinv BigInt, err error) {