Commit Graph

144 Commits

Author SHA1 Message Date
Tomi Fontanilles d4394c2f9b mbedtls config: fix too early check_config.h includes
check_config.h was included manually by custom configuration files.
This caused compilation errors when updating MbedTLS to 3.6.0
because check_config.h was processed too early, before the whole
configuration is defined, effectively causing configuration check errors.

MbedTLS already takes care of including check_config.h at the right time.
Remove those erroneous manual check_config.h includes.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-04-25 11:05:54 +02:00
Roland Mikhel 5899face4d sim: PSA Crypto ECDSA enablement
This commit enables ECDSA signature verification using
PSA Crypto API.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I33f559ecdd59b1ce41c6a2d5f315212300d585e3
2023-09-12 16:29:11 +02:00
Matthew Dalzell 34d5a6915f Tests: Enable psa-crypto-api feature
This patch enables psa-crypto-api feature

Signed-off-by: Matthew Dalzell <matthew.dalzell@arm.com>
Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2023-06-28 15:24:06 +02:00
Antonio de Angelis 65eb35c2c7 sim: Initialize PSA Crypto subsystem based on psa-crypto-api feature
If the psa-crypto-api feature is defined, the simulator will
initialize the PSA Crypto API exactly once. It needs also to
enable the test external RNG as the assumption is that the
PSA subsystem is configured to use MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG

Signed-off-by: David Brown <david.brown@linaro.org>
Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Signed-off-by: Matthew Dalzell <matthew.dalzell@arm.com>
Change-Id: Id02727b8673867ecf1e4fbbdfa3c4b6d6f98f8df
2023-06-28 15:24:06 +02:00
Roland Mikhel d6703520d1 sim: Add hw-rollback-protection feature
This commit adds simulator support to test the
hw-rollback-protection feature which is using
nv-counters. In the simulator they are stored in Rust
to prevent any race conditions from happening due to
the parallel execution of the tests.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I445fc50615ed1f0c06e5933b16811c24d9d302fc
2023-06-27 14:42:34 +02:00
Antonio de Angelis 02bf072d2d bootutil/crypto: Refactor the RSA signature verification and encryption
This patch refactor the RSA operations done by the signature verification
module and by the encrypted images decryption module. Previous solution is
tightly coupled with Mbed TLS, while this patch provides an abstraction of
the RSA functionalities in a dedicated crypto abstraction header, crypto/rsa.h
that supports both Mbed TLS APIs and PSA Crypto APIs. In case of PSA Crypto,
the verification scheme is directly provided by the crypto backend hence it
simplifies the operations done in the image verification module.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: I973bc3374b62eee2d7717c2368bce7611d37a0c8
2023-06-09 14:35:28 +02:00
Antonio de Angelis 10529d3032 bootutil/crypto: Have a single ECDSA verification module
Remove the generic ECDSA verification module and keep the
existing one, just renaming it image_ecdsa.c. Make sure
that the abstraction layer is generically called ecdsa.h
and the abstraction names are not P256 specific.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
Change-Id: I6f78cfc1b1c2851cdad67efa91c6cb49498187bb
2023-04-26 13:57:53 +02:00
Dominik Ermel b1d4e00186 sim: Add flash_area_get_sector
Commits adds implementation of flash_area_get_sector that
is supposed to replace flash_area_sector_from_off.
The flash_area_get_sector gets additional parameter of flash_area
type, while flash_area_sector_from_off uses hardcoded flash_area.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-03-14 08:13:20 -06:00
Dominik Ermel 453e8bd7de flash_map_backend: Remove flash_area_id_to_image_slot
The function has not been in use and some ports have not been
implementing it anyway.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2023-02-14 16:40:21 -07:00
Andrzej Puzdrowski 453b0dd790 sim: added flash_area_sector_from_off() API implementation
Added implementation of the above API function.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-06-14 11:25:02 +02:00
Andrzej Puzdrowski cc547a76da sim/mcuboot-sys: provide sim-own porting files
The sim platform was sharing a few header
files with the zephyr-rtos port. This patch provides
sim own headers.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-06-14 11:25:02 +02:00
Andrzej Puzdrowski a914048bee sim/mcuboot-sys: mbedtls configuations
copied configurations form the zephyr port

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-06-14 11:25:02 +02:00
David Brown 42a7e545bf sim: Migrate to Rust 2021 edition
Change the edition in the various Cargo.toml to 2021.  There are no
changes to the code needed for this.  This will require Rust 1.56 in
order to build.

Signed-off-by: David Brown <david.brown@linaro.org>
2022-04-12 08:11:57 +02:00
David Brown 1bc106e44c sim: Homogenize max-align-32 feature check
This feature check was done statically instead of dynamically in the
build.rs file.  Change this to match the rest.  Perhaps we might want to
change all of them to be done at compile time, but that should be done
with all of the features.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-12-17 08:54:09 -03:00
Gustavo Henrique Nihei 7bfd14bbc5 sim: Fit unit tests to larger write align values
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-12-16 13:19:12 -07:00
Gustavo Henrique Nihei 4aa286d2db flash_map: Increase minimum supported write align via flash_area_align
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-12-16 13:19:12 -07:00
David Brown c8d62018b9 sim: Update Linaro copyrights
Update to current year for files modified.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
David Brown 7e0d3b427a sim: Remove profile config from mcuboot-sys
Having profile configuration in sub crates generates a warning every
time Cargo is run.  Remove these lines, as the top-level Cargo.toml file
defines these values.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-11-15 10:38:24 -07:00
Raef Coles 3fd3ecca7a sim: add tests for partial ram-loading
Signed-off-by: Raef Coles <raef.coles@arm.com>
2021-11-05 09:38:10 -06:00
Raef Coles f11de6494c boot: enable partial multi-image booting
Signed-off-by: Raef Coles <raef.coles@arm.com>
2021-11-05 09:38:10 -06:00
David Brown 5f4e1484b7 sim: mcuboot-sys: Avoid duplicate C files
When building mcuboot-sys, the build script currently adds some
duplicate files.  When used as a library, this works, because the code
is linked in as a library.  However, when mcuboot-sys is tested itself,
all specified files will be brought in, which results in duplicate
symbols for these files.

Fix this by keeping track of all of the files that we've added, and
making sure to add each file once.  Additionally, instead of using the
orphaned files in mbedtls-asn1, just always use the verions in the main
mbedtls library.  There are some configurations of the code that end up
using both the extracted files and the full mbed TLS.  Avoid that
conflict by just always using the full tree.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-09-27 15:22:09 -06:00
David Brown 115ce57de7 sim: Allow 'large-write' in mcuboot-sys
When collected together as a workspace, the test framework ends up
running all of the configurations on each project.  One configuration
option `large-write` doesn't really mean anything to mcuboot-sys, but
adding support for the feature allows this package to be tested along
with all of the other packages.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-09-27 15:22:09 -06:00
David Brown f17d39112f sim: Test ram-loading with DIRECT_XIP
Combine all of the pieces to be able to test ram loading with multiple
images.  We construct a model `RamData` that indicates where each image
should be loaded into RAM.  This has to be made early enough to compute
signatures on the images, and then used later to verify that the images
were loaded properly.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 8a4e23bb6b sim: Basic ram-load test
Test the basic configuration for ram loading.  Instead of a fixed
address for RAM, the values come dynamically from a thread-local
variable (allowing the tests to run in parallel).  The size of the ram
along with the address of the buffer in the test address space are
passed in this way.

This tests the single-image configurations of ram loading.  Testing
multi-image will take additional work, as the RAM will need to be large
enough for both images, and the second image will need a meaningful
offset address in RAM.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 11ffa0a56b sim: Support direct-xip configuration
Add simulator support for building the direct-xip configuration.
Although this builds, there are no tests that test any of the
functionality, so all current tests trivially pass.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 7e377ab17b sim: Enable sim building with ram-load
Allow the sim to test configurations with MCUBOOT_RAM_LOAD defined.
This does not define any tests for this mode.

