5 RSA_set_default_method, RSA_get_default_method, RSA_set_method,
6 RSA_get_method, RSA_PKCS1_SSLeay,
7 RSA_null_method, RSA_flags, RSA_new_method - select RSA method
11 #include <openssl/rsa.h>
12 #include <openssl/engine.h>
14 void RSA_set_default_openssl_method(RSA_METHOD *meth);
16 RSA_METHOD *RSA_get_default_openssl_method(void);
18 int RSA_set_method(RSA *rsa, ENGINE *engine);
20 RSA_METHOD *RSA_get_method(RSA *rsa);
22 RSA_METHOD *RSA_PKCS1_SSLeay(void);
24 RSA_METHOD *RSA_null_method(void);
26 int RSA_flags(RSA *rsa);
28 RSA *RSA_new_method(ENGINE *engine);
32 An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
33 operations. By modifying the method, alternative implementations
34 such as hardware accelerators may be used.
36 Initially, the default is to use the OpenSSL internal implementation.
37 RSA_PKCS1_SSLeay() returns a pointer to that method.
39 RSA_set_default_openssl_method() makes B<meth> the default method for all B<RSA>
40 structures created later. B<NB:> This is true only whilst the default engine
41 for RSA operations remains as "openssl". ENGINEs provide an
42 encapsulation for implementations of one or more algorithms at a time, and all
43 the RSA functions mentioned here operate within the scope of the default
46 RSA_get_default_openssl_method() returns a pointer to the current default
47 method for the "openssl" engine.
49 RSA_set_method() selects B<engine> for all operations using the key
52 RSA_get_method() returns a pointer to the RSA_METHOD from the currently
53 selected ENGINE for B<rsa>.
55 RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
57 RSA_new_method() allocates and initializes an RSA structure so that
58 B<engine> will be used for the RSA operations. If B<engine> is NULL,
59 the default engine for RSA operations is used.
61 =head1 THE RSA_METHOD STRUCTURE
63 typedef struct rsa_meth_st
65 /* name of the implementation */
69 int (*rsa_pub_enc)(int flen, unsigned char *from,
70 unsigned char *to, RSA *rsa, int padding);
72 /* verify arbitrary data */
73 int (*rsa_pub_dec)(int flen, unsigned char *from,
74 unsigned char *to, RSA *rsa, int padding);
76 /* sign arbitrary data */
77 int (*rsa_priv_enc)(int flen, unsigned char *from,
78 unsigned char *to, RSA *rsa, int padding);
81 int (*rsa_priv_dec)(int flen, unsigned char *from,
82 unsigned char *to, RSA *rsa, int padding);
84 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
86 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
88 /* compute r = a ^ p mod m (May be NULL for some implementations) */
89 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
90 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
92 /* called at RSA_new */
93 int (*init)(RSA *rsa);
95 /* called at RSA_free */
96 int (*finish)(RSA *rsa);
98 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
99 * operations, even if p,q,dmp1,dmq1,iqmp
101 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
102 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
106 char *app_data; /* ?? */
108 /* sign. For backward compatibility, this is used only
109 * if (flags & RSA_FLAG_SIGN_VER)
111 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
112 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
114 /* verify. For backward compatibility, this is used only
115 * if (flags & RSA_FLAG_SIGN_VER)
117 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
118 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
124 RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_openssl_method()
125 and RSA_get_method() return pointers to the respective RSA_METHODs.
127 RSA_set_default_openssl_method() returns no value.
129 RSA_set_method() selects B<engine> as the engine that will be responsible for
130 all operations using the structure B<rsa>. If this function completes successfully,
131 then the B<rsa> structure will have its own functional reference of B<engine>, so
132 the caller should remember to free their own reference to B<engine> when they are
133 finished with it. NB: An ENGINE's RSA_METHOD can be retrieved (or set) by
134 ENGINE_get_RSA() or ENGINE_set_RSA().
136 RSA_new_method() returns NULL and sets an error code that can be
137 obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise
138 it returns a pointer to the newly allocated structure.
142 L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
146 RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
147 RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
148 well as the rsa_sign and rsa_verify components of RSA_METHOD were
149 added in OpenSSL 0.9.4.
151 RSA_set_default_openssl_method() and RSA_get_default_openssl_method()
152 replaced RSA_set_default_method() and RSA_get_default_method() respectively,
153 and RSA_set_method() and RSA_new_method() were altered to use B<ENGINE>s
154 rather than B<RSA_METHOD>s during development of OpenSSL 0.9.6.