Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * \file tfm_crypto_struct.h |
| 10 | * |
| 11 | * \brief Similarly to what psa_crypto_struct.h defines for |
| 12 | * the frontend, this header provides Crypto service |
| 13 | * specific definitions for operation contexts. |
| 14 | * Current implementation is directly based on Mbed TLS. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __TFM_CRYPTO_STRUCT_H__ |
| 18 | #define __TFM_CRYPTO_STRUCT_H__ |
| 19 | |
| 20 | /* Include the Mbed TLS configuration file, the way Mbed TLS does it |
| 21 | * in each of its header files. |
| 22 | */ |
| 23 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 24 | #include "platform/ext/common/tfm_mbedtls_config.h" |
| 25 | #else |
| 26 | #include MBEDTLS_CONFIG_FILE |
| 27 | #endif |
| 28 | |
| 29 | #include "mbedtls/cipher.h" |
| 30 | #include "mbedtls/cmac.h" |
| 31 | #include "mbedtls/md.h" |
| 32 | |
| 33 | struct tfm_hash_operation_s |
| 34 | { |
| 35 | psa_algorithm_t alg; |
| 36 | mbedtls_md_context_t md; |
| 37 | }; |
| 38 | |
| 39 | struct tfm_hmac_internal_data_s |
| 40 | { |
| 41 | /* The hash context. */ |
| 42 | struct psa_hash_operation_s hash_ctx; |
| 43 | /* The HMAC part of the context. */ |
| 44 | uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE]; |
| 45 | }; |
| 46 | |
| 47 | struct tfm_mac_operation_s |
| 48 | { |
| 49 | psa_algorithm_t alg; |
| 50 | uint8_t key_set; |
| 51 | uint8_t iv_required; |
| 52 | uint8_t iv_set; |
| 53 | uint8_t has_input; |
| 54 | uint8_t key_usage_sign; |
| 55 | uint8_t key_usage_verify; |
| 56 | uint8_t mac_size; |
| 57 | union |
| 58 | { |
| 59 | struct tfm_hmac_internal_data_s hmac; |
| 60 | mbedtls_cipher_context_t cmac; |
| 61 | } ctx; |
| 62 | }; |
| 63 | |
| 64 | #define PSA_CIPHER_IV_MAX_SIZE 16 |
| 65 | |
| 66 | struct tfm_cipher_operation_s |
| 67 | { |
| 68 | psa_algorithm_t alg; |
| 69 | uint8_t key_set; |
| 70 | uint8_t iv_required; |
| 71 | uint8_t iv_set; |
| 72 | uint8_t iv_size; |
| 73 | uint8_t block_size; |
| 74 | psa_key_slot_t key; |
| 75 | mbedtls_cipher_context_t cipher; |
| 76 | }; |
| 77 | #endif /* __TFM_CRYPTO_STRUCT_H__ */ |