Coverage Report

Created: 2025-11-16 06:40

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