BN_rand_range() needs a BN_rand() variant that doesn't set the MSB.
[openssl.git] / doc / crypto / RSA_set_method.pod
1 =pod
2
3 =head1 NAME
4
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
8
9 =head1 SYNOPSIS
10
11  #include <openssl/rsa.h>
12  #include <openssl/engine.h>
13
14  void RSA_set_default_openssl_method(RSA_METHOD *meth);
15
16  RSA_METHOD *RSA_get_default_openssl_method(void);
17
18  int RSA_set_method(RSA *rsa, ENGINE *engine);
19
20  RSA_METHOD *RSA_get_method(RSA *rsa);
21
22  RSA_METHOD *RSA_PKCS1_SSLeay(void);
23
24  RSA_METHOD *RSA_null_method(void);
25
26  int RSA_flags(RSA *rsa);
27
28  RSA *RSA_new_method(ENGINE *engine);
29
30 =head1 DESCRIPTION
31
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.
35
36 Initially, the default is to use the OpenSSL internal implementation.
37 RSA_PKCS1_SSLeay() returns a pointer to that method.
38
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
44 "openssl" engine.
45
46 RSA_get_default_openssl_method() returns a pointer to the current default
47 method for the "openssl" engine.
48
49 RSA_set_method() selects B<engine> for all operations using the key
50 B<rsa>.
51
52 RSA_get_method() returns a pointer to the RSA_METHOD from the currently
53 selected ENGINE for B<rsa>.
54
55 RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
56
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.
60
61 =head1 THE RSA_METHOD STRUCTURE
62
63  typedef struct rsa_meth_st
64  {
65      /* name of the implementation */
66         const char *name;
67
68      /* encrypt */
69         int (*rsa_pub_enc)(int flen, unsigned char *from,
70           unsigned char *to, RSA *rsa, int padding);
71
72      /* verify arbitrary data */
73         int (*rsa_pub_dec)(int flen, unsigned char *from,
74           unsigned char *to, RSA *rsa, int padding);
75
76      /* sign arbitrary data */
77         int (*rsa_priv_enc)(int flen, unsigned char *from,
78           unsigned char *to, RSA *rsa, int padding);
79
80      /* decrypt */
81         int (*rsa_priv_dec)(int flen, unsigned char *from,
82           unsigned char *to, RSA *rsa, int padding);
83
84      /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
85                                         implementations) */
86         int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
87
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);
91
92      /* called at RSA_new */
93         int (*init)(RSA *rsa);
94
95      /* called at RSA_free */
96         int (*finish)(RSA *rsa);
97
98      /* RSA_FLAG_EXT_PKEY        - rsa_mod_exp is called for private key
99       *                            operations, even if p,q,dmp1,dmq1,iqmp
100       *                            are NULL
101       * RSA_FLAG_SIGN_VER        - enable rsa_sign and rsa_verify
102       * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
103       */
104         int flags;
105
106         char *app_data; /* ?? */
107
108      /* sign. For backward compatibility, this is used only
109       * if (flags & RSA_FLAG_SIGN_VER)
110       */
111         int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
112            unsigned char *sigret, unsigned int *siglen, RSA *rsa);
113
114      /* verify. For backward compatibility, this is used only
115       * if (flags & RSA_FLAG_SIGN_VER)
116       */
117         int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
118            unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
119
120  } RSA_METHOD;
121
122 =head1 RETURN VALUES
123
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.
126
127 RSA_set_default_openssl_method() returns no value.
128
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().
135
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.
139
140 =head1 SEE ALSO
141
142 L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
143
144 =head1 HISTORY
145
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.
150
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.
155
156 =cut