OpenBSD manual page server

Manual Page Search Parameters

RSA_SET_METHOD(3) Library Functions Manual RSA_SET_METHOD(3)

RSA_set_default_method, RSA_get_default_method, RSA_set_method, RSA_get_method, RSA_PKCS1_SSLeay, RSA_flags, RSA_new_methodselect RSA method

#include <openssl/rsa.h>

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_SSLeay(void);

int
RSA_flags(const RSA *rsa);

RSA *
RSA_new_method(ENGINE *engine);

An RSA_METHOD object contains pointers to the functions used for RSA operations. By default, the internal implementation returned by () is used. By selecting another method, alternative implementations such as hardware accelerators may be used.

() selects meth as the default method for all RSA structures created later. If any ENGINE was registered with ENGINE_register_RSA(3) that can be successfully initialized, it overrides the default.

() returns a pointer to the current default method, even if it is actually overridden by an ENGINE.

() selects meth to perform all operations using the key rsa. This replaces the previous RSA_METHOD used by the RSA key, calling the finish function set up with RSA_meth_set_finish(3) if any, and if the previous method was supplied by an ENGINE, ENGINE_finish(3) is called on it. If meth contains an init function set up with RSA_meth_set_init(3), that function is called just before returning from RSA_set_method().

It is possible to have RSA keys that only work with certain RSA_METHOD implementations (e.g. from an ENGINE module that supports embedded hardware-protected keys), and in such cases attempting to change the RSA_METHOD for the key can have unexpected results.

() returns a pointer to the RSA_METHOD being used by rsa. This method may or may not be supplied by an ENGINE implementation 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 by RSA_set_method().

The misleadingly named function () returns the flags that are set for the current RSA_METHOD of rsa. The flags used by rsa itself can instead be tested with RSA_test_flags(3). See the BUGS section for more details.

() allocates and initializes an RSA structure so that engine is used for the RSA operations. If engine is NULL, ENGINE_get_default_RSA(3) is used. If that returns NULL, the default method controlled by RSA_set_default_method() is used.

The initial flags are copied from the RSA_METHOD object used and will not be affected by later changes to that object, but may be modified by the optional init function which may have been set up with RSA_meth_set_init(3) and which is called just before returning from ().

RSA_PKCS1_SSLeay(), RSA_get_default_method(), and RSA_get_method() return pointers to the respective RSA_METHOD.

RSA_set_method() returns 1 on success or 0 on failure. Currently, it cannot fail.

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.

ENGINE_get_default_RSA(3), ENGINE_register_RSA(3), ENGINE_set_default_RSA(3), RSA_meth_new(3), RSA_new(3)

RSA_set_default_method(), RSA_PKCS1_SSLeay(), and RSA_new_method() first appeared in SSLeay 0.8.0. RSA_flags() first appeared in SSLeay 0.9.0. These functions have been available since OpenBSD 2.4.

RSA_get_default_method(), RSA_set_method(), and RSA_get_method() as well as the rsa_sign and rsa_verify components of RSA_METHOD first appeared in OpenSSL 0.9.4 and have been available since OpenBSD 2.6.

The behaviour of RSA_flags() is a misfeature 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.

May 14, 2023 OpenBSD-7.4