---
name: "libressl-RSA_meth_new"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-RSA_meth_new"
---

# libressl-RSA\_meth\_new(3)

build up RSA methods

## NAME

**RSA\_meth\_new**, **RSA\_meth\_dup**, **RSA\_meth\_free**, **RSA\_meth\_get0\_name**, **RSA\_meth\_set1\_name**, **RSA\_meth\_get\_flags**, **RSA\_meth\_set\_flags**, **RSA\_meth\_get0\_app\_data**, **RSA\_meth\_set0\_app\_data**, **RSA\_meth\_get\_init**, **RSA\_meth\_set\_init**, **RSA\_meth\_get\_finish**, **RSA\_meth\_set\_finish**, **RSA\_meth\_get\_pub\_enc**, **RSA\_meth\_set\_pub\_enc**, **RSA\_meth\_get\_pub\_dec**, **RSA\_meth\_set\_pub\_dec**, **RSA\_meth\_get\_priv\_enc**, **RSA\_meth\_set\_priv\_enc**, **RSA\_meth\_get\_priv\_dec**, **RSA\_meth\_set\_priv\_dec**, **RSA\_meth\_get\_sign**, **RSA\_meth\_set\_sign**, **RSA\_meth\_get\_verify**, **RSA\_meth\_set\_verify**, **RSA\_meth\_get\_mod\_exp**, **RSA\_meth\_set\_mod\_exp**, **RSA\_meth\_get\_bn\_mod\_exp**, **RSA\_meth\_set\_bn\_mod\_exp**, **RSA\_meth\_get\_keygen**, **RSA\_meth\_set\_keygen** – build up RSA methods

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/rsa.h\>**

*RSA\_METHOD* *\**\

**RSA\_meth\_new**(*const char \*name*, *int flags*);

*RSA\_METHOD* *\**\

**RSA\_meth\_dup**(*const RSA\_METHOD \*meth*);

*void*\

**RSA\_meth\_free**(*RSA\_METHOD \*meth*);

*const* *char* *\**\

**RSA\_meth\_get0\_name**(*const RSA\_METHOD \*meth*);

*int*\

**RSA\_meth\_set1\_name**(*RSA\_METHOD \*meth*, *const char \*name*);

*int*\

**RSA\_meth\_get\_flags**(*const RSA\_METHOD \*meth*);

*int*\

**RSA\_meth\_set\_flags**(*RSA\_METHOD \*meth*, *int flags*);

*void* *\**\

**RSA\_meth\_get0\_app\_data**(*const RSA\_METHOD \*meth*);

*int*\

**RSA\_meth\_set0\_app\_data**(*RSA\_METHOD \*meth*, *void \*app\_data*);

*int*\

**(\*RSA\_meth\_get\_init(const RSA\_METHOD \*meth))**(*RSA \*rsa*);

*int*\

**RSA\_meth\_set\_init**(*RSA\_METHOD \*meth*, *int (\*init)(RSA \*rsa)*);

*int*\

**(\*RSA\_meth\_get\_finish(const RSA\_METHOD \*meth))**(*RSA \*rsa*);

*int*\

**RSA\_meth\_set\_finish**(*RSA\_METHOD \*meth*, *int (\*finish)(RSA \*rsa)*);

*int*\

**(\*RSA\_meth\_get\_pub\_enc(const RSA\_METHOD \*meth))**(*int flen*, *const unsigned char \*from*, *unsigned char \*to*, *RSA \*rsa*, *int padding*);

*int*\

**RSA\_meth\_set\_pub\_enc**(*RSA\_METHOD \*meth*, *int (\*pub\_enc)(int flen, const unsigned char \*from, unsigned char \*to, RSA \*rsa, int padding)*);

*int*\

**(\*RSA\_meth\_get\_pub\_dec(const RSA\_METHOD \*meth))**(*int flen*, *const unsigned char \*from*, *unsigned char \*to*, *RSA \*rsa*, *int padding*);

*int*\

