Coverage Report

Created: 2026-02-14 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/providers/implementations/asymciphers/rsa_enc.c
Line
Count
Source
1
/*
2
 * Copyright 2019-2026 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
} PROV_RSA_CTX;
79
80
static void *rsa_newctx(void *provctx)
81
16.7k
{
82
16.7k
    PROV_RSA_CTX *prsactx;
83
84
16.7k
    if (!ossl_prov_is_running())
85
0
        return NULL;
86
16.7k
    prsactx = OPENSSL_zalloc(sizeof(PROV_RSA_CTX));
87
16.7k
    if (prsactx == NULL)
88
0
        return NULL;
89
16.7k
    prsactx->libctx = PROV_LIBCTX_OF(provctx);
90
91
16.7k
    return prsactx;
92
16.7k
}
93
94
static int rsa_init(void *vprsactx, void *vrsa, const OSSL_PARAM params[],
95
    int operation)
96
5.19k
{
97
5.19k
    PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
98
99
5.19k
    if (!ossl_prov_is_running() || prsactx == NULL || vrsa == NULL)
100
0
        return 0;
101
102
5.19k
    if (!ossl_rsa_check_key(prsactx->libctx, vrsa, operation))
103
0
        return 0;
104
105
5.19k
    if (!RSA_up_ref(vrsa))
106
0
        return 0;
107
5.19k
    RSA_free(prsactx->rsa);
108
5.19k
    prsactx->rsa = vrsa;
109
5.19k
    prsactx->operation = operation;
110
111
5.19k
    switch (RSA_test_flags(prsactx->rsa, RSA_FLAG_TYPE_MASK)) {
112
5.19k
    case RSA_FLAG_TYPE_RSA:
113
5.19k
        prsactx->pad_mode = RSA_PKCS1_PADDING;
114
5.19k
        break;
115
0
    default:
116
        /* This should not happen due to the check above */
117
0
        ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
118
0
        return 0;
119
5.19k
    }
120
5.19k
    return rsa_set_ctx_params(prsactx, params);
121
5.19k
}
122
123
static int rsa_encrypt_init(void *vprsactx, void *vrsa,
124
    const OSSL_PARAM params[])
125
6.26k
{
126
6.26k
    return rsa_init(vprsactx, vrsa, params, EVP_PKEY_OP_ENCRYPT);
127
6.26k
}
128
129
static int rsa_decrypt_init(void *vprsactx, void *vrsa,
130
    const OSSL_PARAM params[])
131
10.4k
{
132
10.4k
    return rsa_init(vprsactx, vrsa, params, EVP_PKEY_OP_DECRYPT);
133
10.4k
}
134
135
static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen,
136
    size_t outsize, const unsigned char *in, size_t inlen)
137
12.5k
{
138
12.5k
    PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
139
12.5k
    size_t len = RSA_size(prsactx->rsa);
140
12.5k
    int ret;
141
142
12.5k
    if (!ossl_prov_is_running())
143
0
        return 0;
144
145
12.5k
    if (len == 0) {
146
8
        ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
147
8
        return 0;
148
8
    }
149
150
12.5k
    if (out == NULL) {
151
6.25k
        *outlen = len;
152
6.25k
        return 1;
153
6.25k
    }
154
155
6.25k
    if (outsize < len) {
156
0
        ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
157
0
        return 0;
158
0
    }
159
160
6.25k
    if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
161
0
        int rsasize = RSA_size(prsactx->rsa);
162
0
        unsigned char *tbuf;
163
164
0
        if ((tbuf = OPENSSL_malloc(rsasize)) == NULL) {
165
0
            ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
166
0
            return 0;
167
0
        }
168
0
        if (prsactx->oaep_md == NULL) {
169
0
            prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA-1", NULL);
170
0
            if (prsactx->oaep_md == NULL) {
171
0
                OPENSSL_free(tbuf);
172
0
                ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
173
0
                return 0;
174
0
            }
175
0
        }
176
0
        ret = ossl_rsa_padding_add_PKCS1_OAEP_mgf1_ex(prsactx->libctx, tbuf,
177
0
            rsasize, in, inlen,
178
0
            prsactx->oaep_label,
179
0
            prsactx->oaep_labellen,
180
0
            prsactx->oaep_md,
181
0
            prsactx->mgf1_md);
182
183
0
        if (!ret) {
184
0
            OPENSSL_free(tbuf);
185
0
            return 0;
186
0
        }
187
0
        ret = RSA_public_encrypt(rsasize, tbuf, out, prsactx->rsa,
188
0
            RSA_NO_PADDING);
189
0
        OPENSSL_free(tbuf);
190
6.25k
    } else {
191
6.25k
        ret = RSA_public_encrypt(inlen, in, out, prsactx->rsa,
192
6.25k
            prsactx->pad_mode);
193
6.25k
    }
