Coverage Report

Created: 2023-04-12 06:23

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