**RSA\_meth\_set\_pub\_dec**(*RSA\_METHOD \*meth*, *int (\*pub\_dec)(int flen, const unsigned char \*from, unsigned char \*to, RSA \*rsa, int padding)*);

*int*\

**(\*RSA\_meth\_get\_priv\_enc(const RSA\_METHOD \*meth))**(*int flen*, *const unsigned char \*from*, *unsigned char \*to*, *RSA \*rsa*, *int padding*);

*int*\

**RSA\_meth\_set\_priv\_enc**(*RSA\_METHOD \*meth*, *int (\*priv\_enc)(int flen, const unsigned char \*from, unsigned char \*to, RSA \*rsa, int padding)*);

*int*\

**(\*RSA\_meth\_get\_priv\_dec(const RSA\_METHOD \*meth))**(*int flen*, *const unsigned char \*from*, *unsigned char \*to*, *RSA \*rsa*, *int padding*);

*int*\

**RSA\_meth\_set\_priv\_dec**(*RSA\_METHOD \*meth*, *int (\*priv\_dec)(int flen, const unsigned char \*from, unsigned char \*to, RSA \*rsa, int padding)*);

*int*\

**(\*RSA\_meth\_get\_sign(const RSA\_METHOD \*meth))**(*int type*, *const unsigned char \*m*, *unsigned int m\_length*, *unsigned char \*sigret*, *unsigned int \*siglen*, *const RSA \*rsa*);

*int*\

**RSA\_meth\_set\_sign**(*RSA\_METHOD \*rsa*, *int (\*sign)(int type, const unsigned char \*m, unsigned int m\_length, unsigned char \*sigret, unsigned int \*siglen, const RSA \*rsa)*);

*int*\

**(\*RSA\_meth\_get\_verify(const RSA\_METHOD \*meth))**(*int dtype*, *const unsigned char \*m*, *unsigned int m\_length*, *const unsigned char \*sigbuf*, *unsigned int siglen*, *const RSA \*rsa*);

*int*\

**RSA\_meth\_set\_verify**(*RSA\_METHOD \*rsa*, *int (\*verify)(int dtype, const unsigned char \*m, unsigned int m\_length, const unsigned char \*sigbuf, unsigned int siglen, const RSA \*rsa)*);

*int*\

**(\*RSA\_meth\_get\_mod\_exp(const RSA\_METHOD \*meth))**(*BIGNUM \*r0*, *const BIGNUM \*i*, *RSA \*rsa*, *BN\_CTX \*ctx*);

*int*\

**RSA\_meth\_set\_mod\_exp**(*RSA\_METHOD \*meth*, *int (\*mod\_exp)(BIGNUM \*r0, const BIGNUM \*i, RSA \*rsa, BN\_CTX \*ctx)*);

*int*\

**(\*RSA\_meth\_get\_bn\_mod\_exp(const RSA\_METHOD \*meth))**(*BIGNUM \*r*, *const BIGNUM \*a*, *const BIGNUM \*p*, *const BIGNUM \*m*, *BN\_CTX \*ctx*, *BN\_MONT\_CTX \*m\_ctx*);

*int*\

**RSA\_meth\_set\_bn\_mod\_exp**(*RSA\_METHOD \*meth*, *int (\*bn\_mod\_exp)(BIGNUM \*r, const BIGNUM \*a, const BIGNUM \*p, const BIGNUM \*m, BN\_CTX \*ctx, BN\_MONT\_CTX \*m\_ctx)*);

*int*\

**(\*RSA\_meth\_get\_keygen(const RSA\_METHOD \*meth))**(*RSA \*rsa*, *int bits*, *BIGNUM \*e*, *BN\_GENCB \*cb*);

*int*\

**RSA\_meth\_set\_keygen**(*RSA\_METHOD \*meth*, *int (\*keygen)(RSA \*rsa, int bits, BIGNUM \*e, BN\_GENCB \*cb)*);

## DESCRIPTION

The *RSA\_METHOD* structure holds function pointers for custom RSA implementations.

