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" |
Manuel Pégourié-Gonnard | f88b1b5 | 2022-07-15 11:05:05 +0200 | [diff] [blame^] | 27 | #include "or_psa_helpers.h" |
Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 28 | |
| 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 | */ |
| 35 | static inline unsigned char mbedtls_md_internal_get_size( mbedtls_md_type_t md_type ) |
| 36 | { |
| 37 | switch( md_type ) |
| 38 | { |
Manuel Pégourié-Gonnard | f88b1b5 | 2022-07-15 11:05:05 +0200 | [diff] [blame^] | 39 | #if defined(MBEDTLS_OR_PSA_WANT_ALG_MD5) |
Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 40 | case MBEDTLS_MD_MD5: |
| 41 | return( 16 ); |
| 42 | #endif |
Manuel Pégourié-Gonnard | f88b1b5 | 2022-07-15 11:05:05 +0200 | [diff] [blame^] | 43 | #if defined(MBEDTLS_OR_PSA_WANT_ALG_RIPEMD160) || \ |
| 44 | defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_1) |
Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 45 | case MBEDTLS_MD_RIPEMD160: |
| 46 | case MBEDTLS_MD_SHA1: |
| 47 | return( 20 ); |
| 48 | #endif |
Manuel Pégourié-Gonnard | f88b1b5 | 2022-07-15 11:05:05 +0200 | [diff] [blame^] | 49 | #if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_224) |
Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 50 | case MBEDTLS_MD_SHA224: |
| 51 | return( 28 ); |
| 52 | #endif |
Manuel Pégourié-Gonnard | f88b1b5 | 2022-07-15 11:05:05 +0200 | [diff] [blame^] | 53 | #if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_256) |
Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 54 | case MBEDTLS_MD_SHA256: |
| 55 | return( 32 ); |
| 56 | #endif |
Manuel Pégourié-Gonnard | f88b1b5 | 2022-07-15 11:05:05 +0200 | [diff] [blame^] | 57 | #if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_384) |
Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 58 | case MBEDTLS_MD_SHA384: |
| 59 | return( 48 ); |
| 60 | #endif |
Manuel Pégourié-Gonnard | f88b1b5 | 2022-07-15 11:05:05 +0200 | [diff] [blame^] | 61 | #if defined(MBEDTLS_OR_PSA_WANT_ALG_SHA_512) |
Manuel Pégourié-Gonnard | d8a298e | 2022-07-05 17:40:04 +0200 | [diff] [blame] | 62 | case MBEDTLS_MD_SHA512: |
| 63 | return( 64 ); |
| 64 | #endif |
| 65 | default: |
| 66 | return( 0 ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | #endif /* MBEDTLS_MD_INTERNAL_H */ |