194
    /* A ret value of 0 is not an error */
195
6.25k
    if (ret < 0)
196
734
        return ret;
197
5.52k
    *outlen = ret;
198
5.52k
    return 1;
199
6.25k
}
200
201
static int rsa_decrypt(void *vprsactx, unsigned char *out, size_t *outlen,
202
    size_t outsize, const unsigned char *in, size_t inlen)
203
538
{
204
538
    PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
205
538
    int ret;
206
538
    size_t len = RSA_size(prsactx->rsa);
207
208
538
    if (!ossl_prov_is_running())
209
0
        return 0;
210
211
538
    if (prsactx->pad_mode == RSA_PKCS1_WITH_TLS_PADDING) {
212
538
        if (out == NULL) {
213
0
            *outlen = SSL_MAX_MASTER_KEY_LENGTH;
214
0
            return 1;
215
0
        }
216
538
        if (outsize < SSL_MAX_MASTER_KEY_LENGTH) {
217
0
            ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
218
0
            return 0;
219
0
        }
220
538
    } else {
221
0
        if (out == NULL) {
222
0
            if (len == 0) {
223
0
                ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY);
224
0
                return 0;
225
0
            }
226
0
            *outlen = len;
227
0
            return 1;
228
0
        }
229
230
0
        if (outsize < len) {
231
0
            ERR_raise(ERR_LIB_PROV, PROV_R_BAD_LENGTH);
232
0
            return 0;
233
0
        }
234
0
    }
235
236
538
    if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING
237
538
        || prsactx->pad_mode == RSA_PKCS1_WITH_TLS_PADDING) {
238
538
        unsigned char *tbuf;
239
240
538
        if ((tbuf = OPENSSL_malloc(len)) == NULL) {
241
0
            ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
242
0
            return 0;
243
0
        }
244
538
        ret = RSA_private_decrypt(inlen, in, tbuf, prsactx->rsa,
245
538
            RSA_NO_PADDING);
246
        /*
247
         * With no padding then, on success ret should be len, otherwise an
248
         * error occurred (non-constant time)
249
         */
250
538
        if (ret != (int)len) {
251
1
            OPENSSL_free(tbuf);
252
1
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_DECRYPT);
253
1
            return 0;
254
1
        }
255
537
        if (prsactx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
256
0
            if (prsactx->oaep_md == NULL) {
257
0
                prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA-1", NULL);
258
0
                if (prsactx->oaep_md == NULL) {
259
0
                    OPENSSL_free(tbuf);
260
0
                    ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
261
0
                    return 0;
262
0
                }
263
0
            }
264
0
            ret = RSA_padding_check_PKCS1_OAEP_mgf1(out, outsize, tbuf,
265
0
                len, len,
266
0
                prsactx->oaep_label,
267
0
                prsactx->oaep_labellen,
268
0
                prsactx->oaep_md,
269
0
                prsactx->mgf1_md);
270
537
        } else {
271
            /* RSA_PKCS1_WITH_TLS_PADDING */
272
537
            if (prsactx->client_version <= 0) {
273
0
                ERR_raise(ERR_LIB_PROV, PROV_R_BAD_TLS_CLIENT_VERSION);
274
0
                OPENSSL_free(tbuf);
275
0
                return 0;
276
0
            }
277
537
            ret = ossl_rsa_padding_check_PKCS1_type_2_TLS(
278
537
                prsactx->libctx, out, outsize, tbuf, len,
279
537
                prsactx->client_version, prsactx->alt_version);
280
537
        }
