diff options
Diffstat (limited to 'src/lib/libcrypto/doc/RSA_set_method.pod')
-rw-r--r-- | src/lib/libcrypto/doc/RSA_set_method.pod | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/src/lib/libcrypto/doc/RSA_set_method.pod b/src/lib/libcrypto/doc/RSA_set_method.pod new file mode 100644 index 0000000000..0687c2242a --- /dev/null +++ b/src/lib/libcrypto/doc/RSA_set_method.pod | |||
@@ -0,0 +1,197 @@ | |||
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_method(const RSA_METHOD *meth); | ||
15 | |||
16 | RSA_METHOD *RSA_get_default_method(void); | ||
17 | |||
18 | int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); | ||
19 | |||
20 | RSA_METHOD *RSA_get_method(const RSA *rsa); | ||
21 | |||
22 | RSA_METHOD *RSA_PKCS1_SSLeay(void); | ||
23 | |||
24 | RSA_METHOD *RSA_null_method(void); | ||
25 | |||
26 | int RSA_flags(const 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 such as | ||
34 | hardware accelerators may be used. IMPORTANT: See the NOTES section for | ||
35 | important information about how these RSA API functions are affected by the | ||
36 | use of B<ENGINE> API calls. | ||
37 | |||
38 | Initially, the default RSA_METHOD is the OpenSSL internal implementation, | ||
39 | as returned by RSA_PKCS1_SSLeay(). | ||
40 | |||
41 | RSA_set_default_method() makes B<meth> the default method for all RSA | ||
42 | structures created later. B<NB>: This is true only whilst no ENGINE has | ||
43 | been set as a default for RSA, so this function is no longer recommended. | ||
44 | |||
45 | RSA_get_default_method() returns a pointer to the current default | ||
46 | RSA_METHOD. However, the meaningfulness of this result is dependant on | ||
47 | whether the ENGINE API is being used, so this function is no longer | ||
48 | recommended. | ||
49 | |||
50 | RSA_set_method() selects B<meth> to perform all operations using the key | ||
51 | B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the | ||
52 | previous method was supplied by an ENGINE, the handle to that ENGINE will | ||
53 | be released during the change. It is possible to have RSA keys that only | ||
54 | work with certain RSA_METHOD implementations (eg. from an ENGINE module | ||
55 | that supports embedded hardware-protected keys), and in such cases | ||
56 | attempting to change the RSA_METHOD for the key can have unexpected | ||
57 | results. | ||
58 | |||
59 | RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>. | ||
60 | This method may or may not be supplied by an ENGINE implementation, but if | ||
61 | it is, the return value can only be guaranteed to be valid as long as the | ||
62 | RSA key itself is valid and does not have its implementation changed by | ||
63 | RSA_set_method(). | ||
64 | |||
65 | RSA_flags() returns the B<flags> that are set for B<rsa>'s current | ||
66 | RSA_METHOD. See the BUGS section. | ||
67 | |||
68 | RSA_new_method() allocates and initializes an RSA structure so that | ||
69 | B<engine> will be used for the RSA operations. If B<engine> is NULL, the | ||
70 | default ENGINE for RSA operations is used, and if no default ENGINE is set, | ||
71 | the RSA_METHOD controlled by RSA_set_default_method() is used. | ||
72 | |||
73 | =head1 THE RSA_METHOD STRUCTURE | ||
74 | |||
75 | typedef struct rsa_meth_st | ||
76 | { | ||
77 | /* name of the implementation */ | ||
78 | const char *name; | ||
79 | |||
80 | /* encrypt */ | ||
81 | int (*rsa_pub_enc)(int flen, unsigned char *from, | ||
82 | unsigned char *to, RSA *rsa, int padding); | ||
83 | |||
84 | /* verify arbitrary data */ | ||
85 | int (*rsa_pub_dec)(int flen, unsigned char *from, | ||
86 | unsigned char *to, RSA *rsa, int padding); | ||
87 | |||
88 | /* sign arbitrary data */ | ||
89 | int (*rsa_priv_enc)(int flen, unsigned char *from, | ||
90 | unsigned char *to, RSA *rsa, int padding); | ||
91 | |||
92 | /* decrypt */ | ||
93 | int (*rsa_priv_dec)(int flen, unsigned char *from, | ||
94 | unsigned char *to, RSA *rsa, int padding); | ||
95 | |||
96 | /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some | ||
97 | implementations) */ | ||
98 | int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa); | ||
99 | |||
100 | /* compute r = a ^ p mod m (May be NULL for some implementations) */ | ||
101 | int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
102 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
103 | |||
104 | /* called at RSA_new */ | ||
105 | int (*init)(RSA *rsa); | ||
106 | |||
107 | /* called at RSA_free */ | ||
108 | int (*finish)(RSA *rsa); | ||
109 | |||
110 | /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key | ||
111 | * operations, even if p,q,dmp1,dmq1,iqmp | ||
112 | * are NULL | ||
113 | * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify | ||
114 | * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match | ||
115 | */ | ||
116 | int flags; | ||
117 | |||
118 | char *app_data; /* ?? */ | ||
119 | |||
120 | /* sign. For backward compatibility, this is used only | ||
121 | * if (flags & RSA_FLAG_SIGN_VER) | ||
122 | */ | ||
123 | int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len, | ||
124 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
125 | |||
126 | /* verify. For backward compatibility, this is used only | ||
127 | * if (flags & RSA_FLAG_SIGN_VER) | ||
128 | */ | ||
129 | int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len, | ||
130 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
131 | |||
132 | } RSA_METHOD; | ||
133 | |||
134 | =head1 RETURN VALUES | ||
135 | |||
136 | RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method() | ||
137 | and RSA_get_method() return pointers to the respective RSA_METHODs. | ||
138 | |||
139 | RSA_set_default_method() returns no value. | ||
140 | |||
141 | RSA_set_method() returns a pointer to the old RSA_METHOD implementation | ||
142 | that was replaced. However, this return value should probably be ignored | ||
143 | because if it was supplied by an ENGINE, the pointer could be invalidated | ||
144 | at any time if the ENGINE is unloaded (in fact it could be unloaded as a | ||
145 | result of the RSA_set_method() function releasing its handle to the | ||
146 | ENGINE). For this reason, the return type may be replaced with a B<void> | ||
147 | declaration in a future release. | ||
148 | |||
149 | RSA_new_method() returns NULL and sets an error code that can be obtained | ||
150 | by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise | ||
151 | it returns a pointer to the newly allocated structure. | ||
152 | |||
153 | =head1 NOTES | ||
154 | |||
155 | As of version 0.9.7, RSA_METHOD implementations are grouped together with | ||
156 | other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE> | ||
157 | modules. If a default ENGINE is specified for RSA functionality using an | ||
158 | ENGINE API function, that will override any RSA defaults set using the RSA | ||
159 | API (ie. RSA_set_default_method()). For this reason, the ENGINE API is the | ||
160 | recommended way to control default implementations for use in RSA and other | ||
161 | cryptographic algorithms. | ||
162 | |||
163 | =head1 BUGS | ||
164 | |||
165 | The behaviour of RSA_flags() is a mis-feature that is left as-is for now | ||
166 | to avoid creating compatibility problems. RSA functionality, such as the | ||
167 | encryption functions, are controlled by the B<flags> value in the RSA key | ||
168 | itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key | ||
169 | (which is what this function returns). If the flags element of an RSA key | ||
170 | is changed, the changes will be honoured by RSA functionality but will not | ||
171 | be reflected in the return value of the RSA_flags() function - in effect | ||
172 | RSA_flags() behaves more like an RSA_default_flags() function (which does | ||
173 | not currently exist). | ||
174 | |||
175 | =head1 SEE ALSO | ||
176 | |||
177 | L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)> | ||
178 | |||
179 | =head1 HISTORY | ||
180 | |||
181 | RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8. | ||
182 | RSA_get_default_method(), RSA_set_method() and RSA_get_method() as | ||
183 | well as the rsa_sign and rsa_verify components of RSA_METHOD were | ||
184 | added in OpenSSL 0.9.4. | ||
185 | |||
186 | RSA_set_default_openssl_method() and RSA_get_default_openssl_method() | ||
187 | replaced RSA_set_default_method() and RSA_get_default_method() | ||
188 | respectively, and RSA_set_method() and RSA_new_method() were altered to use | ||
189 | B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine | ||
190 | version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE | ||
191 | API was restructured so that this change was reversed, and behaviour of the | ||
192 | other functions resembled more closely the previous behaviour. The | ||
193 | behaviour of defaults in the ENGINE API now transparently overrides the | ||
194 | behaviour of defaults in the RSA API without requiring changing these | ||
195 | function prototypes. | ||
196 | |||
197 | =cut | ||