diff --git a/rsa.go b/rsa.go index c30e5768..a48bab3b 100644 --- a/rsa.go +++ b/rsa.go @@ -397,14 +397,15 @@ func newRSAKey3(isPriv bool, N, E, D, P, Q, Dp, Dq, Qinv BigInt) (C.GO_EVP_PKEY_ } comps = append(comps, required[:]...) - // OpenSSL 3.0 and 3.1 required all the precomputed values if - // P and Q are present. See: - // https://github.com/openssl/openssl/pull/22334 - if vMinor >= 2 || (P != nil && Q != nil && Dp != nil && Dq != nil && Qinv != nil) { - if P != nil && Q != nil { + if P != nil && Q != nil { + allPrecomputedExists := Dp != nil && Dq != nil && Qinv != nil + // OpenSSL 3.0 and 3.1 required all the precomputed values if + // P and Q are present. If they are not, we need to omit also P and Q. + // See https://github.com/openssl/openssl/pull/22334 + if vMinor >= 2 || allPrecomputedExists { comps = append(comps, bigIntParam{paramRSA_P, P}, bigIntParam{paramRSA_Q, Q}) } - if Dp != nil && Dq != nil && Qinv != nil { + if allPrecomputedExists { comps = append(comps, bigIntParam{paramRSA_Dp, Dp}, bigIntParam{paramRSA_Dq, Dq},