**RSA\_meth\_new**() creates a new *RSA\_METHOD* structure. A copy of the NUL-terminated *name* is stored in the new *RSA\_METHOD* object. Any new *RSA* object constructed from this *RSA\_METHOD* will have the given *flags* set by default, as if they were set with RSA\_set\_flags(3).

**RSA\_meth\_dup**() creates a deep copy of *meth*, except that a pointer stored into it with **RSA\_meth\_set0\_app\_data**() is copied as a pointer without creating a copy of its content. This might be useful for creating a new *RSA\_METHOD* based on an existing one, but with some differences.

**RSA\_meth\_free**() destroys *meth* and frees any memory associated with it, except that memory pointed to by a pointer set with **RSA\_meth\_set0\_app\_data**() is not freed. If *meth* is NULL, no action occurs.

**RSA\_meth\_get0\_name**() returns an internal pointer to the name of *meth*. **RSA\_meth\_set1\_name**() stores a copy of the NUL-terminated *name* in the *RSA\_METHOD* object after freeing the previously stored name. Method names are ignored by the default RSA implementation but can be used by alternative implementations and by the application program.

**RSA\_meth\_get\_flags**() retrieves the flags from *meth*. Flags are documented in RSA\_test\_flags(3). **RSA\_meth\_set\_flags**() overwrites all flags in *meth*. Unlike RSA\_set\_flags(3), it does not preserve any flags that were set before the call.

**RSA\_meth\_get0\_app\_data**() and **RSA\_meth\_set0\_app\_data**() get and set a pointer to implementation-specific data. The function **RSA\_meth\_free**() does not [free(3)](/free/3.md) the memory pointed to by *app\_data*. The default RSA implementation does not use *app\_data*.

**RSA\_meth\_get\_init**() and **RSA\_meth\_set\_init**() get and set an optional function used when creating a new *RSA* object. Unless *init* is NULL, it will be called at the end of RSA\_new(3), RSA\_new\_method(3), and RSA\_set\_method(3), passing a pointer to the newly allocated or reset *RSA* object as an argument. The default RSA implementation, RSA\_PKCS1\_SSLeay(3), contains an *init* function equivalent to calling RSA\_set\_flags(3) with an argument of RSA\_FLAG\_CACHE\_PUBLIC \| RSA\_FLAG\_CACHE\_PRIVATE.

**RSA\_meth\_get\_finish**() and **RSA\_meth\_set\_finish**() get and set an optional function for destroying an *RSA* object. Unless *finish* is NULL, it will be called from RSA\_set\_method(3) and from RSA\_free(3). It takes the same argument as RSA\_free(3) and is intended to do RSA implementation specific cleanup. The memory used by the *RSA* object itself should not be freed by the *finish* function. The default RSA implementation contains a *finish* function freeing the memory used by the RSA\_FLAG\_CACHE\_PUBLIC and RSA\_FLAG\_CACHE\_PRIVATE caches.

**RSA\_meth\_get\_pub\_enc**(), **RSA\_meth\_set\_pub\_enc**(), **RSA\_meth\_get\_pub\_dec**(), **RSA\_meth\_set\_pub\_dec**(), **RSA\_meth\_get\_priv\_enc**(), **RSA\_meth\_set\_priv\_enc**(), **RSA\_meth\_get\_priv\_dec**(), and **RSA\_meth\_set\_priv\_dec**() get and set the mandatory functions used for public and private key encryption and decryption. These functions will be called from RSA\_public\_encrypt(3), RSA\_public\_decrypt(3), RSA\_private\_encrypt(3), and RSA\_private\_decrypt(3), respectively, and take the same parameters as those.

**RSA\_meth\_get\_sign**(), **RSA\_meth\_set\_sign**(), **RSA\_meth\_get\_verify**(), and **RSA\_meth\_set\_verify**() get and set the optional functions used for creating and verifying an RSA signature.