281
537
        OPENSSL_free(tbuf);
282
537
    } else {
283
0
        ret = RSA_private_decrypt(inlen, in, out, prsactx->rsa,
284
0
            prsactx->pad_mode);
285
0
    }
286
537
    *outlen = constant_time_select_s(constant_time_msb_s(ret), *outlen, ret);
287
537
    ret = constant_time_select_int(constant_time_msb(ret), 0, 1);
288
537
    return ret;
289
538
}
290
291
static void rsa_freectx(void *vprsactx)
292
16.7k
{
293
16.7k
    PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
294
295
16.7k
    RSA_free(prsactx->rsa);
296
297
16.7k
    EVP_MD_free(prsactx->oaep_md);
298
16.7k
    EVP_MD_free(prsactx->mgf1_md);
299
16.7k
    OPENSSL_free(prsactx->oaep_label);
300
301
16.7k
    OPENSSL_free(prsactx);
302
16.7k
}
303
304
static void *rsa_dupctx(void *vprsactx)
305
0
{
306
0
    PROV_RSA_CTX *srcctx = (PROV_RSA_CTX *)vprsactx;
307
0
    PROV_RSA_CTX *dstctx;
308
309
0
    if (!ossl_prov_is_running())
310
0
        return NULL;
311
312
0
    dstctx = OPENSSL_zalloc(sizeof(*srcctx));
313
0
    if (dstctx == NULL)
314
0
        return NULL;
315
316
0
    *dstctx = *srcctx;
317
0
    if (dstctx->rsa != NULL && !RSA_up_ref(dstctx->rsa)) {
318
0
        OPENSSL_free(dstctx);
319
0
        return NULL;
320
0
    }
321
322
0
    if (dstctx->oaep_md != NULL && !EVP_MD_up_ref(dstctx->oaep_md)) {
323
0
        RSA_free(dstctx->rsa);
324
0
        OPENSSL_free(dstctx);
325
0
        return NULL;
326
0
    }
327
328
0
    if (dstctx->mgf1_md != NULL && !EVP_MD_up_ref(dstctx->mgf1_md)) {
329
0
        RSA_free(dstctx->rsa);
330
0
        EVP_MD_free(dstctx->oaep_md);
331
0
        OPENSSL_free(dstctx);
332
0
        return NULL;
333
0
    }
334
335
0
    if (dstctx->oaep_label != NULL
336
0
        && (dstctx->oaep_label = OPENSSL_memdup(dstctx->oaep_label, dstctx->oaep_labellen)) == NULL) {
337
0
        rsa_freectx(dstctx);
338
0
        return NULL;
339
0
    }
340
341
0
    return dstctx;
342
0
}
343
344
static int rsa_get_ctx_params(void *vprsactx, OSSL_PARAM *params)
345
0
{
346
0
    PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
347
0
    OSSL_PARAM *p;
348
349
0
    if (prsactx == NULL)
350
0
        return 0;
351
352
0
    p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE);
353
0
    if (p != NULL)
354
0
        switch (p->data_type) {
355
0
        case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
356
0
            if (!OSSL_PARAM_set_int(p, prsactx->pad_mode))
357
0
                return 0;
358
0
            break;
359
0
        case OSSL_PARAM_UTF8_STRING: {
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
        } break;
377
0
        default:
378
0
            return 0;
379
0
        }
380
381
0
    p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST);
382
0
    if (p != NULL && !OSSL_PARAM_set_utf8_string(p, prsactx->oaep_md == NULL ? "" : EVP_MD_get0_name(prsactx->oaep_md)))
383
0
        return 0;
384
385
0
    p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST);
386
0
    if (p != NULL) {
387
0
        EVP_MD *mgf1_md = prsactx->mgf1_md == NULL ? prsactx->oaep_md
388
0
                                                   : prsactx->mgf1_md;
389
390
0
        if (!OSSL_PARAM_set_utf8_string(p, mgf1_md == NULL ? "" : EVP_MD_get0_name(mgf1_md)))
391
0
            return 0;
392
0
    }
393
394
0
    p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL);