This adds definitions for simulated RAM offsets to the simulator.  This
will define the offset (from `IMAGE_RAM_BASE`) to where the simulated
RAM will be located.  For now, just give these somewhat reasonable
values so that we are able to at least compile the RAM_LOADING code in
the simulator.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 4b82c671cf sim: Implement function in sim
The function `flash_area_id_from_image_slot` is used in the RAM_LOAD and
DIRECT_XIP configurations.  Define a version for use in the simulator.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown d82de8c7de sim: Allow access to the boot response
When the bootloader completes, it fills a response structure with
various information.  Move this into the BootGoResult and provide an
accessor for it.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown 6d47d42eb6 sim: Make BootGoResult into an enum
Now that this result is abstracted, take the special case for a sim stop
and make it its own field.  This hides the magic number we use to
indicate this to be entirely within mcuboot-sys.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown c423ac4517 sim: Return abstract value from boot_go
Instead of a tuple of values that is matched, return an abstract type
that has methods for querying the information we need.  Abstracting this
will allow us to return additional information without having to change
all of the code that matches against these patterns.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown d216b20883 sim: Pass boot_rsp down from the simulator
Instead of having this struct at a fairly low level in the simulator,
with the filled-in values effectively discarded after each call, pass
the value from higher up in the simulator.  This prepares us for being
able to use the resulting data in upcoming tests.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
David Brown f1ae694fa1 sim: Fix flash_area_get_device_id in sim
commit c304a7f84a
(refs/bisect/good-c304a7f84a7e7e345457e23b179fa302b8732fb9)
Author: Dominik Ermel <dominik.ermel@nordicsemi.no>
Date:   Mon Jun 14 16:08:42 2021 +0000

    sim: Add flash_area_get_device_id implementation

Adds an implementation for this function in the simulator that just
returns 0.  Fix this to return the proper ID so that when tests start
checking for this, it will return the right value.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-07-19 11:22:13 -06:00
Sherry Zhang f4580cb672 Update mbedtls to mbedtls-3.0.0
Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: If406625c09949cca7575d234807e49c00cbc2fa7
2021-07-16 09:42:57 +02:00
Dominik Ermel c304a7f84a sim: Add flash_area_get_device_id implementation
With switch to getter functions the implementation of the function
is now required.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-07-06 14:42:53 -06:00
Salome Thirot 6fdbf55756 Sim: Add testcases for AES256 image encryption
Signed-off-by: Salome Thirot <salome.thirot@arm.com>
2021-05-18 07:25:12 -03:00
Andrzej Puzdrowski 137d797177 sim: emits *_SWAP_USING_SCRATCH macros
Emits either MCUBOOT_SWAP_USING_SCRATCH and
CONFIG_BOOT_SWAP_USING_SCRATCH when swap using scratch
algorithm is expected.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-05-14 14:19:56 +02:00
Fabio Utzig 6c553d6741 sim: add Mbed TLS EC256 encrypted image support
Add new feature that allows testing EC256 encrypted images using the
Mbed TLS backend.

Move config-ecdsa.h to config-ec.h because definitions are very similar
between ECDSA and ECDH with Mbed TLS so resort to a single config file.

