Manuel Pégourié-Gonnard | 36fb12e | 2023-03-28 11:33:23 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Translation between MD and PSA identifiers (algorithms, errors). |
| 3 | * |
| 4 | * Note: this internal module will go away when everything becomes based on |
| 5 | * PSA Crypto; it is a helper for the transition period. |
| 6 | * |
| 7 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame^] | 8 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Manuel Pégourié-Gonnard | 36fb12e | 2023-03-28 11:33:23 +0200 | [diff] [blame] | 9 | */ |
| 10 | #ifndef MBEDTLS_MD_PSA_H |
| 11 | #define MBEDTLS_MD_PSA_H |
| 12 | |
| 13 | #include "common.h" |
| 14 | |
| 15 | #include "mbedtls/md.h" |
| 16 | #include "psa/crypto.h" |
| 17 | |
| 18 | /** |
| 19 | * \brief This function returns the PSA algorithm identifier |
| 20 | * associated with the given digest type. |
| 21 | * |
Manuel Pégourié-Gonnard | 44176b0 | 2023-06-07 11:23:26 +0200 | [diff] [blame] | 22 | * \param md_type The type of digest to search for. Must not be NONE. |
| 23 | * |
| 24 | * \warning If \p md_type is \c MBEDTLS_MD_NONE, this function will |
| 25 | * not return \c PSA_ALG_NONE, but an invalid algorithm. |
Manuel Pégourié-Gonnard | 36fb12e | 2023-03-28 11:33:23 +0200 | [diff] [blame] | 26 | * |
Manuel Pégourié-Gonnard | 1f6d2e3 | 2023-06-06 12:34:45 +0200 | [diff] [blame] | 27 | * \warning This function does not check if the algorithm is |
| 28 | * supported, it always returns the corresponding identifier. |
| 29 | * |
Manuel Pégourié-Gonnard | 70aa2a1 | 2023-05-03 12:26:56 +0200 | [diff] [blame] | 30 | * \return The PSA algorithm identifier associated with \p md_type, |
| 31 | * regardless of whether it is supported or not. |
Manuel Pégourié-Gonnard | 36fb12e | 2023-03-28 11:33:23 +0200 | [diff] [blame] | 32 | */ |
Manuel Pégourié-Gonnard | 001cbc9 | 2023-06-07 12:06:06 +0200 | [diff] [blame] | 33 | static inline psa_algorithm_t mbedtls_md_psa_alg_from_type(mbedtls_md_type_t md_type) |
| 34 | { |
| 35 | return PSA_ALG_CATEGORY_HASH | (psa_algorithm_t) md_type; |
| 36 | } |
Manuel Pégourié-Gonnard | 36fb12e | 2023-03-28 11:33:23 +0200 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * \brief This function returns the given digest type |
| 40 | * associated with the PSA algorithm identifier. |
| 41 | * |
| 42 | * \param psa_alg The PSA algorithm identifier to search for. |
| 43 | * |
Manuel Pégourié-Gonnard | 1f6d2e3 | 2023-06-06 12:34:45 +0200 | [diff] [blame] | 44 | * \warning This function does not check if the algorithm is |
| 45 | * supported, it always returns the corresponding identifier. |
| 46 | * |
Manuel Pégourié-Gonnard | 70aa2a1 | 2023-05-03 12:26:56 +0200 | [diff] [blame] | 47 | * \return The MD type associated with \p psa_alg, |
| 48 | * regardless of whether it is supported or not. |
Manuel Pégourié-Gonnard | 36fb12e | 2023-03-28 11:33:23 +0200 | [diff] [blame] | 49 | */ |
Manuel Pégourié-Gonnard | 001cbc9 | 2023-06-07 12:06:06 +0200 | [diff] [blame] | 50 | static inline mbedtls_md_type_t mbedtls_md_type_from_psa_alg(psa_algorithm_t psa_alg) |
| 51 | { |
| 52 | return (mbedtls_md_type_t) (psa_alg & PSA_ALG_HASH_MASK); |
| 53 | } |
Manuel Pégourié-Gonnard | 36fb12e | 2023-03-28 11:33:23 +0200 | [diff] [blame] | 54 | |
| 55 | /** Convert PSA status to MD error code. |
| 56 | * |
| 57 | * \param status PSA status. |
| 58 | * |
| 59 | * \return The corresponding MD error code, |
| 60 | */ |
| 61 | int mbedtls_md_error_from_psa(psa_status_t status); |
| 62 | |
| 63 | #endif /* MBEDTLS_MD_PSA_H */ |