395
0
    if (p != NULL && !OSSL_PARAM_set_octet_ptr(p, prsactx->oaep_label, prsactx->oaep_labellen))
396
0
        return 0;
397
398
0
    p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION);
399
0
    if (p != NULL && !OSSL_PARAM_set_uint(p, prsactx->client_version))
400
0
        return 0;
401
402
0
    p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION);
403
0
    if (p != NULL && !OSSL_PARAM_set_uint(p, prsactx->alt_version))
404
0
        return 0;
405
406
0
    return 1;
407
0
}
408
409
static const OSSL_PARAM known_gettable_ctx_params[] = {
410
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, NULL, 0),
411
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL, 0),
412
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, NULL, 0),
413
    OSSL_PARAM_DEFN(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, OSSL_PARAM_OCTET_PTR,
414
        NULL, 0),
415
    OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION, NULL),
416
    OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION, NULL),
417
    OSSL_PARAM_END
418
};
419
420
static const OSSL_PARAM *rsa_gettable_ctx_params(ossl_unused void *vprsactx,
421
    ossl_unused void *provctx)
422
0
{
423
0
    return known_gettable_ctx_params;
424
0
}
425
426
static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])
427
1.91k
{
428
1.91k
    PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx;
429
1.91k
    const OSSL_PARAM *p;
430
1.91k
    char mdname[OSSL_MAX_NAME_SIZE];
431
1.91k
    char mdprops[OSSL_MAX_PROPQUERY_SIZE] = { '\0' };
432
1.91k
    char *str = NULL;
433
434
1.91k
    if (prsactx == NULL)
435
0
        return 0;
436
1.91k
    if (params == NULL)
437
840
        return 1;
438
439
1.07k
    p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST);
440
1.07k
    if (p != NULL) {
441
0
        str = mdname;
442
0
        if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdname)))
443
0
            return 0;
444
445
0
        p = OSSL_PARAM_locate_const(params,
446
0
            OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST_PROPS);
447
0
        if (p != NULL) {
448
0
            str = mdprops;
449
0
            if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdprops)))
450
0
                return 0;
451
0
        }
452
453
0
        EVP_MD_free(prsactx->oaep_md);
454
0
        prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, mdname, mdprops);
455
456
0
        if (prsactx->oaep_md == NULL)
457
0
            return 0;
458
0
    }
459
460
1.07k
    p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE);
461
1.07k
    if (p != NULL) {
462
538
        int pad_mode = 0;
463
464
538
        switch (p->data_type) {
465
538
        case OSSL_PARAM_INTEGER: /* Support for legacy pad mode number */
466
538
            if (!OSSL_PARAM_get_int(p, &pad_mode))
467
0
                return 0;
468
538
            break;
469
538
        case OSSL_PARAM_UTF8_STRING: {
470
0
            int i;
471
472
0
            if (p->data == NULL)
473
0
                return 0;
474
475
0
            for (i = 0; padding_item[i].id != 0; i++) {
476
0
                if (strcmp(p->data, padding_item[i].ptr) == 0) {
477
0
                    pad_mode = padding_item[i].id;
478
0
                    break;
479
0
                }
480
0
            }
481
0
        } break;
482
0
        default:
483
0
            return 0;
484
538
        }
485
486
        /*
487
         * PSS padding is for signatures only so is not compatible with
488
         * asymmetric cipher use.
489
         */
490
538
        if (pad_mode == RSA_PKCS1_PSS_PADDING)
491
0
            return 0;
492
538
        if (pad_mode == RSA_PKCS1_OAEP_PADDING && prsactx->oaep_md == NULL) {
493
0
            prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA1", mdprops);
494
0
            if (prsactx->oaep_md == NULL)
495
0
                return 0;
496
0
        }
497
538
        prsactx->pad_mode = pad_mode;
498
538
    }
499
500
1.07k
    p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST);
501
1.07k
    if (p != NULL) {
502
0
        str = mdname;
503
0
        if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdname)))
504
0
            return 0;
505
506
0
        p = OSSL_PARAM_locate_const(params,
507
0
            OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS);
