RSA_SET_METHOD(3ossl)
๐ RSA_SET_METHOD ๐
okay so welcome to the RSA_SET_METHOD page from the OpenSSL manual โ manual name: OpenSSL, section: 3ossl, and this page is giving major deprecated API energy. Buckle up, bestie. ๐ซถ
๐ธ NAME ๐ธ
This page is about RSA_set_default_method, RSA_get_default_method, RSA_set_method, RSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags, and RSA_new_method โ and their whole thing is select RSA method. ๐
โจ SYNOPSIS โจ
#include <openssl/rsa.h>
The following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by definingOPENSSL_API_COMPATwith a suitable version value, seeopenssl_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 ๐
All of the functions described on this page are deprecated. Applications should instead use the OSSL_PROVIDER APIs. periodt. ๐ญ
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. IMPORTANT: See the NOTES section for important information about how these RSA API functions are affected by the use of ENGINE API calls. ๐
Initially, the default RSA_METHOD is the OpenSSL internal implementation, as returned by RSA_PKCS1_OpenSSL().
RSA_set_default_method()โ makesmeththe default method for allRSAstructures created later. NB: This is true only whilst noENGINEhas been set as a default for RSA, so this function is no longer recommended. 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 defaultRSA_METHOD. However, the meaningfulness of this result is dependent on whether theENGINEAPI is being used, so this function is no longer recommended.RSA_set_method()โ selectsmethto perform all operations using the keyrsa. This will replace theRSA_METHODused by the RSA key and if the previous method was supplied by anENGINE, the handle to thatENGINEwill be released during the change. It is possible to have RSA keys that only work with certainRSA_METHODimplementations (e.g. from anENGINEmodule that supports embedded hardware-protected keys), and in such cases attempting to change theRSA_METHODfor the key can have unexpected results. ๐RSA_get_method()โ returns a pointer to theRSA_METHODbeing used byrsa. This method may or may not be supplied by anENGINEimplementation, but if it is, 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 byRSA_set_method().RSA_flags()โ returns the flags that are set forrsa's currentRSA_METHOD. See theBUGSsection. ๐RSA_new_method()โ allocates and initializes anRSAstructure so thatenginewill be used for the RSA operations. IfengineisNULL, the defaultENGINEfor RSA operations is used, and if no defaultENGINEis set, theRSA_METHODcontrolled byRSA_set_default_method()is used.
Also, the page literally repeats these next two, so here they are again, bestie:
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 ๐ฎ
okay this is the whole struct, and yes it's giving "vintage C code" but we keep it exactly:
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 ๐
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 a pointer to the old RSA_METHOD implementation that was replaced. However, this return value should probably be ignored because if it was supplied by an ENGINE, the pointer could be invalidated at any time if the ENGINE is unloaded (in fact it could be unloaded as a result of the RSA_set_method() function releasing its handle to the ENGINE). For this reason, the return type may be replaced with a void declaration in a future release. ๐ฌ
RSA_new_method() returns NULL and sets an error code that can be obtained by ERR_get_error(3) if the allocation fails. Otherwise it returns a pointer to the newly allocated structure. ๐ซถ
๐ 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 ๐
๐ฆ 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 2000-2020 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 <https://www.openssl.org/source/license.html>.
later, bestie ๐ this was the RSA_SET_METHOD(3ossl) page from OpenSSL 3.5.0, dated 2026-09-25 โ mwah ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms