blob: 120585bd6fcb03e334b44b305765b317697d7891 [file] [log] [blame]
Raef Coles237af692022-07-20 10:36:43 +01001/*
2 * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8/* Interop between TF-M fih.h and mcuboot fault_injection_hardening.h, so that
9 * platform code can target fih.h and for bl2 this will be redirected to
10 * fault_injection_hardening.h
11 */
12
13#ifndef __INTEROP_FIH_H__
14#define __INTEROP_FIH_H__
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20#include "stdint.h"
21
22#undef FIH_ENABLE_GLOBAL_FAIL
23#undef FIH_ENABLE_CFI
24#undef FIH_ENABLE_DOUBLE_VARS
25#undef FIH_ENABLE_DELAY
26
27#if !defined(MCUBOOT_FIH_PROFILE_OFF)
28
29#if defined(MCUBOOT_FIH_PROFILE_LOW)
30#define FIH_ENABLE_GLOBAL_FAIL
31#define FIH_ENABLE_CFI
32
33#elif defined(MCUBOOT_FIH_PROFILE_MEDIUM)
34#define FIH_ENABLE_DOUBLE_VARS
35#define FIH_ENABLE_GLOBAL_FAIL
36#define FIH_ENABLE_CFI
37
38#elif defined(MCUBOOT_FIH_PROFILE_HIGH)
39#define FIH_ENABLE_DELAY /* Requires an hardware entropy source */
40#define FIH_ENABLE_DOUBLE_VARS
41#define FIH_ENABLE_GLOBAL_FAIL
42#define FIH_ENABLE_CFI
43
44#else
45#error "Invalid FIH Profile configuration"
46#endif /* MCUBOOT_FIH_PROFILE */
47
48/*
49 * FIH return type macro changes the function return types to fih_int.
50 * All functions that need to be protected by FIH and called via FIH_CALL must
51 * return a fih_int type.
52 */
53#define FIH_RET_TYPE(type) fih_int
54
55#include "bootutil/fault_injection_hardening.h"
56
57#else /* MCUBOOT_FIH_PROFILE_OFF */
58typedef int32_t fih_int;
59
60#define FIH_INT_INIT(x) (x)
61
62#define FIH_SUCCESS 0
63#define FIH_FAILURE -1
64
65#define fih_int_validate(x)
66
67#define fih_int_decode(x) (x)
68
69#define fih_int_encode(x) (x)
70
71#define fih_int_encode_zero_equality(x) ((x) == 0 ? 0 : 1)
72
73#define fih_eq(x, y) ((x) == (y))
74
75#define fih_not_eq(x, y) ((x) != (y))
76
77#define fih_delay_init() (0)
78#define fih_delay()
79
80#define FIH_CALL(f, ret, ...) \
81 do { \
82 ret = f(__VA_ARGS__); \
83 } while (0)
84
85#define FIH_RET(ret) \
86 do { \
87 return ret; \
88 } while (0)
89
90#define FIH_PANIC do { \
91 while(1) {}; \
92 } while (0)
93
94#define FIH_RET_TYPE(type) type
95
96#define FIH_CFI_STEP_INIT(x)
97#define FIH_CFI_STEP_DECREMENT()
98#define FIH_CFI_STEP_ERR_RESET()
99
100#define FIH_LABEL_CRITICAL_POINT()
101
102#endif /* !MCUBOOT_FIH_PROFILE_OFF */
103
104
105#ifdef __cplusplus
106}
107#endif /* __cplusplus */
108
109#endif /* __INTEROP_FIH_H__ */