Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Context structure declaration of the software-based driver which performs |
| 3 | * hashing through the PSA Crypto driver dispatch layer. |
| 4 | */ |
| 5 | /* |
| 6 | * Copyright The Mbed TLS Contributors |
| 7 | * SPDX-License-Identifier: Apache-2.0 |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | * not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | */ |
| 21 | |
| 22 | #ifndef PSA_CRYPTO_BUILTIN_HASH_H |
| 23 | #define PSA_CRYPTO_BUILTIN_HASH_H |
| 24 | |
| 25 | #include <psa/crypto_driver_common.h> |
| 26 | #include "mbedtls/md2.h" |
| 27 | #include "mbedtls/md4.h" |
| 28 | #include "mbedtls/md5.h" |
| 29 | #include "mbedtls/ripemd160.h" |
| 30 | #include "mbedtls/sha1.h" |
| 31 | #include "mbedtls/sha256.h" |
| 32 | #include "mbedtls/sha512.h" |
| 33 | |
| 34 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) || \ |
| 35 | defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) || \ |
| 36 | defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \ |
| 37 | defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \ |
| 38 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \ |
| 39 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \ |
| 40 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ |
| 41 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \ |
| 42 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) |
| 43 | #define MBEDTLS_PSA_BUILTIN_HASH |
| 44 | #endif |
| 45 | |
| 46 | typedef struct |
| 47 | { |
| 48 | psa_algorithm_t alg; |
| 49 | union |
| 50 | { |
| 51 | unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ |
| 52 | #if defined(MBEDTLS_MD2_C) |
| 53 | mbedtls_md2_context md2; |
| 54 | #endif |
| 55 | #if defined(MBEDTLS_MD4_C) |
| 56 | mbedtls_md4_context md4; |
| 57 | #endif |
| 58 | #if defined(MBEDTLS_MD5_C) |
| 59 | mbedtls_md5_context md5; |
| 60 | #endif |
| 61 | #if defined(MBEDTLS_RIPEMD160_C) |
| 62 | mbedtls_ripemd160_context ripemd160; |
| 63 | #endif |
| 64 | #if defined(MBEDTLS_SHA1_C) |
| 65 | mbedtls_sha1_context sha1; |
| 66 | #endif |
| 67 | #if defined(MBEDTLS_SHA256_C) |
| 68 | mbedtls_sha256_context sha256; |
| 69 | #endif |
| 70 | #if defined(MBEDTLS_SHA512_C) |
| 71 | mbedtls_sha512_context sha512; |
| 72 | #endif |
| 73 | } ctx; |
| 74 | } mbedtls_psa_hash_operation_t; |
| 75 | |
| 76 | #define MBEDTLS_PSA_HASH_OPERATION_INIT {0, {0}} |
| 77 | |
| 78 | /* |
| 79 | * BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY. |
| 80 | */ |
| 81 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 82 | |
| 83 | typedef struct { |
| 84 | mbedtls_psa_hash_operation_t operation; |
| 85 | } mbedtls_transparent_test_driver_hash_operation_t; |
| 86 | |
| 87 | #define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT { MBEDTLS_PSA_HASH_OPERATION_INIT } |
| 88 | |
| 89 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 90 | |
| 91 | #endif /* PSA_CRYPTO_BUILTIN_HASH_H */ |