Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 1 | /** |
| 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" |
| 27 | |
| 28 | /** Get the output length of the given hash type |
| 29 | * |
| 30 | * \param md_type The hash type. |
| 31 | * |
| 32 | * \return The output length in bytes, or 0 if not known |
| 33 | */ |
| 34 | static inline unsigned char mbedtls_md_internal_get_size( mbedtls_md_type_t md_type ) |
| 35 | { |
| 36 | switch( md_type ) |
| 37 | { |
| 38 | #if defined(MBEDTLS_MD5_C) || defined(PSA_WANT_ALG_MD5) |
| 39 | case MBEDTLS_MD_MD5: |
| 40 | return( 16 ); |
| 41 | #endif |
| 42 | #if defined(MBEDTLS_RIPEMD160_C) || defined(PSA_WANT_ALG_RIPEMD160) || \ |
| 43 | defined(MBEDTLS_SHA1_C) || defined(PSA_WANT_ALG_SHA_1) |
| 44 | case MBEDTLS_MD_RIPEMD160: |
| 45 | case MBEDTLS_MD_SHA1: |
| 46 | return( 20 ); |
| 47 | #endif |
| 48 | #if defined(MBEDTLS_SHA224_C) || defined(PSA_WANT_ALG_SHA_224) |
| 49 | case MBEDTLS_MD_SHA224: |
| 50 | return( 28 ); |
| 51 | #endif |
| 52 | #if defined(MBEDTLS_SHA256_C) || defined(PSA_WANT_ALG_SHA_256) |
| 53 | case MBEDTLS_MD_SHA256: |
| 54 | return( 32 ); |
| 55 | #endif |
| 56 | #if defined(MBEDTLS_SHA384_C) || defined(PSA_WANT_ALG_SHA_384) |
| 57 | case MBEDTLS_MD_SHA384: |
| 58 | return( 48 ); |
| 59 | #endif |
| 60 | #if defined(MBEDTLS_SHA512_C) || defined(PSA_WANT_ALG_SHA_512) |
| 61 | case MBEDTLS_MD_SHA512: |
| 62 | return( 64 ); |
| 63 | #endif |
| 64 | default: |
| 65 | return( 0 ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | #endif /* MBEDTLS_MD_INTERNAL_H */ |