Skip to content

Commit

Permalink
simplify func
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Dec 13, 2024
1 parent 028b466 commit 8d39402
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8d39402

Please sign in to comment.