RSA\_SET\_METHOD(3ossl) OpenSSL RSA\_SET\_METHOD(3ossl)

# [NAME](#NAME)

RSA\_set\_default\_method, RSA\_get\_default\_method, RSA\_set\_method, RSA\_get\_method, RSA\_PKCS1\_OpenSSL, RSA\_flags, RSA\_new\_method - select RSA method

# [SYNOPSIS](#SYNOPSIS)

```
 #include <openssl/rsa.h>
```

The following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by defining **OPENSSL\_API\_COMPAT** with a suitable version value, see [**openssl\_user\_macros**(7)](/man/os/openssl-4.0/openssl_user_macros.7):

```
 void RSA_set_default_method(const RSA_METHOD *meth);
 const RSA_METHOD *RSA_get_default_method(void);
 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
 const RSA_METHOD *RSA_get_method(const RSA *rsa);
 const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
 int RSA_flags(const RSA *rsa);
 RSA *RSA_new_method(ENGINE *engine);
```

# [DESCRIPTION](#DESCRIPTION)

All of the functions described on this page are deprecated. Applications should instead use the OSSL\_PROVIDER APIs.

An **RSA\_METHOD** specifies the functions that OpenSSL uses for RSA operations. By modifying the method, alternative implementations such as hardware accelerators may be used.

Initially, the default RSA\_METHOD is the OpenSSL internal implementation, as returned by **RSA\_PKCS1\_OpenSSL()**.

**RSA\_set\_default\_method()** makes **meth** the default method for all RSA structures created later. **NB**: This function is not thread-safe and should not be called at the same time as other OpenSSL functions.

**RSA\_get\_default\_method()** returns a pointer to the current default RSA\_METHOD.

**RSA\_set\_method()** selects **meth** to perform all operations using the key **rsa**. This will replace the RSA\_METHOD used by the RSA key. It is possible to have RSA keys that only work with certain RSA\_METHOD implementations, and in such cases attempting to change the RSA\_METHOD for the key can have unexpected results.

**RSA\_get\_method()** returns a pointer to the RSA\_METHOD being used by **rsa**. The return value can only be guaranteed to be valid as long as the RSA key itself is valid and does not have its implementation changed by **RSA\_set\_method()**.

**RSA\_flags()** returns the **flags** that are set for **rsa**'s current RSA\_METHOD. See the BUGS section.

**RSA\_new\_method()** allocates and initializes an RSA structure. **engine** must be NULL and the RSA\_METHOD controlled by **RSA\_set\_default\_method()** is used.

**RSA\_flags()** returns the **flags** that are set for **rsa**'s current method.

**RSA\_new\_method()** allocates and initializes an **RSA** structure so that **method** will be used for the RSA operations. If **method** is **NULL**, the default method is used.

# [THE RSA\_METHOD STRUCTURE](#THE_RSA_METHOD_STRUCTURE)

```
 typedef struct rsa_meth_st
 {
     /* name of the implementation */
     const char *name;
     /* encrypt */
     int (*rsa_pub_enc)(int flen, unsigned char *from,
                        unsigned char *to, RSA *rsa, int padding);
     /* verify arbitrary data */
     int (*rsa_pub_dec)(int flen, unsigned char *from,
                        unsigned char *to, RSA *rsa, int padding);
     /* sign arbitrary data */
     int (*rsa_priv_enc)(int flen, unsigned char *from,
                         unsigned char *to, RSA *rsa, int padding);
     /* decrypt */
     int (*rsa_priv_dec)(int flen, unsigned char *from,
                         unsigned char *to, RSA *rsa, int padding);
     /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some implementations) */
     int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
     /* compute r = a ^ p mod m (May be NULL for some implementations) */
     int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
                       const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
     /* called at RSA_new */
     int (*init)(RSA *rsa);
     /* called at RSA_free */
     int (*finish)(RSA *rsa);
     /*
      * RSA_FLAG_EXT_PKEY        - rsa_mod_exp is called for private key
      *                            operations, even if p,q,dmp1,dmq1,iqmp
      *                            are NULL
      * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
      */
     int flags;
     char *app_data; /* ?? */
     int (*rsa_sign)(int type,
                     const unsigned char *m, unsigned int m_length,
                     unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
     int (*rsa_verify)(int dtype,
                       const unsigned char *m, unsigned int m_length,
                       const unsigned char *sigbuf, unsigned int siglen,
                       const RSA *rsa);
     /* keygen. If NULL built-in RSA key generation will be used */
     int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
 } RSA_METHOD;
```

# [RETURN VALUES](#RETURN_VALUES)

**RSA\_PKCS1\_OpenSSL()**, **RSA\_PKCS1\_null\_method()**, **RSA\_get\_default\_method()** and **RSA\_get\_method()** return pointers to the respective RSA\_METHODs.

**RSA\_set\_default\_method()** returns no value.

**RSA\_set\_method()** returns 1 for success. It always succeeds.

**RSA\_new\_method()** returns NULL and sets an error code that can be obtained by [**ERR\_get\_error**(3)](/man/os/openssl-4.0/ERR_get_error.3) if the allocation fails. Otherwise it returns a pointer to the newly allocated structure.

# [BUGS](#BUGS)

The behaviour of **RSA\_flags()** is a mis-feature that is left as-is for now to avoid creating compatibility problems. RSA functionality, such as the encryption functions, are controlled by the **flags** value in the RSA key itself, not by the **flags** value in the RSA\_METHOD attached to the RSA key (which is what this function returns). If the flags element of an RSA key is changed, the changes will be honoured by RSA functionality but will not be reflected in the return value of the **RSA\_flags()** function - in effect **RSA\_flags()** behaves more like an **RSA\_default\_flags()** function (which does not currently exist).

# [SEE ALSO](#SEE_ALSO)

[**RSA\_new**(3)](/man/os/openssl-4.0/RSA_new.3)

# [HISTORY](#HISTORY)

All of these functions were deprecated in OpenSSL 3.0.

The **RSA\_null\_method()**, which was a partial attempt to avoid patent issues, was replaced to always return NULL in OpenSSL 1.1.1.

# [COPYRIGHT](#COPYRIGHT)

Copyright 2000-2026 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at &lt;https://www.openssl.org/source/license.html&gt;.

2026-09-29 4.0.3

---

Document: RSA_PKCS1_OpenSSL(3ossl) from openssl-4.0 4.0.3-r7 (Chainguard OS)
