]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/common/digest_to_nid.c
Fix typo in CONTRIBUTING.md
[thirdparty/openssl.git] / providers / common / digest_to_nid.c
CommitLineData
16fbda84 1/*
8020d79b 2 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
16fbda84
SL
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
52c8535a
P
10#include "internal/deprecated.h"
11
16fbda84
SL
12#include <openssl/objects.h>
13#include <openssl/core_names.h>
14#include <openssl/evp.h>
15#include <openssl/core.h>
7a810fac 16#include "prov/securitycheck.h"
16fbda84
SL
17#include "internal/nelem.h"
18
19/*
20 * Internal library code deals with NIDs, so we need to translate from a name.
21 * We do so using EVP_MD_is_a(), and therefore need a name to NID map.
22 */
7b676cc8 23int ossl_digest_md_to_nid(const EVP_MD *md, const OSSL_ITEM *it, size_t it_len)
16fbda84
SL
24{
25 size_t i;
16fbda84
SL
26
27 if (md == NULL)
49ed5ba8 28 return NID_undef;
16fbda84 29
49ed5ba8
SL
30 for (i = 0; i < it_len; i++)
31 if (EVP_MD_is_a(md, it[i].ptr))
32 return (int)it[i].id;
33 return NID_undef;
16fbda84
SL
34}
35
36/*
6a2ab4a9 37 * Retrieve one of the FIPS approved hash algorithms by nid.
16fbda84
SL
38 * See FIPS 180-4 "Secure Hash Standard" and FIPS 202 - SHA-3.
39 */
7b676cc8 40int ossl_digest_get_approved_nid(const EVP_MD *md)
16fbda84
SL
41{
42 static const OSSL_ITEM name_to_nid[] = {
43 { NID_sha1, OSSL_DIGEST_NAME_SHA1 },
44 { NID_sha224, OSSL_DIGEST_NAME_SHA2_224 },
45 { NID_sha256, OSSL_DIGEST_NAME_SHA2_256 },
46 { NID_sha384, OSSL_DIGEST_NAME_SHA2_384 },
47 { NID_sha512, OSSL_DIGEST_NAME_SHA2_512 },
48 { NID_sha512_224, OSSL_DIGEST_NAME_SHA2_512_224 },
49 { NID_sha512_256, OSSL_DIGEST_NAME_SHA2_512_256 },
50 { NID_sha3_224, OSSL_DIGEST_NAME_SHA3_224 },
51 { NID_sha3_256, OSSL_DIGEST_NAME_SHA3_256 },
52 { NID_sha3_384, OSSL_DIGEST_NAME_SHA3_384 },
53 { NID_sha3_512, OSSL_DIGEST_NAME_SHA3_512 },
54 };
55
7b676cc8 56 return ossl_digest_md_to_nid(md, name_to_nid, OSSL_NELEM(name_to_nid));
16fbda84 57}