diff --git a/boot/boot_serial/include/boot_serial/boot_serial_encryption.h b/boot/boot_serial/include/boot_serial/boot_serial_encryption.h index 6b42a3bdca..b7496e7c43 100644 --- a/boot/boot_serial/include/boot_serial/boot_serial_encryption.h +++ b/boot/boot_serial/include/boot_serial/boot_serial_encryption.h @@ -6,7 +6,7 @@ #ifndef H_BOOT_SERIAL_ENCRYPTION_ #define H_BOOT_SERIAL_ENCRYPTION_ -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" /** * Validate hash of a primary boot image doing on the fly decryption as well diff --git a/boot/boot_serial/src/boot_serial_encryption.c b/boot/boot_serial/src/boot_serial_encryption.c index dc919af852..dbc7edf3c5 100644 --- a/boot/boot_serial/src/boot_serial_encryption.c +++ b/boot/boot_serial/src/boot_serial_encryption.c @@ -14,7 +14,7 @@ #include <../src/bootutil_priv.h> #include "bootutil/bootutil_log.h" #include "bootutil/bootutil_public.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" BOOT_LOG_MODULE_REGISTER(serial_encryption); diff --git a/boot/bootutil/CMakeLists.txt b/boot/bootutil/CMakeLists.txt index 5388828ee0..6b86a9a39e 100644 --- a/boot/bootutil/CMakeLists.txt +++ b/boot/bootutil/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(bootutil STATIC) target_include_directories(bootutil PUBLIC include + ../fault_injection_hardening/include PRIVATE src ) @@ -26,7 +27,7 @@ target_sources(bootutil src/bootutil_public.c src/caps.c src/encrypted.c - src/fault_injection_hardening.c + ../fault_injection_hardening/src/fault_injection_hardening.c src/image_ecdsa.c src/image_ed25519.c src/image_rsa.c diff --git a/boot/bootutil/include/bootutil/boot_hooks.h b/boot/bootutil/include/bootutil/boot_hooks.h index 96414e3dfa..615dc567c3 100644 --- a/boot/bootutil/include/bootutil/boot_hooks.h +++ b/boot/bootutil/include/bootutil/boot_hooks.h @@ -35,7 +35,7 @@ #define H_BOOTUTIL_HOOKS #include "bootutil/bootutil.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #define DO_HOOK_CALL(f, ret_default, ...) \ f(__VA_ARGS__) diff --git a/boot/bootutil/include/bootutil/bootutil.h b/boot/bootutil/include/bootutil/bootutil.h index 196fcb00df..7caaa9790a 100644 --- a/boot/bootutil/include/bootutil/bootutil.h +++ b/boot/bootutil/include/bootutil/bootutil.h @@ -30,7 +30,7 @@ #include #include -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil/bootutil_public.h" #ifdef __cplusplus diff --git a/boot/bootutil/include/bootutil/image.h b/boot/bootutil/include/bootutil/image.h index 3d103f8daa..69afcb7477 100644 --- a/boot/bootutil/include/bootutil/image.h +++ b/boot/bootutil/include/bootutil/image.h @@ -30,7 +30,7 @@ #include #include -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #ifdef __cplusplus extern "C" { diff --git a/boot/bootutil/include/bootutil/mcuboot_uuid.h b/boot/bootutil/include/bootutil/mcuboot_uuid.h index 433d1d2fe3..1347e79f36 100644 --- a/boot/bootutil/include/bootutil/mcuboot_uuid.h +++ b/boot/bootutil/include/bootutil/mcuboot_uuid.h @@ -17,7 +17,7 @@ */ #include -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #ifdef __cplusplus extern "C" { diff --git a/boot/bootutil/include/bootutil/security_cnt.h b/boot/bootutil/include/bootutil/security_cnt.h index f8365caa22..cff60605c0 100644 --- a/boot/bootutil/include/bootutil/security_cnt.h +++ b/boot/bootutil/include/bootutil/security_cnt.h @@ -26,7 +26,7 @@ */ #include -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #ifdef __cplusplus extern "C" { diff --git a/boot/bootutil/include/fih_config.h b/boot/bootutil/include/fih_config.h new file mode 100644 index 0000000000..17ccfd12a1 --- /dev/null +++ b/boot/bootutil/include/fih_config.h @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * (c) 2026, Infineon Technologies AG, or an affiliate of Infineon + * Technologies AG. All rights reserved. + */ + +#ifndef __FIH_CONFIG_H__ +#define __FIH_CONFIG_H__ + +/* + * MCUboot-specific configuration adapter for the fault_injection_hardening + * library. This file maps the MCUBOOT_FIH_PROFILE_* build options to the + * generic FIH_PROFILE_* macros consumed by fault_injection_hardening.h. + */ + +#include "mcuboot_config/mcuboot_config.h" + +#if defined(MCUBOOT_FIH_PROFILE_HIGH) +# define FIH_PROFILE_HIGH +#elif defined(MCUBOOT_FIH_PROFILE_MEDIUM) +# define FIH_PROFILE_MEDIUM +#elif defined(MCUBOOT_FIH_PROFILE_LOW) +# define FIH_PROFILE_LOW +#elif defined(MCUBOOT_FIH_PROFILE_OFF) +# define FIH_PROFILE_OFF +#else +/* Default: fault injection hardening disabled */ +# define FIH_PROFILE_OFF +#endif + +#endif /* __FIH_CONFIG_H__ */ diff --git a/boot/bootutil/src/bootutil_find_key.c b/boot/bootutil/src/bootutil_find_key.c index 7d34e05f4d..6f49aa61e9 100644 --- a/boot/bootutil/src/bootutil_find_key.c +++ b/boot/bootutil/src/bootutil_find_key.c @@ -29,7 +29,7 @@ #include #include "bootutil/crypto/sha.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil/image.h" #include "bootutil/sign_key.h" #include "bootutil_priv.h" diff --git a/boot/bootutil/src/bootutil_loader.h b/boot/bootutil/src/bootutil_loader.h index 530f09131d..033564f497 100644 --- a/boot/bootutil/src/bootutil_loader.h +++ b/boot/bootutil/src/bootutil_loader.h @@ -33,7 +33,7 @@ #include #include "bootutil/image.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil/bootutil.h" #include "bootutil_priv.h" diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c index c8644bec4f..6d2879d18b 100644 --- a/boot/bootutil/src/bootutil_misc.c +++ b/boot/bootutil/src/bootutil_misc.c @@ -38,7 +38,7 @@ #include "bootutil_priv.h" #include "bootutil_misc.h" #include "bootutil/bootutil_log.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #ifdef MCUBOOT_ENC_IMAGES #include "bootutil/enc_key.h" #endif diff --git a/boot/bootutil/src/bootutil_priv.h b/boot/bootutil/src/bootutil_priv.h index 77bce24ec1..4ebbe2031d 100644 --- a/boot/bootutil/src/bootutil_priv.h +++ b/boot/bootutil/src/bootutil_priv.h @@ -36,7 +36,7 @@ #include "bootutil/bootutil.h" #include "bootutil/image.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil_area.h" #include "mcuboot_config/mcuboot_config.h" diff --git a/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c b/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c index 663999b5d3..ddc0f8eb50 100644 --- a/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c +++ b/boot/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c @@ -4,7 +4,7 @@ * Copyright (c) 2020 Arm Limited */ -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #ifdef FIH_ENABLE_DELAY diff --git a/boot/bootutil/src/fault_injection_hardening_delay_rng_psa.c b/boot/bootutil/src/fault_injection_hardening_delay_rng_psa.c index 7900c2c485..4d39c9cffc 100644 --- a/boot/bootutil/src/fault_injection_hardening_delay_rng_psa.c +++ b/boot/bootutil/src/fault_injection_hardening_delay_rng_psa.c @@ -15,7 +15,7 @@ * is the stable, backend-independent replacement. */ -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #ifdef FIH_ENABLE_DELAY diff --git a/boot/bootutil/src/image_ecdsa.c b/boot/bootutil/src/image_ecdsa.c index 30c7d0d0f3..a41e19d80f 100644 --- a/boot/bootutil/src/image_ecdsa.c +++ b/boot/bootutil/src/image_ecdsa.c @@ -35,7 +35,7 @@ BOOT_LOG_MODULE_DECLARE(mcuboot); #if defined(MCUBOOT_SIGN_EC256) || defined(MCUBOOT_SIGN_EC384) #include "bootutil_priv.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil/crypto/ecdsa.h" #if !defined(MCUBOOT_BUILTIN_KEY) diff --git a/boot/bootutil/src/image_rsa.c b/boot/bootutil/src/image_rsa.c index 5479b75ebd..02665e9c71 100644 --- a/boot/bootutil/src/image_rsa.c +++ b/boot/bootutil/src/image_rsa.c @@ -35,7 +35,7 @@ BOOT_LOG_MODULE_DECLARE(mcuboot); #ifdef MCUBOOT_SIGN_RSA #include "bootutil_priv.h" #include "bootutil/sign_key.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #define BOOTUTIL_CRYPTO_RSA_SIGN_ENABLED #include "bootutil/crypto/rsa.h" diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c index 3e8031b768..8d69600695 100644 --- a/boot/bootutil/src/image_validate.c +++ b/boot/bootutil/src/image_validate.c @@ -40,7 +40,7 @@ #include "bootutil/crypto/sha.h" #include "bootutil/sign_key.h" #include "bootutil/security_cnt.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "mcuboot_config/mcuboot_config.h" #include "bootutil/bootutil_log.h" diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c index 6b0e84a03e..3b2b13a5ad 100644 --- a/boot/bootutil/src/loader.c +++ b/boot/bootutil/src/loader.c @@ -45,7 +45,7 @@ #include "bootutil/bootutil_log.h" #include "bootutil/security_cnt.h" #include "bootutil/boot_record.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil/ramload.h" #include "bootutil/boot_hooks.h" #include "bootutil/mcuboot_status.h" diff --git a/boot/bootutil/src/ram_load.c b/boot/bootutil/src/ram_load.c index 31d4852fe4..25cc93cd4c 100644 --- a/boot/bootutil/src/ram_load.c +++ b/boot/bootutil/src/ram_load.c @@ -31,7 +31,7 @@ #include "bootutil/bootutil_public.h" #include "bootutil/image.h" #include "bootutil_priv.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil/ramload.h" #include "bootutil/mcuboot_status.h" diff --git a/boot/cypress/MCUBootApp/MCUBootApp.mk b/boot/cypress/MCUBootApp/MCUBootApp.mk index bba1160304..9e5f6ca7af 100644 --- a/boot/cypress/MCUBootApp/MCUBootApp.mk +++ b/boot/cypress/MCUBootApp/MCUBootApp.mk @@ -84,6 +84,7 @@ SOURCES_APP += $(SOURCES_APP_SRC) SOURCES_APP += $(SOURCES_FLASH_PORT) INCLUDE_DIRS_MCUBOOT := $(addprefix -I, $(CURDIR)/../bootutil/include) +INCLUDE_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/../fault_injection_hardening/include) INCLUDE_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/../bootutil/src) INCLUDE_DIRS_MCUBOOT += $(addprefix -I, $(CURDIR)/..) diff --git a/boot/cypress/MCUBootApp/main.c b/boot/cypress/MCUBootApp/main.c index a87d98123c..f497aa29e8 100644 --- a/boot/cypress/MCUBootApp/main.c +++ b/boot/cypress/MCUBootApp/main.c @@ -36,7 +36,7 @@ #include "bootutil/bootutil_log.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "watchdog.h" diff --git a/boot/espressif/CMakeLists.txt b/boot/espressif/CMakeLists.txt index 31087fbc66..ffe9610ef9 100644 --- a/boot/espressif/CMakeLists.txt +++ b/boot/espressif/CMakeLists.txt @@ -185,6 +185,7 @@ set(ZCBOR_DIR ${MCUBOOT_ROOT_DIR}/boot/zcbor) list(APPEND inc_directories ${BOOTUTIL_DIR}/include + ${MCUBOOT_ROOT_DIR}/boot/fault_injection_hardening/include ${BOOTUTIL_DIR}/src ${ESPRESSIF_PORT_DIR}/include ) @@ -206,7 +207,7 @@ set(bootutil_srcs ${BOOTUTIL_DIR}/src/bootutil_public.c ${BOOTUTIL_DIR}/src/caps.c ${BOOTUTIL_DIR}/src/encrypted.c - ${BOOTUTIL_DIR}/src/fault_injection_hardening.c + ${MCUBOOT_ROOT_DIR}/boot/fault_injection_hardening/src/fault_injection_hardening.c ${BOOTUTIL_DIR}/src/fault_injection_hardening_delay_rng_mbedtls.c ${BOOTUTIL_DIR}/src/image_ecdsa.c ${BOOTUTIL_DIR}/src/image_ed25519.c diff --git a/boot/espressif/main.c b/boot/espressif/main.c index 0a736780f9..358e04acc5 100644 --- a/boot/espressif/main.c +++ b/boot/espressif/main.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include "bootloader_init.h" diff --git a/boot/espressif/port/esp_loader.c b/boot/espressif/port/esp_loader.c index a6d101edae..205ba86876 100644 --- a/boot/espressif/port/esp_loader.c +++ b/boot/espressif/port/esp_loader.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include "bootloader_memory_utils.h" #include "bootloader_flash_priv.h" diff --git a/boot/fault_injection_hardening/.gitignore b/boot/fault_injection_hardening/.gitignore new file mode 100644 index 0000000000..d5bd6f76bc --- /dev/null +++ b/boot/fault_injection_hardening/.gitignore @@ -0,0 +1,42 @@ +# Build artifacts +*.o +*.a +*.so +*.dylib +*.dll +*.exe +*.elf +*.bin +*.hex +*.map + +# CMake +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +Makefile +build/ + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.egg-info/ +dist/ +build/ + +# IDEs +.vscode/ +.idea/ +*.swp +*.swo +*~ +.DS_Store + +# Cargo/Rust (if used) +target/ +Cargo.lock + +# Temporary files +*.tmp +*.bak diff --git a/boot/fault_injection_hardening/CMakeLists.txt b/boot/fault_injection_hardening/CMakeLists.txt new file mode 100644 index 0000000000..321332e6d8 --- /dev/null +++ b/boot/fault_injection_hardening/CMakeLists.txt @@ -0,0 +1,37 @@ +# +# CMakeLists.txt for the Fault Injection Hardening library +# +# This is the top-level CMakeLists.txt for building the FIH library as a +# standalone component. When used within MCUboot, the FIH sources are typically +# integrated into the bootutil library. This file allows FIH to be built and +# tested independently. +# +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2020 Arm Limited +# + +cmake_minimum_required(VERSION 3.12) +project(fault_injection_hardening) + +# Add the FIH library +add_library(fih STATIC + src/fault_injection_hardening.c +) + +target_include_directories(fih + PUBLIC + include +) + +# When used outside MCUboot, callers must provide fih_config.h on the include path +# or in their project. The following demonstrates how to add it: +# +# target_include_directories(your_target PRIVATE path/to/your/fih_config.h) + +# Enable testing (optional) +enable_testing() + +# Add tests if they exist +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt") + add_subdirectory(tests) +endif() diff --git a/boot/fault_injection_hardening/CODE_OF_CONDUCT.md b/boot/fault_injection_hardening/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..39bb346a43 --- /dev/null +++ b/boot/fault_injection_hardening/CODE_OF_CONDUCT.md @@ -0,0 +1,63 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. diff --git a/boot/fault_injection_hardening/CONTRIBUTING.md b/boot/fault_injection_hardening/CONTRIBUTING.md new file mode 100644 index 0000000000..e78b92781f --- /dev/null +++ b/boot/fault_injection_hardening/CONTRIBUTING.md @@ -0,0 +1,75 @@ +# Contributing to the Fault Injection Hardening Library + +Thank you for your interest in contributing to this project! We welcome contributions from the community. + +## How to Contribute + +### Reporting Bugs + +If you find a bug, please open an issue with: +- A clear description of the problem +- Steps to reproduce the issue +- The platform and compiler you're using +- Any relevant error messages or logs + +### Suggesting Enhancements + +For feature requests or improvements: +- Describe the enhancement and its use case +- Explain why it would be useful +- Provide code examples if applicable + +### Code Contributions + +1. **Fork the repository** and create a feature branch: + ```bash + git checkout -b feature/your-feature-name + ``` + +2. **Make your changes** with clear, descriptive commits: + ```bash + git commit -m "Brief description of changes" + ``` + +3. **Follow the code style**: + - Use consistent indentation (spaces or tabs as per project convention) + - Add comments for complex logic + - Keep lines reasonably sized for readability + +4. **Test your changes**: + - Verify compilation with different compilers where possible + - Test on multiple architectures if applicable + - Include tests for new functionality + +5. **Submit a pull request**: + - Provide a clear description of what your PR does + - Reference any related issues + - Ensure your branch is up to date with main + +## Development Setup + +### Building and Testing + +```bash +# Check the README.md for platform-specific build instructions +``` + +### Code Review + +All submissions are subject to review. We appreciate constructive feedback and may request changes to: +- Improve code quality +- Ensure consistency with existing code +- Verify security implications +- Check documentation completeness + +## Code of Conduct + +This project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. + +## License + +By contributing to this project, you agree that your contributions will be licensed under its Apache License 2.0. + +## Questions? + +If you have questions, feel free to open an issue or discussion. We're here to help! diff --git a/boot/fault_injection_hardening/LICENSE b/boot/fault_injection_hardening/LICENSE new file mode 100644 index 0000000000..527aa4a36c --- /dev/null +++ b/boot/fault_injection_hardening/LICENSE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or transformation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, Source or Object + form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work or Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. On the same terms and conditions as + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and any Derivative Works in Source or Object form. + + 3. Grant of Patent License. On the same terms and conditions as + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file, then any + Derivative Works that You distribute must include a readable + copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE from the Work, provided that + such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions of this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contribution. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/boot/fault_injection_hardening/NOTICE b/boot/fault_injection_hardening/NOTICE new file mode 100644 index 0000000000..0452fec16f --- /dev/null +++ b/boot/fault_injection_hardening/NOTICE @@ -0,0 +1,5 @@ +This library was originally developed as part of the MCUboot secure bootloader +project: https://github.com/mcu-tools/mcuboot + +Original design and implementation was developed at +Arm Limited, copyright 2020. diff --git a/boot/fault_injection_hardening/README.md b/boot/fault_injection_hardening/README.md new file mode 100644 index 0000000000..0f61ab351f --- /dev/null +++ b/boot/fault_injection_hardening/README.md @@ -0,0 +1,124 @@ +# Fault Injection Hardening Library + +A portable C library providing mitigations against fault injection attacks on cryptographic operations and other security-critical code. + +## Overview + +This library provides a set of compiler-independent mechanisms to harden code against fault injection attacks, which attempt to cause computational errors through physical manipulation (such as electromagnetic pulses or precision timing attacks). It offers configurable levels of protection: + +- **High Profile** (`FIH_PROFILE_HIGH`): Enables delay randomization, double-variable encoding, global failure loops, and control flow integrity checking +- **Medium Profile** (`FIH_PROFILE_MEDIUM`): Enables double-variable encoding, global failure loops, and control flow integrity checking (no delay randomization) +- **Low Profile** (`FIH_PROFILE_LOW`): Enables global failure loops and control flow integrity checking +- **Off** (`FIH_PROFILE_OFF`): All protections disabled (default if not configured) + +## Features + +### FIH_ENABLE_DOUBLE_VARS +Represents critical variables as tuples `(value, value ^ mask)` to detect bit flips. Provides both basic storage and comparison operations that validate integrity. + +### FIH_ENABLE_GLOBAL_FAIL +Redirects all failure paths to a global, hardened loop resistant to unlooping attacks. More difficult for an attacker to escape than simple inline `while(1)` loops. + +### FIH_ENABLE_CFI (Control Flow Integrity) +Maintains a global counter incremented before and decremented after sensitive function calls. Post-call validation ensures the function was executed and not skipped via glitch attacks. + +### FIH_ENABLE_DELAY +Introduces random delays using an external entropy source (RNG) to make precise fault injection timing much harder. + +## Usage + +Include the main header: + +```c +#include "fault_injection_hardening.h" +``` + +The library expects `fih_config.h` to be available on the include path, which should define one of `FIH_PROFILE_*` macros. For MCUboot, this is provided by [boot/bootutil/include/fih_config.h](../bootutil/include/fih_config.h). + +For non-MCUboot projects, provide your own `fih_config.h`: + +```c +#ifndef __FIH_CONFIG_H__ +#define __FIH_CONFIG_H__ + +/* Define your desired FIH profile */ +#define FIH_PROFILE_HIGH + +#endif +``` + +### Example: Protecting a Function + +```c +#include "fault_injection_hardening.h" + +fih_ret validate_signature(const uint8_t *sig, const uint8_t *key) { + FIH_DECLARE(fih_rc, FIH_FAILURE); + + /* Perform validation */ + int result = crypto_verify(sig, key); + + /* Encode result as FIH value */ + FIH_SET(fih_rc, fih_ret_encode_zero_equality(result)); + + FIH_RET(fih_rc); +} + +int main(void) { + FIH_DECLARE(result, FIH_FAILURE); + + /* Call with FIH protection and validation */ + FIH_CALL(validate_signature, result, sig_data, key_data); + + /* Check result with fault-injection-resistant comparison */ + if (FIH_NOT_EQ(result, FIH_SUCCESS)) { + FIH_PANIC; /* Hardened panic loop */ + } + + return 0; +} +``` + +## Integration + +### With Delay Randomization + +If using `FIH_PROFILE_HIGH`, the library requires an entropy source for random delays. Implement `fih_delay_random_uchar()` to provide random bytes: + +```c +unsigned char fih_delay_random_uchar(void) { + return get_random_byte_from_rng(); +} +``` + +### Return Values + +Use `fih_ret_encode_zero_equality()` to convert standard C return patterns: + +```c +fih_ret my_function(void) { + int result = do_work(); /* 0 = success, non-zero = error */ + FIH_RET(fih_ret_encode_zero_equality(result)); +} +``` + +## Compatibility + +- **C Standard**: C99 and later +- **Compilers**: GCC, Clang, IAR Embedded Workbench, MSVC (with appropriate builtin support) +- **Architecture**: Architecture-independent (portable C) + +## Notes + +- These mitigations are **not guaranteed to be secure** for all compilers, but they increase resilience against fault injection significantly. +- The effectiveness depends on compiler behavior and optimization levels. +- Always pair with hardware-level protections where available. +- Testing and fault injection simulation tools are recommended to verify effectiveness. + +## License + +Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details. + +## References + +The original development of this library was part of the MCUboot secure bootloader project. For more information on MCUboot, visit [mcuboot.com](http://mcuboot.com/). diff --git a/boot/fault_injection_hardening/docs/SECURITY.md b/boot/fault_injection_hardening/docs/SECURITY.md new file mode 100644 index 0000000000..f65dc0bf8b --- /dev/null +++ b/boot/fault_injection_hardening/docs/SECURITY.md @@ -0,0 +1,70 @@ +# Security Policy + +## Reporting Security Vulnerabilities + +The security of the Fault Injection Hardening Library is important to us. If you discover a security vulnerability in this project, please report it responsibly. + +### How to Report + +**Do not open a public issue** for security vulnerabilities. + +Instead, please email your report to the MCUboot security team at: +- **mcuboot-security@arm.com** (primary) +- Or report through the upstream [MCUboot project](https://github.com/mcu-tools/mcuboot/security) + +Include the following information: +- Description of the vulnerability +- Steps to reproduce the issue +- Potential impact +- Any suggested fixes (if you have them) + +### What to Expect + +- We will acknowledge receipt of your report within 48 hours +- We will investigate and determine the severity +- We will work on a fix and coordinate a responsible disclosure +- We will credit you in the security advisory (unless you prefer anonymity) + +## Security Considerations + +When using the FIH library, keep in mind: + +1. **These are mitigations, not guarantees** — FIH hardening significantly increases the difficulty of successful fault injection attacks, but does not guarantee immunity from all attacks. + +2. **Compiler-dependent** — Effectiveness can vary by compiler, optimization level, and platform. Test on your target hardware with your toolchain. + +3. **Combine with hardware defenses** — Use FIH alongside hardware-level protections such as: + - Tamper detection sensors + - Glitch filters + - Power supply monitoring + - Physical shielding (where applicable) + +4. **Profile selection matters** — Choose the appropriate FIH profile based on your security requirements: + - `HIGH`: Maximum protection, highest overhead + - `MEDIUM`: Balanced protection and performance + - `LOW`: Minimal overhead, basic protection + - `OFF`: Disabled (for development/testing only) + +5. **Entropy source quality** — When using `FIH_PROFILE_HIGH`, the quality of random delays depends on your RNG implementation. + +6. **Testing** — Validate effectiveness through fault injection testing tools and hardware testing on your target platform. + +## Responsible Disclosure Timeline + +We follow a responsible disclosure process: + +1. **Private Report** → Immediate acknowledgment (48 hours) +2. **Investigation** → 5-10 business days +3. **Fix Development** → 2-4 weeks (depending on severity) +4. **Coordinated Release** → Public advisory and patch release simultaneously +5. **Credit** → Security advisory acknowledges reporter (with permission) + +## Past Security Issues + +For information about previously discovered and fixed security issues, see the [MCUboot Security Advisories](https://github.com/mcu-tools/mcuboot/security/advisories). + +## Security Resources + +- [OWASP: Fault Injection](https://owasp.org/www-community/attacks/Fault_injection) +- [ARM: Fault Injection Attacks](https://developer.arm.com/) +- [MCUboot Documentation](https://mcuboot.readthedocs.io/) diff --git a/boot/fault_injection_hardening/docs/SubmittingPatches.md b/boot/fault_injection_hardening/docs/SubmittingPatches.md new file mode 100644 index 0000000000..a5e4fc53a2 --- /dev/null +++ b/boot/fault_injection_hardening/docs/SubmittingPatches.md @@ -0,0 +1,259 @@ +# Submitting Patches to the Fault Injection Hardening Library + +This document provides detailed guidelines for submitting patches and pull requests. + +## Before You Start + +1. **Check the Issue Tracker** — Look for related issues or existing PRs +2. **Discuss Major Changes** — Open an issue first to get feedback on significant changes +3. **Understand the Scope** — Familiarize yourself with the FIH library architecture + +## Patch Submission Process + +### Step 1: Fork and Create a Branch + +```bash +git clone https://github.com/your-username/mcuboot.git +cd mcuboot +git checkout -b feature/my-feature +``` + +Branch naming conventions: +- `fix/issue-description` — Bug fixes +- `feature/feature-name` — New features +- `docs/documentation-update` — Documentation only +- `refactor/component-name` — Code refactoring + +### Step 2: Make Your Changes + +#### Code Changes + +- Keep changes focused and atomic +- One logical change per commit +- Write descriptive commit messages (see below) +- Test frequently during development + +#### Commit Messages + +Good commit messages: +``` +component: Brief one-line summary (50 chars max) + +Longer explanation of the change, wrapped at 72 characters. +Explain the problem being solved and why this approach was chosen. + +- Use bullet points for multiple related changes +- Reference issues: Fixes #123 +- Reference related commits if relevant + +Signed-off-by: Your Name +``` + +### Step 3: Test Your Changes + +#### Compilation Testing + +```bash +# Test with different compilers +gcc -Wall -Wextra -std=c99 ... +clang -Wall -Wextra -std=c99 ... + +# Test all FIH profiles +# Compile with: -DFIH_PROFILE_HIGH, -DFIH_PROFILE_MEDIUM, etc. +``` + +#### Functional Testing + +1. **Unit Tests**: Run existing tests + ```bash + cd build && make test + ``` + +2. **Integration Testing**: Verify with MCUboot + - Build MCUboot with your changes + - Run MCUboot test suite + - Test on target hardware if possible + +3. **Profile Testing**: Test with all FIH profiles + - HIGH (all protections) + - MEDIUM (no delay) + - LOW (basic) + - OFF (disabled) + +### Step 4: Format and Style Checks + +Before committing: + +```bash +# Check for style issues +# (project uses existing C89/C99 conventions) + +# Ensure SPDX headers are present +grep -n "SPDX-License-Identifier" your_file.c + +# Check line lengths (aim for <120 chars) +awk 'length > 120 {print NR": "length": "$0}' your_file.c +``` + +### Step 5: Create a Pull Request + +#### PR Title +- Clear, descriptive (50 characters or less) +- Format: `component: Brief description` +- Examples: + - `fih: Fix FIH_EQ comparison for high profile` + - `docs: Add delay RNG integration guide` + - `build: Update CMakeLists.txt for standalone compilation` + +#### PR Description + +```markdown +## Description +Brief explanation of what this PR does. + +## Motivation +Why this change is needed. + +## Testing +- [ ] Compiled with GCC +- [ ] Compiled with Clang +- [ ] Tested with FIH_PROFILE_HIGH +- [ ] Tested with FIH_PROFILE_OFF +- [ ] Existing tests pass +- [ ] Manual testing completed + +## Checklist +- [ ] SPDX license header added/updated +- [ ] Comments added for complex logic +- [ ] No breaking changes to public API +- [ ] Documentation updated if needed +- [ ] Commit messages are clear + +## Related Issues +Fixes #123 +Related to #456 +``` + +## Special Considerations + +### Performance-Critical Changes + +If your change affects performance: +- Include benchmark results (if applicable) +- Explain trade-offs between protection and performance +- Note any overhead introduced +- Consider impact of different FIH profiles + +### Security-Related Changes + +If your change affects security: +- See [SECURITY.md](docs/SECURITY.md) +- Report privately if it's a vulnerability discovery +- Include security review notes in PR + +### Platform-Specific Changes + +If supporting a new platform: +- Clearly document platform assumptions +- Add platform guards where needed +- Include testing notes for that platform +- Don't break existing platforms + +### API Changes + +If you modify the public API: +- Maintain backward compatibility if possible +- Document breaking changes clearly +- Update all affected code samples +- Consider deprecation periods for removals + +## Code Review Process + +### What to Expect + +1. **Initial Review** (1-3 days) + - Automated checks run + - Maintainers review for scope and approach + +2. **Technical Review** (3-7 days) + - Code quality and standards review + - Testing validation + - Security considerations + +3. **Discussion** (as needed) + - Questions about design decisions + - Requests for changes or clarifications + - Suggestions for improvements + +4. **Approval and Merge** + - Once all feedback is addressed + - Tests pass successfully + - PR is approved by maintainers + +### Responding to Feedback + +- **Be respectful** — Code review is about the code, not the person +- **Ask for clarification** — If feedback is unclear, ask questions +- **Provide rationale** — Explain your design decisions +- **Be willing to change** — Sometimes reviewers have good points +- **Respond promptly** — Timely responses keep the review moving + +## Common Patch Types + +### Bug Fixes +- Must reference the issue being fixed +- Include a minimal test case if possible +- Document the root cause in the commit message + +### Feature Additions +- Discuss design in an issue first (if major) +- Include documentation +- Add tests for new functionality +- Update examples if applicable + +### Documentation Improvements +- Clear before/after comparison +- Explain any terminology changes +- Check for consistency with other docs + +### Performance Optimizations +- Include performance measurements +- Explain the optimization approach +- Note any platform dependencies +- Don't sacrifice readability without good reason + +## Signing Off + +All commits should include a "Signed-off-by" line: + +```bash +git commit -s -m "component: Your commit message" +``` + +This confirms you have the right to submit the code and agree to the Apache 2.0 license. + +## Troubleshooting + +### PR is not building +- Check the CI logs for specific errors +- Run local tests matching the CI environment +- Ensure all dependencies are available + +### Feedback is overwhelming +- Break the PR into smaller changes +- Ask reviewers to prioritize feedback +- Focus on addressing critical issues first + +### Disagreement with feedback +- Discuss respectfully +- Provide technical rationale +- Ask for clarification if needed +- Escalate to maintainers if necessary + +## Questions? + +- Check the [Contributing Guide](contributing.md) +- Review existing PRs and issues for examples +- Ask in a new issue for clarification + +Thank you for contributing! diff --git a/boot/fault_injection_hardening/docs/contributing.md b/boot/fault_injection_hardening/docs/contributing.md new file mode 100644 index 0000000000..efdd60d682 --- /dev/null +++ b/boot/fault_injection_hardening/docs/contributing.md @@ -0,0 +1,158 @@ +# Contributing to the Fault Injection Hardening Library + +Thank you for your interest in contributing! We welcome contributions including: +- Bug reports and fixes +- Feature enhancements +- Documentation improvements +- Platform ports and optimizations +- Testing and validation + +## Getting Started + +1. **Check existing issues** — Before starting work, check if your issue/feature is already being discussed +2. **Discuss major changes** — For significant changes, open an issue first to get feedback +3. **Fork and branch** — Create a feature branch for your work + +## Development Setup + +### Prerequisites + +- C99 compatible compiler (GCC, Clang, IAR, MSVC) +- CMake 3.12+ (for standalone builds) +- Git + +### Building + +```bash +mkdir build +cd build +cmake .. +make +``` + +## Coding Standards + +### Style Guidelines + +- **Indentation**: Use the existing style (typically 4 spaces or tabs) +- **Comments**: Add comments for non-obvious logic, especially in fault-hardened code +- **Naming**: Use clear, descriptive names for variables and functions +- **Line length**: Keep lines under 120 characters where practical +- **SPDX Headers**: Include SPDX license identifier in all source files + +Example file header: +```c +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2026 Your Organization + * + * Description of what this file does. + */ +``` + +### Compiler Support + +Code should compile cleanly with: +- GCC (versions 7+) +- Clang (versions 5+) +- IAR Embedded Workbench +- MSVC (with appropriate platform support) + +Avoid compiler-specific extensions unless necessary, and guard them appropriately. + +## Testing + +### Before Submitting + +Test your changes with: + +1. **Multiple Compilers**: At minimum GCC and Clang +2. **All Profiles**: Test with all FIH profiles (HIGH, MEDIUM, LOW, OFF) +3. **Existing Tests**: Ensure no regressions in existing tests + +### Adding Tests + +- Unit tests go in a `tests/` subdirectory (following the CMakeLists.txt hook) +- Include test documentation explaining: + - What is being tested + - Why the test is needed + - How to run the test + +## Submitting Changes + +### Pull Request Process + +1. **Create a descriptive PR**: + - Clear title describing the change + - Detailed description of what and why + - Link to related issues + +2. **Commit messages** should be clear: + ``` + component: Brief description + + Longer explanation if needed. Reference issues with #123. + ``` + +3. **Documentation**: + - Update README or docs if adding features + - Add copyright headers to new files + - Include license and attribution as appropriate + +4. **Code review**: + - Be responsive to feedback + - Discuss disagreements respectfully + - Make requested changes promptly + +### Expectations + +All contributions must: +- [ ] Pass compilation checks +- [ ] Include appropriate comments/documentation +- [ ] Not break existing functionality +- [ ] Follow the project's code style +- [ ] Include SPDX license headers +- [ ] Be under Apache License 2.0 + +## Reporting Issues + +### Bug Reports + +Include: +- Clear title and description +- Steps to reproduce +- Expected vs. actual behavior +- Compiler and platform information +- Relevant code or configuration + +### Feature Requests + +Include: +- Use case and motivation +- Proposed design (if applicable) +- Potential impact on existing code +- Suggested implementation (optional) + +## License + +By contributing to this project, you agree that your contributions will be licensed under the Apache License 2.0. + +## Code of Conduct + +Participants are expected to uphold the [Contributor Covenant Code of Conduct](../CODE_OF_CONDUCT.md). + +## Questions? + +- Open an issue for public questions +- For security concerns, see [SECURITY.md](SECURITY.md) +- Contact the MCUboot community for general questions + +## Recognition + +Contributors are recognized in: +- Commit history +- Release notes for substantial contributions +- Project documentation (if applicable) + +Thank you for making FIH better! diff --git a/boot/fault_injection_hardening/docs/index.md b/boot/fault_injection_hardening/docs/index.md new file mode 100644 index 0000000000..0571501812 --- /dev/null +++ b/boot/fault_injection_hardening/docs/index.md @@ -0,0 +1,46 @@ +# Fault Injection Hardening Library Documentation + +Welcome to the Fault Injection Hardening (FIH) Library documentation. + +## Quick Start + +- **[README](../README.md)** — Overview, features, and basic usage examples +- **[Security Policy](SECURITY.md)** — How to report security vulnerabilities +- **[Contributing](contributing.md)** — How to contribute to the project +- **[Submitting Patches](SubmittingPatches.md)** — Guidelines for submitting code changes + +## Features + +The FIH library provides four configurable profiles for protecting code against fault injection attacks: + +- **HIGH**: Full protections (delay, double-vars, global fail, CFI) +- **MEDIUM**: Double-vars, global fail, CFI (no delay) +- **LOW**: Global fail and CFI only +- **OFF**: No protections + +## Integration + +The library is designed to be: +- **Standalone**: Can be used independently outside MCUboot +- **Configurable**: Profiles can be set via `fih_config.h` +- **Portable**: Architecture and compiler independent + +## Building + +See the top-level [CMakeLists.txt](../CMakeLists.txt) for standalone compilation. + +When integrated into MCUboot, FIH is built as part of the bootutil library. + +## Testing + +The library is validated through: +- **Integration Tests**: Part of MCUboot's CI with fault injection simulation +- **Multi-compiler Testing**: Verified with GCC, Clang, IAR, and other compilers +- **Multiple Platforms**: Tested across various ARM and other architectures + +See [SubmittingPatches](SubmittingPatches.md#testing) for testing requirements. + +## More Information + +- [MCUboot Project](https://github.com/mcu-tools/mcuboot) +- [Original Design and Development](../README.md#references) diff --git a/boot/bootutil/include/bootutil/fault_injection_hardening.h b/boot/fault_injection_hardening/include/fault_injection_hardening.h similarity index 95% rename from boot/bootutil/include/bootutil/fault_injection_hardening.h rename to boot/fault_injection_hardening/include/fault_injection_hardening.h index 1106e977b0..bb2d5ad5ca 100644 --- a/boot/bootutil/include/bootutil/fault_injection_hardening.h +++ b/boot/fault_injection_hardening/include/fault_injection_hardening.h @@ -10,7 +10,7 @@ /* Fault injection mitigation library. * * Has support for different measures, which can either be enabled/disabled - * separately or by defining one of the MCUBOOT_FIH_PROFILEs. + * separately or by defining one of the FIH_PROFILEs. * * NOTE: These constructs against fault injection attacks are not guaranteed to * be secure for all compilers, but execution is going to be correct and @@ -54,29 +54,33 @@ * fail causing a panic. */ -#include "mcuboot_config/mcuboot_config.h" +#include "fih_config.h" -#if defined(MCUBOOT_FIH_PROFILE_HIGH) +#if defined(FIH_PROFILE_HIGH) #define FIH_ENABLE_DELAY /* Requires an entropy source */ #define FIH_ENABLE_DOUBLE_VARS #define FIH_ENABLE_GLOBAL_FAIL #define FIH_ENABLE_CFI -#elif defined(MCUBOOT_FIH_PROFILE_MEDIUM) +#elif defined(FIH_PROFILE_MEDIUM) #define FIH_ENABLE_DOUBLE_VARS #define FIH_ENABLE_GLOBAL_FAIL #define FIH_ENABLE_CFI -#elif defined(MCUBOOT_FIH_PROFILE_LOW) +#elif defined(FIH_PROFILE_LOW) #define FIH_ENABLE_GLOBAL_FAIL #define FIH_ENABLE_CFI -#elif !defined(MCUBOOT_FIH_PROFILE_OFF) -#define MCUBOOT_FIH_PROFILE_OFF -#endif /* MCUBOOT_FIH_PROFILE */ +#elif defined(FIH_PROFILE_OFF) +/* No FIH features enabled */ + +#else +#error "None of FIH_PROFILE_HIGH, FIH_PROFILE_MEDIUM, FIH_PROFILE_LOW or " \ + "FIH_PROFILE_OFF is defined in fih_config.h." +#endif /* FIH_PROFILE */ #ifdef FIH_ENABLE_DELAY #include "fault_injection_hardening_delay_rng.h" @@ -90,17 +94,17 @@ extern "C" { /* Non-zero success value to defend against register resets. Zero is the most * common value for a corrupted register so complex bit-patterns are used */ -#ifndef MCUBOOT_FIH_PROFILE_OFF +#ifndef FIH_PROFILE_OFF #define FIH_POSITIVE_VALUE 0x1AAAAAAA #define FIH_NEGATIVE_VALUE 0x15555555 #define FIH_CONST1 0x1FCDEA88 #define FIH_CONST2 0x19C1F6E1 -#else +#else /* FIH_PROFILE_OFF */ #define FIH_POSITIVE_VALUE 0 #define FIH_NEGATIVE_VALUE -1 #define FIH_CONST1 1 #define FIH_CONST2 1 -#endif +#endif /* FIH_PROFILE_OFF */ /* A volatile mask is used to prevent compiler optimization - the mask is xored * with the variable to create the backup and the integrity can be checked with diff --git a/boot/bootutil/include/bootutil/fault_injection_hardening_delay_rng.h b/boot/fault_injection_hardening/include/fault_injection_hardening_delay_rng.h similarity index 100% rename from boot/bootutil/include/bootutil/fault_injection_hardening_delay_rng.h rename to boot/fault_injection_hardening/include/fault_injection_hardening_delay_rng.h diff --git a/boot/bootutil/src/fault_injection_hardening.c b/boot/fault_injection_hardening/src/fault_injection_hardening.c similarity index 98% rename from boot/bootutil/src/fault_injection_hardening.c rename to boot/fault_injection_hardening/src/fault_injection_hardening.c index fbe75e87ee..3d38c1a851 100644 --- a/boot/bootutil/src/fault_injection_hardening.c +++ b/boot/fault_injection_hardening/src/fault_injection_hardening.c @@ -4,7 +4,7 @@ * Copyright (c) 2020 Arm Limited */ -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #ifdef FIH_ENABLE_DOUBLE_VARS /* Variable that could be (but isn't) changed at runtime to force the compiler diff --git a/boot/mynewt/src/main.c b/boot/mynewt/src/main.c index 9c92c019ba..578a3208db 100644 --- a/boot/mynewt/src/main.c +++ b/boot/mynewt/src/main.c @@ -45,7 +45,7 @@ #include "bootutil/image.h" #include "bootutil/bootutil.h" #include "bootutil/bootutil_log.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #if MYNEWT_VAL(BOOT_CUSTOM_START) void boot_custom_start(uintptr_t flash_base, struct boot_rsp *rsp); diff --git a/boot/mynewt/src/single_loader.c b/boot/mynewt/src/single_loader.c index 394fc372ac..8019b03444 100644 --- a/boot/mynewt/src/single_loader.c +++ b/boot/mynewt/src/single_loader.c @@ -10,7 +10,7 @@ #include "../../../bootutil/src/bootutil_priv.h" #include "bootutil/bootutil_log.h" #include "bootutil/bootutil_public.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "mcuboot_config/mcuboot_config.h" diff --git a/boot/zephyr/CMakeLists.txt b/boot/zephyr/CMakeLists.txt index df5e607e52..f56ab189cf 100644 --- a/boot/zephyr/CMakeLists.txt +++ b/boot/zephyr/CMakeLists.txt @@ -91,6 +91,7 @@ endif() # Generic bootutil sources and includes. zephyr_include_directories(${BOOT_DIR}/bootutil/include) +zephyr_include_directories(${BOOT_DIR}/fault_injection_hardening/include) zephyr_sources( ${BOOT_DIR}/bootutil/src/image_validate.c ${BOOT_DIR}/bootutil/src/bootutil_find_key.c @@ -104,7 +105,7 @@ zephyr_sources( ${BOOT_DIR}/bootutil/src/bootutil_misc.c ${BOOT_DIR}/bootutil/src/bootutil_area.c ${BOOT_DIR}/bootutil/src/bootutil_loader.c - ${BOOT_DIR}/bootutil/src/fault_injection_hardening.c + ${BOOT_DIR}/fault_injection_hardening/src/fault_injection_hardening.c ) if((CONFIG_BOOT_ENCRYPT_X25519 AND CONFIG_BOOT_ED25519_PSA) diff --git a/boot/zephyr/arch/arc.c b/boot/zephyr/arch/arc.c index 78a5511905..0fcded8f54 100644 --- a/boot/zephyr/arch/arc.c +++ b/boot/zephyr/arch/arc.c @@ -13,7 +13,7 @@ #include "bootutil/bootutil_log.h" #include "bootutil/bootutil.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "flash_map_backend/flash_map_backend.h" #include "do_boot.h" diff --git a/boot/zephyr/arch/arm.c b/boot/zephyr/arch/arm.c index 63c4e4e9d7..be9e76e5f6 100644 --- a/boot/zephyr/arch/arm.c +++ b/boot/zephyr/arch/arm.c @@ -26,7 +26,7 @@ #include "bootutil/bootutil_log.h" #include "bootutil/bootutil.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "flash_map_backend/flash_map_backend.h" #include "do_boot.h" diff --git a/boot/zephyr/arch/default.c b/boot/zephyr/arch/default.c index 1ff9dcac05..db6fa402e3 100644 --- a/boot/zephyr/arch/default.c +++ b/boot/zephyr/arch/default.c @@ -13,7 +13,7 @@ #include "bootutil/bootutil_log.h" #include "bootutil/bootutil.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "flash_map_backend/flash_map_backend.h" #include "do_boot.h" diff --git a/boot/zephyr/firmware_loader.c b/boot/zephyr/firmware_loader.c index 2e8eb1696d..a07d1acb3c 100644 --- a/boot/zephyr/firmware_loader.c +++ b/boot/zephyr/firmware_loader.c @@ -13,7 +13,7 @@ #include "bootutil_priv.h" #include "bootutil/bootutil_log.h" #include "bootutil/bootutil_public.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "io/io.h" #include "mcuboot_config/mcuboot_config.h" diff --git a/boot/zephyr/hooks_sample.c b/boot/zephyr/hooks_sample.c index 42639965ed..462f637119 100644 --- a/boot/zephyr/hooks_sample.c +++ b/boot/zephyr/hooks_sample.c @@ -18,7 +18,7 @@ #include #include "bootutil/image.h" #include "bootutil/bootutil.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "flash_map_backend/flash_map_backend.h" /* @retval 0: header was read/populated diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c index 3f3506ffbc..0c3f235e2a 100644 --- a/boot/zephyr/main.c +++ b/boot/zephyr/main.c @@ -33,7 +33,7 @@ #include "bootutil/image.h" #include "bootutil/bootutil.h" #include "bootutil/boot_hooks.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "bootutil/mcuboot_status.h" #include "do_boot.h" diff --git a/boot/zephyr/single_loader.c b/boot/zephyr/single_loader.c index 801313aef8..d18d85e3ac 100644 --- a/boot/zephyr/single_loader.c +++ b/boot/zephyr/single_loader.c @@ -12,7 +12,7 @@ #include "bootutil/bootutil.h" #include "bootutil/bootutil_log.h" #include "bootutil/bootutil_public.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #include "mcuboot_config/mcuboot_config.h" diff --git a/docs/release-notes.d/fault_injection_hardening.md b/docs/release-notes.d/fault_injection_hardening.md new file mode 100644 index 0000000000..c95302df8c --- /dev/null +++ b/docs/release-notes.d/fault_injection_hardening.md @@ -0,0 +1 @@ +- Moved the fault injection hardening code to its own directory. diff --git a/samples/runtime-source/zephyr/hooks/hooks.c b/samples/runtime-source/zephyr/hooks/hooks.c index 065474e193..542b145e47 100644 --- a/samples/runtime-source/zephyr/hooks/hooks.c +++ b/samples/runtime-source/zephyr/hooks/hooks.c @@ -10,7 +10,7 @@ #include "bootutil/bootutil.h" #include "bootutil/bootutil_public.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" #define BOOT_TMPBUF_SZ 256 diff --git a/sim/mcuboot-sys/build.rs b/sim/mcuboot-sys/build.rs index cb7d449ca3..1770e3c83d 100644 --- a/sim/mcuboot-sys/build.rs +++ b/sim/mcuboot-sys/build.rs @@ -621,9 +621,10 @@ fn main() { conf.file("../../boot/bootutil/src/bootutil_loader.c"); conf.file("../../boot/bootutil/src/bootutil_public.c"); conf.file("../../boot/bootutil/src/tlv.c"); - conf.file("../../boot/bootutil/src/fault_injection_hardening.c"); + conf.file("../../boot/fault_injection_hardening/src/fault_injection_hardening.c"); conf.file("csupport/run.c"); conf.conf.include("../../boot/bootutil/include"); + conf.conf.include("../../boot/fault_injection_hardening/include"); conf.conf.include("csupport"); conf.conf.debug(true); conf.conf.flag("-Wall"); diff --git a/sim/mcuboot-sys/csupport/security_cnt.c b/sim/mcuboot-sys/csupport/security_cnt.c index 0f79d8d41c..c777e08e7d 100644 --- a/sim/mcuboot-sys/csupport/security_cnt.c +++ b/sim/mcuboot-sys/csupport/security_cnt.c @@ -6,7 +6,7 @@ #include "bootutil/security_cnt.h" #include "mcuboot_config/mcuboot_logging.h" -#include "bootutil/fault_injection_hardening.h" +#include "fault_injection_hardening.h" /* * Since the simulator is executing unit tests in parallel,