**RSA\_meth\_get\_mod\_exp**() and **RSA\_meth\_set\_mod\_exp**() get and set the function used for Chinese Remainder Theorem (CRT) computations involving the *p*, *q*, *dmp1*, *dmq1*, and *iqmp* fields of an *RSA* object. It is used by the default RSA implementation during RSA\_private\_encrypt(3) and RSA\_private\_decrypt(3) when the required components of the private key are available or when the RSA\_FLAG\_EXT\_PKEY flag is set.

**RSA\_meth\_get\_bn\_mod\_exp**() and **RSA\_meth\_set\_bn\_mod\_exp**() get and set the function used for CRT computations, specifically the value r = *a* ^ *p* mod *m*. It is used by the default RSA implementation during RSA\_public\_encrypt(3) and RSA\_public\_decrypt(3) and as a fallback during RSA\_private\_encrypt(3) and RSA\_private\_decrypt(3).

**RSA\_meth\_get\_keygen**() and **RSA\_meth\_set\_keygen**() get and set the optional function used for generating a new RSA key pair. Unless *keygen* is NULL, it will be called from RSA\_generate\_key\_ex(3) and takes the same parameters. Otherwise, a builtin default implementation is used.

## RETURN VALUES

**RSA\_meth\_new**() and **RSA\_meth\_dup**() return the newly allocated *RSA\_METHOD* object or NULL on failure.

**RSA\_meth\_get0\_name**() returns an internal pointer which must not be freed by the caller.

**RSA\_meth\_get\_flags**() returns zero or more RSA\_FLAG\_\* constants OR'ed together, or 0 if no flags are set in *meth*.

**RSA\_meth\_get0\_app\_data**() returns the pointer that was earlier passed to **RSA\_meth\_set0\_app\_data**() or NULL otherwise.

All other **RSA\_meth\_get\_\***() functions return the appropriate function pointer that has been set with the corresponding **RSA\_meth\_set\_\***() function, or NULL if no such pointer has been set in *meth*.

All **RSA\_meth\_set\***() functions return 1 on success or 0 on failure. In the current implementation, only **RSA\_meth\_set1\_name**() can actually fail.

## SEE ALSO

RSA\_generate\_key\_ex(3), RSA\_new(3), RSA\_private\_encrypt(3), RSA\_public\_encrypt(3), RSA\_set\_flags(3), RSA\_set\_method(3), RSA\_sign(3)

## HISTORY

These functions first appeared in OpenSSL 1.1.0. **RSA\_meth\_new**(), **RSA\_meth\_dup**(), **RSA\_meth\_free**(), **RSA\_meth\_set\_finish**(), **RSA\_meth\_set\_priv\_enc**(), and **RSA\_meth\_set\_priv\_dec**() have been available since OpenBSD 6.3, **RSA\_meth\_set1\_name**() and **RSA\_meth\_get\_finish**() since OpenBSD 6.4, and **RSA\_meth\_get0\_name**(), **RSA\_meth\_get\_flags**(), **RSA\_meth\_set\_flags**(), **RSA\_meth\_get0\_app\_data**(), **RSA\_meth\_set0\_app\_data**(), **RSA\_meth\_get\_init**(), **RSA\_meth\_set\_init**(), **RSA\_meth\_set\_finish**(), **RSA\_meth\_get\_pub\_enc**(), **RSA\_meth\_set\_pub\_enc**(), **RSA\_meth\_get\_pub\_dec**(), **RSA\_meth\_set\_pub\_dec**(), **RSA\_meth\_get\_priv\_enc**(), **RSA\_meth\_get\_priv\_dec**(), **RSA\_meth\_get\_sign**(), **RSA\_meth\_set\_sign**(), **RSA\_meth\_get\_verify**(), **RSA\_meth\_set\_verify**(), **RSA\_meth\_get\_mod\_exp**(), **RSA\_meth\_set\_mod\_exp**(), **RSA\_meth\_get\_bn\_mod\_exp**(), **RSA\_meth\_set\_bn\_mod\_exp**(), **RSA\_meth\_get\_keygen**(), and **RSA\_meth\_set\_keygen**() since OpenBSD 6.6.