508
0
        if (p != NULL) {
509
0
            str = mdprops;
510
0
            if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(mdprops)))
511
0
                return 0;
512
0
        } else {
513
0
            str = NULL;
514
0
        }
515
516
0
        EVP_MD_free(prsactx->mgf1_md);
517
0
        prsactx->mgf1_md = EVP_MD_fetch(prsactx->libctx, mdname, str);
518
519
0
        if (prsactx->mgf1_md == NULL)
520
0
            return 0;
521
0
    }
522
523
1.07k
    p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL);
524
1.07k
    if (p != NULL) {
525
0
        void *tmp_label = NULL;
526
0
        size_t tmp_labellen;
527
528
0
        if (!OSSL_PARAM_get_octet_string(p, &tmp_label, 0, &tmp_labellen))
529
0
            return 0;
530
0
        OPENSSL_free(prsactx->oaep_label);
531
0
        prsactx->oaep_label = (unsigned char *)tmp_label;
532
0
        prsactx->oaep_labellen = tmp_labellen;
533
0
    }
534
535
1.07k
    p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION);
536
1.07k
    if (p != NULL) {
537
538
        unsigned int client_version;
538
539
538
        if (!OSSL_PARAM_get_uint(p, &client_version))
540
0
            return 0;
541
538
        prsactx->client_version = client_version;
542
538
    }
543
544
1.07k
    p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION);
545
1.07k
    if (p != NULL) {
546
0
        unsigned int alt_version;
547
548
0
        if (!OSSL_PARAM_get_uint(p, &alt_version))
549
0
            return 0;
550
0
        prsactx->alt_version = alt_version;
551
0
    }
552
553
1.07k
    return 1;
554
1.07k
}
555
556
static const OSSL_PARAM known_settable_ctx_params[] = {
557
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, NULL, 0),
558
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST_PROPS, NULL, 0),
559
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, NULL, 0),
560
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, NULL, 0),
561
    OSSL_PARAM_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS, NULL, 0),
562
    OSSL_PARAM_octet_string(OSSL_ASYM_CIPHER_PARAM_OAEP_LABEL, NULL, 0),
563
    OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION, NULL),
564
    OSSL_PARAM_uint(OSSL_ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION, NULL),
565
    OSSL_PARAM_END
566
};
567
568
static const OSSL_PARAM *rsa_settable_ctx_params(ossl_unused void *vprsactx,
569
    ossl_unused void *provctx)
570
10.5k
{
571
10.5k
    return known_settable_ctx_params;
572
10.5k
}
573
574
const OSSL_DISPATCH ossl_rsa_asym_cipher_functions[] = {
575
    { OSSL_FUNC_ASYM_CIPHER_NEWCTX, (void (*)(void))rsa_newctx },
576
    { OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT, (void (*)(void))rsa_encrypt_init },
577
    { OSSL_FUNC_ASYM_CIPHER_ENCRYPT, (void (*)(void))rsa_encrypt },
578
    { OSSL_FUNC_ASYM_CIPHER_DECRYPT_INIT, (void (*)(void))rsa_decrypt_init },
579
    { OSSL_FUNC_ASYM_CIPHER_DECRYPT, (void (*)(void))rsa_decrypt },
580
    { OSSL_FUNC_ASYM_CIPHER_FREECTX, (void (*)(void))rsa_freectx },
581
    { OSSL_FUNC_ASYM_CIPHER_DUPCTX, (void (*)(void))rsa_dupctx },
582
    { OSSL_FUNC_ASYM_CIPHER_GET_CTX_PARAMS,
583
        (void (*)(void))rsa_get_ctx_params },
584
    { OSSL_FUNC_ASYM_CIPHER_GETTABLE_CTX_PARAMS,
585
        (void (*)(void))rsa_gettable_ctx_params },
586
    { OSSL_FUNC_ASYM_CIPHER_SET_CTX_PARAMS,
587
        (void (*)(void))rsa_set_ctx_params },
588
    { OSSL_FUNC_ASYM_CIPHER_SETTABLE_CTX_PARAMS,
589
        (void (*)(void))rsa_settable_ctx_params },
590
    { 0, NULL }
591
};