Coverage Report

Created: 2025-06-22 06:56

/src/openssl/crypto/rsa/rsa_schemes.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2020-2024 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
#include <openssl/core.h>
11
#include <openssl/core_names.h>
12
#include <openssl/evp.h>
13
#include <openssl/obj_mac.h>
14
#include "internal/nelem.h"
15
#include "crypto/rsa.h"
16
17
static int meth2nid(const void *meth,
18
                    int (*meth_is_a)(const void *meth, const char *name),
19
                    const OSSL_ITEM *items, size_t items_n)
20
0
{
21
0
    size_t i;
22
23
0
    if (meth != NULL)
24
0
        for (i = 0; i < items_n; i++)
25
0
            if (meth_is_a(meth, items[i].ptr))
26
0
                return (int)items[i].id;
27
0
    return NID_undef;
28
0
}
29
30
static const char *nid2name(int meth, const OSSL_ITEM *items, size_t items_n)
31
0
{
32
0
    size_t i;
33
34
0
    for (i = 0; i < items_n; i++)
35
0
        if (meth == (int)items[i].id)
36
0
            return items[i].ptr;
37
0
    return NULL;
38
0
}
39
40
/*
41
 * The list of permitted hash functions are taken from
42
 * https://tools.ietf.org/html/rfc8017#appendix-A.2.1:
43
 *
44
 * OAEP-PSSDigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
45
 *     { OID id-sha1       PARAMETERS NULL }|
46
 *     { OID id-sha224     PARAMETERS NULL }|
47
 *     { OID id-sha256     PARAMETERS NULL }|
48
 *     { OID id-sha384     PARAMETERS NULL }|
49
 *     { OID id-sha512     PARAMETERS NULL }|
50
 *     { OID id-sha512-224 PARAMETERS NULL }|
51
 *     { OID id-sha512-256 PARAMETERS NULL },
52
 *     ...  -- Allows for future expansion --
53
 * }
54
 */
55
static const OSSL_ITEM oaeppss_name_nid_map[] = {
56
    { NID_sha1,         OSSL_DIGEST_NAME_SHA1         },
57
    { NID_sha224,       OSSL_DIGEST_NAME_SHA2_224     },
58
    { NID_sha256,       OSSL_DIGEST_NAME_SHA2_256     },
59
    { NID_sha384,       OSSL_DIGEST_NAME_SHA2_384     },
60
    { NID_sha512,       OSSL_DIGEST_NAME_SHA2_512     },
61
    { NID_sha512_224,   OSSL_DIGEST_NAME_SHA2_512_224 },
62
    { NID_sha512_256,   OSSL_DIGEST_NAME_SHA2_512_256 },
63
};
64
65
static int md_is_a(const void *md, const char *name)
66
0
{
67
0
    return EVP_MD_is_a(md, name);
68
0
}
69
70
int ossl_rsa_oaeppss_md2nid(const EVP_MD *md)
71
0
{
72
0
    return meth2nid(md, md_is_a,
73
0
                    oaeppss_name_nid_map, OSSL_NELEM(oaeppss_name_nid_map));
74
0
}
75
76
const char *ossl_rsa_oaeppss_nid2name(int md)
77
0
{
78
0
    return nid2name(md, oaeppss_name_nid_map, OSSL_NELEM(oaeppss_name_nid_map));
79
0
}
80
81
const char *ossl_rsa_mgf_nid2name(int mgf)
82
0
{
83
0
    if (mgf == NID_mgf1)
84
0
        return SN_mgf1;
85
0
    return NULL;
86
0
}