2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
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
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"
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
)
24 for (i
= 0; i
< items_n
; i
++)
25 if (meth_is_a(meth
, items
[i
].ptr
))
26 return (int)items
[i
].id
;
30 static const char *nid2name(int meth
, const OSSL_ITEM
*items
, size_t items_n
)
34 for (i
= 0; i
< items_n
; i
++)
35 if (meth
== (int)items
[i
].id
)
41 * The list of permitted hash functions are taken from
42 * https://tools.ietf.org/html/rfc8017#appendix-A.2.1:
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 --
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
},
65 static int md_is_a(const void *md
, const char *name
)
67 return EVP_MD_is_a(md
, name
);
70 int rsa_oaeppss_md2nid(const EVP_MD
*md
)
72 return meth2nid(md
, md_is_a
,
73 oaeppss_name_nid_map
, OSSL_NELEM(oaeppss_name_nid_map
));
76 const char *rsa_oaeppss_nid2name(int md
)
78 return nid2name(md
, oaeppss_name_nid_map
, OSSL_NELEM(oaeppss_name_nid_map
));
81 const char *rsa_mgf_nid2name(int mgf
)