xref: /freebsd/crypto/openssl/providers/implementations/asymciphers/rsa_enc.c (revision e7be843b4a162e68651d3911f0357ed464915629)
1b077aed3SPierre Pronchery /*
2*e7be843bSPierre Pronchery  * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
3b077aed3SPierre Pronchery  *
4b077aed3SPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5b077aed3SPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6b077aed3SPierre Pronchery  * in the file LICENSE in the source distribution or at
7b077aed3SPierre Pronchery  * https://www.openssl.org/source/license.html
8b077aed3SPierre Pronchery  */
9b077aed3SPierre Pronchery 
10b077aed3SPierre Pronchery /*
11b077aed3SPierre Pronchery  * RSA low level APIs are deprecated for public use, but still ok for
12b077aed3SPierre Pronchery  * internal use.
13b077aed3SPierre Pronchery  */
14b077aed3SPierre Pronchery #include "internal/deprecated.h"
15b077aed3SPierre Pronchery 
16b077aed3SPierre Pronchery #include <openssl/crypto.h>
17b077aed3SPierre Pronchery #include <openssl/evp.h>
18b077aed3SPierre Pronchery #include <openssl/core_dispatch.h>
19b077aed3SPierre Pronchery #include <openssl/core_names.h>
20b077aed3SPierre Pronchery #include <openssl/rsa.h>
21b077aed3SPierre Pronchery #include <openssl/params.h>
22b077aed3SPierre Pronchery #include <openssl/err.h>
23b077aed3SPierre Pronchery #include <openssl/proverr.h>
24b077aed3SPierre Pronchery /* Just for SSL_MAX_MASTER_KEY_LENGTH */
25b077aed3SPierre Pronchery #include <openssl/prov_ssl.h>
26b077aed3SPierre Pronchery #include "internal/constant_time.h"
27b077aed3SPierre Pronchery #include "internal/sizes.h"
28b077aed3SPierre Pronchery #include "crypto/rsa.h"
29b077aed3SPierre Pronchery #include "prov/provider_ctx.h"
30b077aed3SPierre Pronchery #include "prov/implementations.h"
31b077aed3SPierre Pronchery #include "prov/providercommon.h"
32b077aed3SPierre Pronchery #include "prov/securitycheck.h"
33b077aed3SPierre Pronchery #include <stdlib.h>
34b077aed3SPierre Pronchery 
35b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_newctx_fn rsa_newctx;
36b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_encrypt_init_fn rsa_encrypt_init;
37b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_encrypt_fn rsa_encrypt;
38b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_decrypt_init_fn rsa_decrypt_init;
39b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_decrypt_fn rsa_decrypt;
40b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_freectx_fn rsa_freectx;
41b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_dupctx_fn rsa_dupctx;
42b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_get_ctx_params_fn rsa_get_ctx_params;
43b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_gettable_ctx_params_fn rsa_gettable_ctx_params;
44b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_set_ctx_params_fn rsa_set_ctx_params;
45b077aed3SPierre Pronchery static OSSL_FUNC_asym_cipher_settable_ctx_params_fn rsa_settable_ctx_params;
46b077aed3SPierre Pronchery 
47b077aed3SPierre Pronchery static OSSL_ITEM padding_item[] = {
48b077aed3SPierre Pronchery     { RSA_PKCS1_PADDING,        OSSL_PKEY_RSA_PAD_MODE_PKCSV15 },
49b077aed3SPierre Pronchery     { RSA_NO_PADDING,           OSSL_PKEY_RSA_PAD_MODE_NONE },
50b077aed3SPierre Pronchery     { RSA_PKCS1_OAEP_PADDING,   OSSL_PKEY_RSA_PAD_MODE_OAEP }, /* Correct spelling first */
51b077aed3SPierre Pronchery     { RSA_PKCS1_OAEP_PADDING,   "oeap"   },
52b077aed3SPierre Pronchery     { 0,                        NULL     }
53b077aed3SPierre Pronchery };
54b077aed3SPierre Pronchery 
55b077aed3SPierre Pronchery /*
56b077aed3SPierre Pronchery  * What's passed as an actual key is defined by the KEYMGMT interface.
57b077aed3SPierre Pronchery  * We happen to know that our KEYMGMT simply passes RSA structures, so
58b077aed3SPierre Pronchery  * we use that here too.
59b077aed3SPierre Pronchery  */
60b077aed3SPierre Pronchery 
61b077aed3SPierre Pronchery typedef struct {
62b077aed3SPierre Pronchery     OSSL_LIB_CTX *libctx;
63b077aed3SPierre Pronchery     RSA *rsa;
64b077aed3SPierre Pronchery     int pad_mode;
65b077aed3SPierre Pronchery     int operation;
66b077aed3SPierre Pronchery     /* OAEP message digest */
67b077aed3SPierre Pronchery     EVP_MD *oaep_md;
68b077aed3SPierre Pronchery     /* message digest for MGF1 */
69b077aed3SPierre Pronchery     EVP_MD *mgf1_md;
70b077aed3SPierre Pronchery     /* OAEP label */
71b077aed3SPierre Pronchery     unsigned char *oaep_label;
72b077aed3SPierre Pronchery     size_t oaep_labellen;
73b077aed3SPierre Pronchery     /* TLS padding */
74b077aed3SPierre Pronchery     unsigned int client_version;
75b077aed3SPierre Pronchery     unsigned int alt_version;
76*e7be843bSPierre Pronchery     /* PKCS#1 v1.5 decryption mode */
77*e7be843bSPierre Pronchery     unsigned int implicit_rejection;
78*e7be843bSPierre Pronchery     OSSL_FIPS_IND_DECLARE
79b077aed3SPierre Pronchery } PROV_RSA_CTX;
80b077aed3SPierre Pronchery 
rsa_newctx(void * provctx)81b077aed3SPierre Pronchery static void *rsa_newctx(void *provctx)
82b077aed3SPierre Pronchery {
83b077aed3SPierre Pronchery     PROV_RSA_CTX *prsactx;
84b077aed3SPierre Pronchery 
85b077aed3SPierre Pronchery     if (!ossl_prov_is_running())
86b077aed3SPierre Pronchery         return NULL;
87b077aed3SPierre Pronchery     prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX));
88b077aed3SPierre Pronchery     if (prsactx == NULL)
89b077aed3SPierre Pronchery         return NULL;
90b077aed3SPierre Pronchery     prsactx->libctx = PROV_LIBCTX_OF(provctx);
91*e7be843bSPierre Pronchery     OSSL_FIPS_IND_INIT(prsactx)
92b077aed3SPierre Pronchery 
93b077aed3SPierre Pronchery     return prsactx;
94b077aed3SPierre Pronchery }
95b077aed3SPierre Pronchery 
rsa_init(void * vprsactx,void * vrsa,const OSSL_PARAM params[],int operation,const char * desc)96b077aed3SPierre Pronchery static int rsa_init(void *vprsactx, void *vrsa, const OSSL_PARAM params[],
97*e7be843bSPierre Pronchery                     int operation, const char *desc)
98b077aed3SPierre Pronchery {
99b077aed3SPierre Pronchery     PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
100*e7be843bSPierre Pronchery     int protect = 0;
101b077aed3SPierre Pronchery 
102b077aed3SPierre Pronchery     if (!ossl_prov_is_running() || prsactx == NULL || vrsa == NULL)
103b077aed3SPierre Pronchery         return 0;
104b077aed3SPierre Pronchery 
105*e7be843bSPierre Pronchery     if (!ossl_rsa_key_op_get_protect(vrsa, operation, &protect))
106b077aed3SPierre Pronchery         return 0;
107b077aed3SPierre Pronchery     if (!RSA_up_ref(vrsa))
108b077aed3SPierre Pronchery         return 0;
109b077aed3SPierre Pronchery     RSA_free(prsactx->rsa);
110b077aed3SPierre Pronchery     prsactx->rsa = vrsa;
111b077aed3SPierre Pronchery     prsactx->operation = operation;
112*e7be843bSPierre Pronchery     prsactx->implicit_rejection = 1;
113b077aed3SPierre Pronchery 
114b077aed3SPierre Pronchery     switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) {
115b077aed3SPierre Pronchery     case RSA_FLAG_TYPE_RSA:
116b077aed3SPierre Pronchery         prsactx->pad_mode = RSA_PKCS1_PADDING;
117b077aed3SPierre Pronchery         break;
118b077aed3SPierre Pronchery     default:
119b077aed3SPierre Pronchery         /* This should not happen due to the check above */
120b077aed3SPierre Pronchery         ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
121b077aed3SPierre Pronchery         return 0;
122b077aed3SPierre Pronchery     }
123*e7be843bSPierre Pronchery 
124*e7be843bSPierre Pronchery     OSSL_FIPS_IND_SET_APPROVED(prsactx)
125*e7be843bSPierre Pronchery     if (!rsa_set_ctx_params(prsactx, params))
126*e7be843bSPierre Pronchery         return 0;
127*e7be843bSPierre Pronchery #ifdef FIPS_MODULE
128*e7be843bSPierre Pronchery     if (!ossl_fips_ind_rsa_key_check(OSSL_FIPS_IND_GET(prsactx),
129*e7be843bSPierre Pronchery                                      OSSL_FIPS_IND_SETTABLE0, prsactx->libctx,
130*e7be843bSPierre Pronchery                                      prsactx->rsa, desc, protect))
131*e7be843bSPierre Pronchery         return 0;
132*e7be843bSPierre Pronchery #endif
133*e7be843bSPierre Pronchery     return 1;
134b077aed3SPierre Pronchery }
135b077aed3SPierre Pronchery 
rsa_encrypt_init(void * vprsactx,void * vrsa,const OSSL_PARAM params[])136b077aed3SPierre Pronchery static int rsa_encrypt_init(void *vprsactx, void *vrsa,
137b077aed3SPierre Pronchery                             const OSSL_PARAM params[])
138b077aed3SPierre Pronchery {
139*e7be843bSPierre Pronchery     return rsa_init(vprsactx, vrsa, params, EVP_PKEY_OP_ENCRYPT,
140*e7be843bSPierre Pronchery                     "RSA Encrypt Init");
141b077aed3SPierre Pronchery }
142b077aed3SPierre Pronchery 
rsa_decrypt_init(void * vprsactx,void * vrsa,const OSSL_PARAM params[])143b077aed3SPierre Pronchery static int rsa_decrypt_init(void *vprsactx, void *vrsa,
144b077aed3SPierre Pronchery                             const OSSL_PARAM params[])
145b077aed3SPierre Pronchery {
146*e7be843bSPierre Pronchery     return rsa_init(vprsactx, vrsa, params, EVP_PKEY_OP_DECRYPT,
147*e7be843bSPierre Pronchery                     "RSA Decrypt Init");
148b077aed3SPierre Pronchery }
149b077aed3SPierre Pronchery 
rsa_encrypt(void * vprsactx,unsigned char * out,size_t * outlen,size_t outsize,const unsigned char * in,size_t inlen)150b077aed3SPierre Pronchery static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen,
151b077aed3SPierre Pronchery                        size_t outsize, const unsigned char *in, size_t inlen)
152b077aed3SPierre Pronchery {
153b077aed3SPierre Pronchery     PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
154b077aed3SPierre Pronchery     int ret;
155b077aed3SPierre Pronchery 
156b077aed3SPierre Pronchery     if (!ossl_prov_is_running())
157b077aed3SPierre Pronchery         return 0;
158b077aed3SPierre Pronchery 
159*e7be843bSPierre Pronchery #ifdef FIPS_MODULE
160*e7be843bSPierre Pronchery     if ((prsactx->pad_mode == RSA_PKCS1_PADDING
161*e7be843bSPierre Pronchery          || prsactx->pad_mode == RSA_PKCS1_WITH_TLS_PADDING)
162*e7be843bSPierre Pronchery         && !OSSL_FIPS_IND_ON_UNAPPROVED(prsactx, OSSL_FIPS_IND_SETTABLE1,
163*e7be843bSPierre Pronchery                                         prsactx->libctx, "RSA Encrypt",
164*e7be843bSPierre Pronchery                                         "PKCS#1 v1.5 padding",
165*e7be843bSPierre Pronchery                                         ossl_fips_config_rsa_pkcs15_padding_disabled)) {
166*e7be843bSPierre Pronchery         ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_PADDING_MODE);
167*e7be843bSPierre Pronchery         return 0;
168*e7be843bSPierre Pronchery     }
169*e7be843bSPierre Pronchery #endif
170*e7be843bSPierre Pronchery 
171b077aed3SPierre Pronchery     if (out == NULL) {
172b077aed3SPierre Pronchery         size_t len = RSA_size(prsactx->rsa);
173b077aed3SPierre Pronchery 
174b077aed3SPierre Pronchery         if (len == 0) {
175b077aed3SPierre Pronchery             ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
176b077aed3SPierre Pronchery             return 0;
177b077aed3SPierre Pronchery         }
178b077aed3SPierre Pronchery         *outlen = len;
179b077aed3SPierre Pronchery         return 1;
180b077aed3SPierre Pronchery     }
181b077aed3SPierre Pronchery 
182b077aed3SPierre Pronchery     if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
183b077aed3SPierre Pronchery         int rsasize = RSA_size(prsactx->rsa);
184b077aed3SPierre Pronchery         unsigned char *tbuf;
185b077aed3SPierre Pronchery 
186*e7be843bSPierre Pronchery         if ((tbuf = OPENSSL_malloc(rsasize)) == NULL)
187b077aed3SPierre Pronchery             return 0;
188b077aed3SPierre Pronchery         if (prsactx->oaep_md == NULL) {
189b077aed3SPierre Pronchery             prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA-1", NULL);
190b077aed3SPierre Pronchery             if (prsactx->oaep_md == NULL) {
191b077aed3SPierre Pronchery                 OPENSSL_free(tbuf);
192b077aed3SPierre Pronchery                 ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
193b077aed3SPierre Pronchery                 return 0;
194b077aed3SPierre Pronchery             }
195b077aed3SPierre Pronchery         }
196b077aed3SPierre Pronchery         ret =
197b077aed3SPierre Pronchery             ossl_rsa_padding_add_PKCS1_OAEP_mgf1_ex(prsactx->libctx, tbuf,
198b077aed3SPierre Pronchery                                                     rsasize, in, inlen,
199b077aed3SPierre Pronchery                                                     prsactx->oaep_label,
200b077aed3SPierre Pronchery                                                     prsactx->oaep_labellen,
201b077aed3SPierre Pronchery                                                     prsactx->oaep_md,
202b077aed3SPierre Pronchery                                                     prsactx->mgf1_md);
203b077aed3SPierre Pronchery 
204b077aed3SPierre Pronchery         if (!ret) {
205b077aed3SPierre Pronchery             OPENSSL_free(tbuf);
206b077aed3SPierre Pronchery             return 0;
207b077aed3SPierre Pronchery         }
208b077aed3SPierre Pronchery         ret = RSA_public_encrypt(rsasize, tbuf, out, prsactx->rsa,
209b077aed3SPierre Pronchery                                  RSA_NO_PADDING);
210b077aed3SPierre Pronchery         OPENSSL_free(tbuf);
211b077aed3SPierre Pronchery     } else {
212b077aed3SPierre Pronchery         ret = RSA_public_encrypt(inlen, in, out, prsactx->rsa,
213b077aed3SPierre Pronchery                                  prsactx->pad_mode);
214b077aed3SPierre Pronchery     }
215b077aed3SPierre Pronchery     /* A ret value of 0 is not an error */
216b077aed3SPierre Pronchery     if (ret < 0)
217b077aed3SPierre Pronchery         return ret;
218b077aed3SPierre Pronchery     *outlen = ret;
219b077aed3SPierre Pronchery     return 1;
220b077aed3SPierre Pronchery }
221b077aed3SPierre Pronchery 
rsa_decrypt(void * vprsactx,unsigned char * out,size_t * outlen,size_t outsize,const unsigned char * in,size_t inlen)222b077aed3SPierre Pronchery static int rsa_decrypt(void *vprsactx, unsigned char *out, size_t *outlen,
223b077aed3SPierre Pronchery                        size_t outsize, const unsigned char *in, size_t inlen)
224b077aed3SPierre Pronchery {
225b077aed3SPierre Pronchery     PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
226b077aed3SPierre Pronchery     int ret;
227*e7be843bSPierre Pronchery     int pad_mode;
228b077aed3SPierre Pronchery     size_t len = RSA_size(prsactx->rsa);
229b077aed3SPierre Pronchery 
230b077aed3SPierre Pronchery     if (!ossl_prov_is_running())
231b077aed3SPierre Pronchery         return 0;
232b077aed3SPierre Pronchery 
233b077aed3SPierre Pronchery     if (prsactx->pad_mode == RSA_PKCS1_WITH_TLS_PADDING) {
234b077aed3SPierre Pronchery         if (out == NULL) {
235b077aed3SPierre Pronchery             *outlen = SSL_MAX_MASTER_KEY_LENGTH;
236b077aed3SPierre Pronchery             return 1;
237b077aed3SPierre Pronchery         }
238b077aed3SPierre Pronchery         if (outsize < SSL_MAX_MASTER_KEY_LENGTH) {
239b077aed3SPierre Pronchery             ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
240b077aed3SPierre Pronchery             return 0;
241b077aed3SPierre Pronchery         }
242b077aed3SPierre Pronchery     } else {
243b077aed3SPierre Pronchery         if (out == NULL) {
244b077aed3SPierre Pronchery             if (len == 0) {
245b077aed3SPierre Pronchery                 ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
246b077aed3SPierre Pronchery                 return 0;
247b077aed3SPierre Pronchery             }
248b077aed3SPierre Pronchery             *outlen = len;
249b077aed3SPierre Pronchery             return 1;
250b077aed3SPierre Pronchery         }
251b077aed3SPierre Pronchery 
252b077aed3SPierre Pronchery         if (outsize < len) {
253b077aed3SPierre Pronchery             ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
254b077aed3SPierre Pronchery             return 0;
255b077aed3SPierre Pronchery         }
256b077aed3SPierre Pronchery     }
257b077aed3SPierre Pronchery 
258b077aed3SPierre Pronchery     if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING
259b077aed3SPierre Pronchery             || prsactx->pad_mode == RSA_PKCS1_WITH_TLS_PADDING) {
260b077aed3SPierre Pronchery         unsigned char *tbuf;
261b077aed3SPierre Pronchery 
262*e7be843bSPierre Pronchery         if ((tbuf = OPENSSL_malloc(len)) == NULL)
263b077aed3SPierre Pronchery             return 0;
264b077aed3SPierre Pronchery         ret = RSA_private_decrypt(inlen, in, tbuf, prsactx->rsa,
265b077aed3SPierre Pronchery                                   RSA_NO_PADDING);
266b077aed3SPierre Pronchery         /*
267b077aed3SPierre Pronchery          * With no padding then, on success ret should be len, otherwise an
268b077aed3SPierre Pronchery          * error occurred (non-constant time)
269b077aed3SPierre Pronchery          */
270b077aed3SPierre Pronchery         if (ret != (int)len) {
271b077aed3SPierre Pronchery             OPENSSL_free(tbuf);
272b077aed3SPierre Pronchery             ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_DECRYPT);
273b077aed3SPierre Pronchery             return 0;
274b077aed3SPierre Pronchery         }
275b077aed3SPierre Pronchery         if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
276b077aed3SPierre Pronchery             if (prsactx->oaep_md == NULL) {
277b077aed3SPierre Pronchery                 prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA-1", NULL);
278b077aed3SPierre Pronchery                 if (prsactx->oaep_md == NULL) {
279b077aed3SPierre Pronchery                     OPENSSL_free(tbuf);
280b077aed3SPierre Pronchery                     ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
281b077aed3SPierre Pronchery                     return 0;
282b077aed3SPierre Pronchery                 }
283b077aed3SPierre Pronchery             }
284b077aed3SPierre Pronchery             ret = RSA_padding_check_PKCS1_OAEP_mgf1(out, outsize, tbuf,
285b077aed3SPierre Pronchery                                                     len, len,
286b077aed3SPierre Pronchery                                                     prsactx->oaep_label,
287b077aed3SPierre Pronchery                                                     prsactx->oaep_labellen,
288b077aed3SPierre Pronchery                                                     prsactx->oaep_md,
289b077aed3SPierre Pronchery                                                     prsactx->mgf1_md);
290b077aed3SPierre Pronchery         } else {
291b077aed3SPierre Pronchery             /* RSA_PKCS1_WITH_TLS_PADDING */
292b077aed3SPierre Pronchery             if (prsactx->client_version <= 0) {
293b077aed3SPierre Pronchery                 ERR_raise(ERR_LIB_PROV, PROV_R_BAD_TLS_CLIENT_VERSION);
294b077aed3SPierre Pronchery                 OPENSSL_free(tbuf);
295b077aed3SPierre Pronchery                 return 0;
296b077aed3SPierre Pronchery             }
297b077aed3SPierre Pronchery             ret = ossl_rsa_padding_check_PKCS1_type_2_TLS(
298b077aed3SPierre Pronchery                         prsactx->libctx, out, outsize, tbuf, len,
299b077aed3SPierre Pronchery                         prsactx->client_version, prsactx->alt_version);
300b077aed3SPierre Pronchery         }
301b077aed3SPierre Pronchery         OPENSSL_free(tbuf);
302b077aed3SPierre Pronchery     } else {
303*e7be843bSPierre Pronchery         if ((prsactx->implicit_rejection == 0) &&
304*e7be843bSPierre Pronchery                 (prsactx->pad_mode == RSA_PKCS1_PADDING))
305*e7be843bSPierre Pronchery             pad_mode = RSA_PKCS1_NO_IMPLICIT_REJECT_PADDING;
306*e7be843bSPierre Pronchery         else
307*e7be843bSPierre Pronchery             pad_mode = prsactx->pad_mode;
308*e7be843bSPierre Pronchery         ret = RSA_private_decrypt(inlen, in, out, prsactx->rsa, pad_mode);
309b077aed3SPierre Pronchery     }
310b077aed3SPierre Pronchery     *outlen = constant_time_select_s(constant_time_msb_s(ret), *outlen, ret);
311b077aed3SPierre Pronchery     ret = constant_time_select_int(constant_time_msb(ret), 0, 1);
312b077aed3SPierre Pronchery     return ret;
313b077aed3SPierre Pronchery }
314b077aed3SPierre Pronchery 
rsa_freectx(void * vprsactx)315b077aed3SPierre Pronchery static void rsa_freectx(void *vprsactx)
316b077aed3SPierre Pronchery {
317b077aed3SPierre Pronchery     PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
318b077aed3SPierre Pronchery 
319b077aed3SPierre Pronchery     RSA_free(prsactx->rsa);
320b077aed3SPierre Pronchery 
321b077aed3SPierre Pronchery     EVP_MD_free(prsactx->oaep_md);
322b077aed3SPierre Pronchery     EVP_MD_free(prsactx->mgf1_md);
323b077aed3SPierre Pronchery     OPENSSL_free(prsactx->oaep_label);
324b077aed3SPierre Pronchery 
325b077aed3SPierre Pronchery     OPENSSL_free(prsactx);
326b077aed3SPierre Pronchery }
327b077aed3SPierre Pronchery 
rsa_dupctx(void * vprsactx)328b077aed3SPierre Pronchery static void *rsa_dupctx(void *vprsactx)
329b077aed3SPierre Pronchery {
330b077aed3SPierre Pronchery     PROV_RSA_CTX *srcctx = (PROV_RSA_CTX *)vprsactx;
331b077aed3SPierre Pronchery     PROV_RSA_CTX *dstctx;
332b077aed3SPierre Pronchery 
333b077aed3SPierre Pronchery     if (!ossl_prov_is_running())
334b077aed3SPierre Pronchery         return NULL;
335b077aed3SPierre Pronchery 
336b077aed3SPierre Pronchery     dstctx = OPENSSL_zalloc(sizeof(*srcctx));
337b077aed3SPierre Pronchery     if (dstctx == NULL)
338b077aed3SPierre Pronchery         return NULL;
339b077aed3SPierre Pronchery 
340b077aed3SPierre Pronchery     *dstctx = *srcctx;
341b077aed3SPierre Pronchery     if (dstctx->rsa != NULL && !RSA_up_ref(dstctx->rsa)) {
342b077aed3SPierre Pronchery         OPENSSL_free(dstctx);
343b077aed3SPierre Pronchery         return NULL;
344b077aed3SPierre Pronchery     }
345b077aed3SPierre Pronchery 
346b077aed3SPierre Pronchery     if (dstctx->oaep_md != NULL && !EVP_MD_up_ref(dstctx->oaep_md)) {
347b077aed3SPierre Pronchery         RSA_free(dstctx->rsa);
348b077aed3SPierre Pronchery         OPENSSL_free(dstctx);
349b077aed3SPierre Pronchery         return NULL;
350b077aed3SPierre Pronchery     }
351b077aed3SPierre Pronchery 
352b077aed3SPierre Pronchery     if (dstctx->mgf1_md != NULL && !EVP_MD_up_ref(dstctx->mgf1_md)) {
353b077aed3SPierre Pronchery         RSA_free(dstctx->rsa);
354b077aed3SPierre Pronchery         EVP_MD_free(dstctx->oaep_md);
355b077aed3SPierre Pronchery         OPENSSL_free(dstctx);
356b077aed3SPierre Pronchery         return NULL;
357b077aed3SPierre Pronchery     }
358b077aed3SPierre Pronchery 
359b077aed3SPierre Pronchery     return dstctx;
360b077aed3SPierre Pronchery }
361b077aed3SPierre Pronchery 
rsa_get_ctx_params(void * vprsactx,OSSL_PARAM * params)362b077aed3SPierre Pronchery static int rsa_get_ctx_params(void *vprsactx, OSSL_PARAM *params)
363b077aed3SPierre Pronchery {
364b077aed3SPierre Pronchery     PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
365b077aed3SPierre Pronchery     OSSL_PARAM *p;
366b077aed3SPierre Pronchery 
367b077aed3SPierre Pronchery     if (prsactx == NULL)
368b077aed3SPierre Pronchery         return 0;
369b077aed3SPierre Pronchery 
370b077aed3SPierre Pronchery     p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE);
371b077aed3SPierre Pronchery     if (p != NULL)
372b077aed3SPierre Pronchery         switch (p->data_type) {
373b077aed3SPierre Pronchery         case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
374b077aed3SPierre Pronchery             if (!OSSL_PARAM_set_int(p, prsactx->pad_mode))
375b077aed3SPierre Pronchery                 return 0;
376b077aed3SPierre Pronchery             break;
377b077aed3SPierre Pronchery         case OSSL_PARAM_UTF8_STRING:
378b077aed3SPierre Pronchery             {
379b077aed3SPierre Pronchery                 int i;
380b077aed3SPierre Pronchery                 const char *word = NULL;
381b077aed3SPierre Pronchery 
382b077aed3SPierre Pronchery                 for (i = 0; padding_item[i].id != 0; i++) {
383b077aed3SPierre Pronchery                     if (prsactx->pad_mode == (int)padding_item[i].id) {
384b077aed3SPierre Pronchery                         word = padding_item[i].ptr;
385b077aed3SPierre Pronchery                         break;
386b077aed3SPierre Pronchery                     }
387b077aed3SPierre Pronchery                 }
388b077aed3SPierre Pronchery 
389b077aed3SPierre Pronchery                 if (word != NULL) {
390b077aed3SPierre Pronchery                     if (!OSSL_PARAM_set_utf8_string(p, word))
391b077aed3SPierre Pronchery                         return 0;
392b077aed3SPierre Pronchery                 } else {
393b077aed3SPierre Pronchery                     ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
394b077aed3SPierre Pronchery                 }
395b077aed3SPierre Pronchery             }
396b077aed3SPierre Pronchery             break;
397b077aed3SPierre Pronchery         default:
398b077aed3SPierre Pronchery             return 0;
399b077aed3SPierre Pronchery         }
400b077aed3SPierre Pronchery 
401b077aed3SPierre Pronchery     p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST);
402b077aed3SPierre Pronchery     if (p != NULL && !OSSL_PARAM_set_utf8_string(p, prsactx->oaep_md == NULL
403b077aed3SPierre Pronchery                                                     ? ""
404b077aed3SPierre Pronchery                                                     : EVP_MD_get0_name(prsactx->oaep_md)))
405b077aed3SPierre Pronchery         return 0;
406b077aed3SPierre Pronchery 
407b077aed3SPierre Pronchery     p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST);
408b077aed3SPierre Pronchery     if (p != NULL) {
409b077aed3SPierre Pronchery         EVP_MD *mgf1_md = prsactx->mgf1_md == NULL ? prsactx->oaep_md
410b077aed3SPierre Pronchery                                                    : prsactx->mgf1_md;
411b077aed3SPierre Pronchery 
412b077aed3SPierre Pronchery         if (!OSSL_PARAM_set_utf8_string(p, mgf1_md == NULL
413b077aed3SPierre Pronchery                                            ? ""
414b077aed3SPierre Pronchery                                            : EVP_MD_get0_name(mgf1_md)))
415b077aed3SPierre Pronchery         return 0;
416b077aed3SPierre Pronchery     }
417b077aed3SPierre Pronchery 
418b077aed3SPierre Pronchery     p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL);
419b077aed3SPierre Pronchery     if (p != NULL &&
420b077aed3SPierre Pronchery         !OSSL_PARAM_set_octet_ptr(p, prsactx->oaep_label,
421b077aed3SPierre Pronchery                                   prsactx->oaep_labellen))
422b077aed3SPierre Pronchery         return 0;
423b077aed3SPierre Pronchery 
424b077aed3SPierre Pronchery     p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION);
425b077aed3SPierre Pronchery     if (p != NULL && !OSSL_PARAM_set_uint(p, prsactx->client_version))
426b077aed3SPierre Pronchery         return 0;
427b077aed3SPierre Pronchery 
428b077aed3SPierre Pronchery     p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION);
429b077aed3SPierre Pronchery     if (p != NULL && !OSSL_PARAM_set_uint(p, prsactx->alt_version))
430b077aed3SPierre Pronchery         return 0;
431b077aed3SPierre Pronchery 
432*e7be843bSPierre Pronchery     p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION);
433*e7be843bSPierre Pronchery     if (p != NULL && !OSSL_PARAM_set_uint(p, prsactx->implicit_rejection))
434*e7be843bSPierre Pronchery         return 0;
435*e7be843bSPierre Pronchery     if (!OSSL_FIPS_IND_GET_CTX_PARAM(prsactx, params))
436*e7be843bSPierre Pronchery         return 0;
437b077aed3SPierre Pronchery     return 1;
438b077aed3SPierre Pronchery }
439b077aed3SPierre Pronchery 
440b077aed3SPierre Pronchery static const OSSL_PARAM known_gettable_ctx_params[] = {
441b077aed3SPierre Pronchery     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, NULL, 0),
442b077aed3SPierre Pronchery     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL, 0),
443b077aed3SPierre Pronchery     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, NULL, 0),
444b077aed3SPierre Pronchery     OSSL_PARAM_DEFN(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, OSSL_PARAM_OCTET_PTR,
445b077aed3SPierre Pronchery                     NULL, 0),
446b077aed3SPierre Pronchery     OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION, NULL),
447b077aed3SPierre Pronchery     OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION, NULL),
448*e7be843bSPierre Pronchery     OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION, NULL),
449*e7be843bSPierre Pronchery     OSSL_FIPS_IND_GETTABLE_CTX_PARAM()
450b077aed3SPierre Pronchery     OSSL_PARAM_END
451b077aed3SPierre Pronchery };
452b077aed3SPierre Pronchery 
rsa_gettable_ctx_params(ossl_unused void * vprsactx,ossl_unused void * provctx)453b077aed3SPierre Pronchery static const OSSL_PARAM *rsa_gettable_ctx_params(ossl_unused void *vprsactx,
454b077aed3SPierre Pronchery                                                  ossl_unused void *provctx)
455b077aed3SPierre Pronchery {
456b077aed3SPierre Pronchery     return known_gettable_ctx_params;
457b077aed3SPierre Pronchery }
458b077aed3SPierre Pronchery 
rsa_set_ctx_params(void * vprsactx,const OSSL_PARAM params[])459b077aed3SPierre Pronchery static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
460b077aed3SPierre Pronchery {
461b077aed3SPierre Pronchery     PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
462b077aed3SPierre Pronchery     const OSSL_PARAM *p;
463b077aed3SPierre Pronchery     char mdname[OSSL_MAX_NAME_SIZE];
464b077aed3SPierre Pronchery     char mdprops[OSSL_MAX_PROPQUERY_SIZE] = { '\0' };
465b077aed3SPierre Pronchery     char *str = NULL;
466b077aed3SPierre Pronchery 
467b077aed3SPierre Pronchery     if (prsactx == NULL)
468b077aed3SPierre Pronchery         return 0;
469*e7be843bSPierre Pronchery     if (ossl_param_is_empty(params))
470b077aed3SPierre Pronchery         return 1;
471b077aed3SPierre Pronchery 
472*e7be843bSPierre Pronchery     if (!OSSL_FIPS_IND_SET_CTX_PARAM(prsactx, OSSL_FIPS_IND_SETTABLE0, params,
473*e7be843bSPierre Pronchery                                      OSSL_ASYM_CIPHER_PARAM_FIPS_KEY_CHECK))
474*e7be843bSPierre Pronchery         return 0;
475*e7be843bSPierre Pronchery     if (!OSSL_FIPS_IND_SET_CTX_PARAM(prsactx, OSSL_FIPS_IND_SETTABLE1, params,
476*e7be843bSPierre Pronchery                                      OSSL_ASYM_CIPHER_PARAM_FIPS_RSA_PKCS15_PAD_DISABLED))
477*e7be843bSPierre Pronchery         return 0;
478*e7be843bSPierre Pronchery 
479b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST);
480b077aed3SPierre Pronchery     if (p != NULL) {
481b077aed3SPierre Pronchery         str = mdname;
482b077aed3SPierre Pronchery         if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdname)))
483b077aed3SPierre Pronchery             return 0;
484b077aed3SPierre Pronchery 
485b077aed3SPierre Pronchery         p = OSSL_PARAM_locate_const(params,
486b077aed3SPierre Pronchery                                     OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST_PROPS);
487b077aed3SPierre Pronchery         if (p != NULL) {
488b077aed3SPierre Pronchery             str = mdprops;
489b077aed3SPierre Pronchery             if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdprops)))
490b077aed3SPierre Pronchery                 return 0;
491b077aed3SPierre Pronchery         }
492b077aed3SPierre Pronchery 
493b077aed3SPierre Pronchery         EVP_MD_free(prsactx->oaep_md);
494b077aed3SPierre Pronchery         prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, mdname, mdprops);
495b077aed3SPierre Pronchery 
496b077aed3SPierre Pronchery         if (prsactx->oaep_md == NULL)
497b077aed3SPierre Pronchery             return 0;
498b077aed3SPierre Pronchery     }
499b077aed3SPierre Pronchery 
500b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE);
501b077aed3SPierre Pronchery     if (p != NULL) {
502b077aed3SPierre Pronchery         int pad_mode = 0;
503b077aed3SPierre Pronchery 
504b077aed3SPierre Pronchery         switch (p->data_type) {
505b077aed3SPierre Pronchery         case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
506b077aed3SPierre Pronchery             if (!OSSL_PARAM_get_int(p, &pad_mode))
507b077aed3SPierre Pronchery                 return 0;
508b077aed3SPierre Pronchery             break;
509b077aed3SPierre Pronchery         case OSSL_PARAM_UTF8_STRING:
510b077aed3SPierre Pronchery             {
511b077aed3SPierre Pronchery                 int i;
512b077aed3SPierre Pronchery 
513b077aed3SPierre Pronchery                 if (p->data == NULL)
514b077aed3SPierre Pronchery                     return 0;
515b077aed3SPierre Pronchery 
516b077aed3SPierre Pronchery                 for (i = 0; padding_item[i].id != 0; i++) {
517b077aed3SPierre Pronchery                     if (strcmp(p->data, padding_item[i].ptr) == 0) {
518b077aed3SPierre Pronchery                         pad_mode = padding_item[i].id;
519b077aed3SPierre Pronchery                         break;
520b077aed3SPierre Pronchery                     }
521b077aed3SPierre Pronchery                 }
522b077aed3SPierre Pronchery             }
523b077aed3SPierre Pronchery             break;
524b077aed3SPierre Pronchery         default:
525b077aed3SPierre Pronchery             return 0;
526b077aed3SPierre Pronchery         }
527b077aed3SPierre Pronchery 
528b077aed3SPierre Pronchery         /*
529b077aed3SPierre Pronchery          * PSS padding is for signatures only so is not compatible with
530b077aed3SPierre Pronchery          * asymmetric cipher use.
531b077aed3SPierre Pronchery          */
532b077aed3SPierre Pronchery         if (pad_mode == RSA_PKCS1_PSS_PADDING)
533b077aed3SPierre Pronchery             return 0;
534b077aed3SPierre Pronchery         if (pad_mode == RSA_PKCS1_OAEP_PADDING && prsactx->oaep_md == NULL) {
535b077aed3SPierre Pronchery             prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA1", mdprops);
536b077aed3SPierre Pronchery             if (prsactx->oaep_md == NULL)
537b077aed3SPierre Pronchery                 return 0;
538b077aed3SPierre Pronchery         }
539b077aed3SPierre Pronchery         prsactx->pad_mode = pad_mode;
540b077aed3SPierre Pronchery     }
541b077aed3SPierre Pronchery 
542b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST);
543b077aed3SPierre Pronchery     if (p != NULL) {
544b077aed3SPierre Pronchery         str = mdname;
545b077aed3SPierre Pronchery         if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdname)))
546b077aed3SPierre Pronchery             return 0;
547b077aed3SPierre Pronchery 
548b077aed3SPierre Pronchery         p = OSSL_PARAM_locate_const(params,
549b077aed3SPierre Pronchery                                     OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS);
550b077aed3SPierre Pronchery         if (p != NULL) {
551b077aed3SPierre Pronchery             str = mdprops;
552b077aed3SPierre Pronchery             if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdprops)))
553b077aed3SPierre Pronchery                 return 0;
554b077aed3SPierre Pronchery         } else {
555b077aed3SPierre Pronchery             str = NULL;
556b077aed3SPierre Pronchery         }
557b077aed3SPierre Pronchery 
558b077aed3SPierre Pronchery         EVP_MD_free(prsactx->mgf1_md);
559b077aed3SPierre Pronchery         prsactx->mgf1_md = EVP_MD_fetch(prsactx->libctx, mdname, str);
560b077aed3SPierre Pronchery 
561b077aed3SPierre Pronchery         if (prsactx->mgf1_md == NULL)
562b077aed3SPierre Pronchery             return 0;
563b077aed3SPierre Pronchery     }
564b077aed3SPierre Pronchery 
565b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL);
566b077aed3SPierre Pronchery     if (p != NULL) {
567b077aed3SPierre Pronchery         void *tmp_label = NULL;
568b077aed3SPierre Pronchery         size_t tmp_labellen;
569b077aed3SPierre Pronchery 
570b077aed3SPierre Pronchery         if (!OSSL_PARAM_get_octet_string(p, &tmp_label, 0, &tmp_labellen))
571b077aed3SPierre Pronchery             return 0;
572b077aed3SPierre Pronchery         OPENSSL_free(prsactx->oaep_label);
573b077aed3SPierre Pronchery         prsactx->oaep_label = (unsigned char *)tmp_label;
574b077aed3SPierre Pronchery         prsactx->oaep_labellen = tmp_labellen;
575b077aed3SPierre Pronchery     }
576b077aed3SPierre Pronchery 
577b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION);
578b077aed3SPierre Pronchery     if (p != NULL) {
579b077aed3SPierre Pronchery         unsigned int client_version;
580b077aed3SPierre Pronchery 
581b077aed3SPierre Pronchery         if (!OSSL_PARAM_get_uint(p, &client_version))
582b077aed3SPierre Pronchery             return 0;
583b077aed3SPierre Pronchery         prsactx->client_version = client_version;
584b077aed3SPierre Pronchery     }
585b077aed3SPierre Pronchery 
586b077aed3SPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION);
587b077aed3SPierre Pronchery     if (p != NULL) {
588b077aed3SPierre Pronchery         unsigned int alt_version;
589b077aed3SPierre Pronchery 
590b077aed3SPierre Pronchery         if (!OSSL_PARAM_get_uint(p, &alt_version))
591b077aed3SPierre Pronchery             return 0;
592b077aed3SPierre Pronchery         prsactx->alt_version = alt_version;
593b077aed3SPierre Pronchery     }
594*e7be843bSPierre Pronchery     p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION);
595*e7be843bSPierre Pronchery     if (p != NULL) {
596*e7be843bSPierre Pronchery         unsigned int implicit_rejection;
597b077aed3SPierre Pronchery 
598*e7be843bSPierre Pronchery         if (!OSSL_PARAM_get_uint(p, &implicit_rejection))
599*e7be843bSPierre Pronchery             return 0;
600*e7be843bSPierre Pronchery         prsactx->implicit_rejection = implicit_rejection;
601*e7be843bSPierre Pronchery     }
602b077aed3SPierre Pronchery     return 1;
603b077aed3SPierre Pronchery }
604b077aed3SPierre Pronchery 
605b077aed3SPierre Pronchery static const OSSL_PARAM known_settable_ctx_params[] = {
606b077aed3SPierre Pronchery     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, NULL, 0),
607e0c4386eSCy Schubert     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST_PROPS, NULL, 0),
608b077aed3SPierre Pronchery     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL, 0),
609b077aed3SPierre Pronchery     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, NULL, 0),
610b077aed3SPierre Pronchery     OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS, NULL, 0),
611b077aed3SPierre Pronchery     OSSL_PARAM_octet_string(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, NULL, 0),
612b077aed3SPierre Pronchery     OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION, NULL),
613b077aed3SPierre Pronchery     OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION, NULL),
614*e7be843bSPierre Pronchery     OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_IMPLICIT_REJECTION, NULL),
615*e7be843bSPierre Pronchery     OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_ASYM_CIPHER_PARAM_FIPS_KEY_CHECK)
616*e7be843bSPierre Pronchery     OSSL_FIPS_IND_SETTABLE_CTX_PARAM(OSSL_ASYM_CIPHER_PARAM_FIPS_RSA_PKCS15_PAD_DISABLED)
617b077aed3SPierre Pronchery     OSSL_PARAM_END
618b077aed3SPierre Pronchery };
619b077aed3SPierre Pronchery 
rsa_settable_ctx_params(ossl_unused void * vprsactx,ossl_unused void * provctx)620b077aed3SPierre Pronchery static const OSSL_PARAM *rsa_settable_ctx_params(ossl_unused void *vprsactx,
621b077aed3SPierre Pronchery                                                  ossl_unused void *provctx)
622b077aed3SPierre Pronchery {
623b077aed3SPierre Pronchery     return known_settable_ctx_params;
624b077aed3SPierre Pronchery }
625b077aed3SPierre Pronchery 
626b077aed3SPierre Pronchery const OSSL_DISPATCH ossl_rsa_asym_cipher_functions[] = {
627b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_NEWCTX, (void (*)(void))rsa_newctx },
628b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT, (void (*)(void))rsa_encrypt_init },
629b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_ENCRYPT, (void (*)(void))rsa_encrypt },
630b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT, (void (*)(void))rsa_decrypt_init },
631b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_DECRYPT, (void (*)(void))rsa_decrypt },
632b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_FREECTX, (void (*)(void))rsa_freectx },
633b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_DUPCTX, (void (*)(void))rsa_dupctx },
634b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS,
635b077aed3SPierre Pronchery       (void (*)(void))rsa_get_ctx_params },
636b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS,
637b077aed3SPierre Pronchery       (void (*)(void))rsa_gettable_ctx_params },
638b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS,
639b077aed3SPierre Pronchery       (void (*)(void))rsa_set_ctx_params },
640b077aed3SPierre Pronchery     { OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS,
641b077aed3SPierre Pronchery       (void (*)(void))rsa_settable_ctx_params },
642*e7be843bSPierre Pronchery     OSSL_DISPATCH_END
643b077aed3SPierre Pronchery };
644