Add new feature and fix the build; add proper Mbed TLS memory
initialization when enc-ec256-mbedtls is used.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2021-05-06 21:05:47 -03:00
David Brown c20bbb22e3 sim: Remove useless `return`s
Apply clippy suggestions to directly result in values instead of
returning those values at the end of a function.  Better matches common
Rust style.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 8608c53f6e sim: Clarify condition
Clippy suggests using an if instead of using a map on an option.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 4bbb93d9ce sim: Clarify condition with is_empty()
Clippy suggests `.is_empty()` over `.len() == 0`.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 7cc4526db6 sim: unsafe cleanup
Cleanup some of the unsafe usage in mcuboot-sys.  In one case, add a
safety comment to the function documentation.  In the other, move the
unsafe to a narrower scope, reducing the number of instances of unsafe
needed.  From clippy suggestions.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown fc8e3c5b69 sim: Implement Default for a few types
Clippy suggests implementing Default when the `new` function for that
type just initializes the type to default values.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 50b5a12c31 sim: Remove pointless use lines
Top-level crates are available by name.  A use of these names is
redundant, so remove these.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 1997f539f7 sim: Remove extraneous static
According to clippy, `&'static` can just be `&` for static definitions,
which always have a static lifetime.  Clean this up in the arrays in the
code, as well as generation code in imgtool.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-03-11 07:25:43 -07:00
David Brown 641af4530c boot: Support Mbed TLS ECDSA for signatures
Add Mbed TLS ECDSA signature verification as an option (in addition to
Tinycrypt and the CC310 hardware version).  Although the Mbed TLS ECDSA
verification code is both larger and slower, this will still save space
if there is another reason that the Mbed TLS code is already being
brought in for another reason (such as certificate management, for
example).

Mbed TLS's ECDSA verification works at a different level than the other
two libraries, so this takes a bit of reworking.  There are some
additional parameters passed to the various functions, and a new define
MCUBOOT_ECDSA_NEED_ASN1_SIG to indicate that the ecdsa verification
wants the original ASN1 signature, not a decoded key.

This adds the boot changes and simulator support to test this configuration.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-23 10:29:31 -07:00
Andrzej Puzdrowski f573b392ec bootutil: extracted app common library from bootutil_misc
Part of code of boot/bootutil/ is re-implemented in zephyr-rtos
repository.
As some code are defined here and there it becomes problem when
need to include it with outstanding feature in a build.
It is possible to mitigate problem using #fdefry - but this was
rather temporary hack.

This patch introduce new module which is common for MCUBoot build
and application build.
Common code were extracted to bootutil_public.c source file and
bootutil_public.h header

MCUboot also select DISABLE_MCUBOOT_BOOTUTIL_LIB_OWN_LOG Kconfig
option, as it must define log configuration on its own for all its
sourcecode.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-01-13 17:49:49 +01:00
Fabio Utzig 4b2e55f362 boot: bootutil: drop flash_area_read_is_empty
Removes the current `flash_area_read_is_empty` which lacked a bit of
clarity in its naming and error handling, as well as requiring an
extra API in the flash map, and switches to using an internal function
`bootutil_buffer_is_erased`.

Code that was previously using `flash_area_read_is_empty` must now be
updated to do a `flash_area_read` followed by a call to
`bootutil_buffer_is_erased` with the read buffer.

The proposal was previously discussed here:

https://github.com/zephyrproject-rtos/zephyr/pull/28519

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-10-08 20:47:56 -03:00
Fabio Utzig 3c9d5c45ab sim: change MCUBOOT_OVERWRITE_ONLY_FAST usage
Remove `MCUBOOT_OVERWRITE_ONLY_FAST` from overwrite-only upgrades, to
make it compatible with `large-write` tests after the latest changes
to the fast overwrite code; make it default when bootstrapping.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-10-05 17:11:14 -03:00
Fabio Utzig 1edb788695 sim: update alignment (aka write_sz) to u16
The simulated alignment functions were returning u8 which would be
invalid for any alignment beyond 128; as a first step in the direction
of allowing larger alignments, make them u16 which should allow for up
to 2**15 aligment size.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-10-05 17:11:14 -03:00
Raef Coles e8fe6cf259 boot: Harden critical path against fault attacks
Add fault attack mitigation measures to code vital for the correct
validation of images.

Change-Id: If6eb1110a8c2966faf105d07ad2e95482a80a8d9
Signed-off-by: Raef Coles <raef.coles@arm.com>
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
2020-10-02 07:31:11 -03:00