blob: 1f216437c4ee7432b80f829a1f80fba4c57249cb [file] [log] [blame]
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +02001/**
2 * Internal MD/hash functions - no crypto, just data.
3 * This is used to avoid depending on MD_C just to query a length.
4 *
5 * Copyright The Mbed TLS Contributors
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#ifndef MBEDTLS_MD_INTERNAL_H
22#define MBEDTLS_MD_INTERNAL_H
23
24#include "common.h"
25
26#include "mbedtls/md.h"
Manuel Pégourié-Gonnardf88b1b52022-07-15 11:05:05 +020027#include "or_psa_helpers.h"
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +020028
29/** Get the output length of the given hash type
30 *
31 * \param md_type The hash type.
32 *
33 * \return The output length in bytes, or 0 if not known
34 */
35static inline unsigned char mbedtls_md_internal_get_size( mbedtls_md_type_t md_type )
36{
37 switch( md_type )
38 {
Manuel Pégourié-Gonnardf88b1b52022-07-15 11:05:05 +020039#if defined(MBEDTLS_OR_PSA_WANT_ALG_MD5)
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +020040 case MBEDTLS_MD_MD5:
41 return( 16 );
42#endif
Manuel Pégourié-Gonnardf88b1b52022-07-15 11:05:05 +020043#if defined(MBEDTLS_OR_PSA_WANT_ALG_RIPEMD160) || \
44 defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_1)
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +020045 case MBEDTLS_MD_RIPEMD160:
46 case MBEDTLS_MD_SHA1:
47 return( 20 );
48#endif
Manuel Pégourié-Gonnardf88b1b52022-07-15 11:05:05 +020049#if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_224)
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +020050 case MBEDTLS_MD_SHA224:
51 return( 28 );
52#endif
Manuel Pégourié-Gonnardf88b1b52022-07-15 11:05:05 +020053#if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_256)
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +020054 case MBEDTLS_MD_SHA256:
55 return( 32 );
56#endif
Manuel Pégourié-Gonnardf88b1b52022-07-15 11:05:05 +020057#if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_384)
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +020058 case MBEDTLS_MD_SHA384:
59 return( 48 );
60#endif
Manuel Pégourié-Gonnardf88b1b52022-07-15 11:05:05 +020061#if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_512)
Manuel Pégourié-Gonnardd8a298e2022-07-05 17:40:04 +020062 case MBEDTLS_MD_SHA512:
63 return( 64 );
64#endif
65 default:
66 return( 0 );
67 }
68}
69
70#endif /* MBEDTLS_MD_INTERNAL_H */