Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] Upmerge 20231208 #290

Closed
wants to merge 114 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
e188dbb
zephyr: Fix boot serial extensions
nordicjm Aug 29, 2023
0d2772c
Add Espressif build status badge
utzig Aug 9, 2023
b58962f
docs: espressif: fix formatting of markdown
utzig Sep 2, 2023
54fd52d
docs: update github-pages and deps versions
utzig Sep 4, 2023
b688ef7
docs: add jemoji plugin
utzig Sep 4, 2023
f0ad026
docs: add webrick dependency
utzig Sep 4, 2023
9bf7ce8
zephyr: Fix build for non-arm archs
LucasTambor Sep 5, 2023
0035c33
zephyr: Provide third image cases for direct image upload
de-nordic Sep 4, 2023
3790f5f
boot: zephyr: use indication LED also in timeout based recovery
pepe2k Dec 15, 2022
480b97f
boot_serial: Fix missing point if using snprintf
biglben Sep 7, 2023
b847a33
espressif: use minimal libc as default for ESP32 boards
sylvioalves Sep 8, 2023
5c5222f
boot_serial: Fix include
nordicjm Sep 12, 2023
8f8fbf9
zephyr: Fall back to minimal C library
nordicjm Sep 12, 2023
274547c
bootutil: PSA Crypto ECDSA enablement
Mar 7, 2023
5899fac
sim: PSA Crypto ECDSA enablement
Mar 14, 2023
03c9ad0
bootutil: Replace hash with SHA384 when P384 is used
Mar 8, 2023
fb5507b
sim: Replace hash with SHA384 when P384 is used
Mar 14, 2023
5c00da4
ci: Add test cases for ECDSA using PSA Crypto
Jun 12, 2023
6ba46c0
boot_serial: Fix issue with queued commands
nordicjm Sep 15, 2023
5f30562
docs: release: Add note on boot_serial duplicate command fix
nordicjm Sep 15, 2023
c7aa2c0
boot_serial: Fix issues with single slot mode/encrypted images
nordicjm Sep 13, 2023
736234c
docs: release: Add note on bs image list fixes
nordicjm Sep 13, 2023
db2024e
espressif: update secure boot and flash encryption
almir-okato Aug 24, 2023
9bef51c
bootutil/crypto: Do not include import key with PSA
Sep 25, 2023
4da5101
zephyr: Add shared data support
nordicjm Aug 3, 2023
6c8c76f
docs: Add note on addition of zephyr retention shared boot info
nordicjm Aug 3, 2023
8d0b35a
bootutil: Add mode for XIP with revert
nordicjm Sep 27, 2023
50f8b5f
bootutil: Add shared data support for XIP with revert mode
nordicjm Sep 27, 2023
268433e
zephyr: Allow user-defined boot serial extensions
nordicjm Aug 29, 2023
ae2aeed
docs: release: Add note on boot serial extension rework
nordicjm Aug 29, 2023
2929a97
bootutil: Show error if flash area open fails
nordicjm Sep 25, 2023
bf8cf46
docs: release: Add note on panicking if flash device open fails
nordicjm Sep 25, 2023
62e2b4d
docs: Update release notes for 2.0.0-rc1
d3zd3z Sep 28, 2023
6a6de4b
scripts: imgtool: update to 2.0.0-rc1 release
d3zd3z Sep 28, 2023
4fe28b3
Update zephyr version files for 2.0.0-rc1
d3zd3z Sep 28, 2023
13767d0
bootutil: Disable MCUBOOT_BOOT_MAX_ALIGN assert for non-swap modes
butok Oct 4, 2023
9b92ee9
boot: zephyr: add support for LPC55Sxx
butok Oct 5, 2023
d3819c9
espressif: allow the use of a different toolchain for building
almir-okato Oct 4, 2023
e0bdcde
Update version files for 2.0.0
d3zd3z Oct 18, 2023
304fd41
mynewt: update to release 2.0.0
utzig Oct 22, 2023
301d565
readme: update for next dev release
d3zd3z Oct 27, 2023
25b7c7a
imgtool: make "align" command line parameter optional
butok Oct 5, 2023
2b924da
samples: zephyr: Use the default MCUBoot PEM key file.
butok Oct 11, 2023
4a1effb
zephyr: Remove deprecated ZEPHYR_TRY_MASS_ERASE option
nordicjm Oct 31, 2023
822b6cb
boot: zephyr: serial_adapter: Fail if USB CDC enabled with console
nordicjm Nov 6, 2023
d5c963c
boot: zephyr: serial_adapter: Add error if main thread not preemptible
nordicjm Nov 6, 2023
0a8bbbf
boot: zephyr: Fix USB configs
nordicjm Nov 6, 2023
013c9e7
boot: zephyr: board: various: Remove size optimisation
nordicjm Nov 6, 2023
e9fccef
boot_serial: Fix missing response if echo command disabled
nordicjm Nov 6, 2023
6c4f7b4
doc: imgtool: update align description
butok Nov 6, 2023
0c0470e
docs: release: Add notes on Zephyr USB fixes and boot serial echo
nordicjm Nov 6, 2023
cd82f8b
boot: zephyr: add support for lpcxpresso55s28
butok Nov 20, 2023
47b3436
zephyr: kconfig: Prevent MBEDTLS selection when tinycrypt is used
nordicjm Nov 21, 2023
3f0b89d
boot: zephyr: add support for mimxrt101x_evk
butok Nov 27, 2023
5e6cffb
boot: boot_serial: Fix single slot encrypted image list
nordicjm Nov 24, 2023
433b848
zephyr: Move IO functions out of main to separate file
nordicjm Aug 16, 2023
215345f
zephyr: Add firmware loader MCUboot operation style
nordicjm Aug 16, 2023
05d1194
docs: release: Add note on firmware loader mode
nordicjm Aug 16, 2023
ab99fe2
scripts: add missing pyyaml dependency
samueltardieu Nov 19, 2023
c43a20f
boot: zephyr: add support for mimxrt1040_evk
butok Dec 5, 2023
d99154f
zephyr: rename 'led_init()' to 'io_led_init()'
pepe2k Dec 5, 2023
8c6c670
zephyr: io: include 'bootutil_log.h' and declare log module membership
pepe2k Dec 5, 2023
2a74a2b
zephyr: io: add 'io_led_set()'
pepe2k Dec 5, 2023
a88e229
zephyr: sysflash: Fix if condition for zephyr applications
nordicjm Dec 7, 2023
2129973
zephyr: firmware/single_loader: Fix compile warning
nordicjm Dec 7, 2023
c5d4f7b
Revert "[nrf noup] boards: thingy53: disable GPIO ISR support"
de-nordic Dec 11, 2023
877be0c
Revert "[nrf noup] crypto: ecdsa: Fix shared crypto MCUBoot EXT_ABI"
de-nordic Dec 11, 2023
1b9a2ad
Revert "[nrf noup] loader: Add firmware version check downgrade preve…
de-nordic Dec 11, 2023
9de47c0
Revert "[nrf noup] boot: zephyr: Boot even if EXT_ABI is not provided"
de-nordic Dec 11, 2023
b046f52
Revert "[nrf noup] sysflash: pm_sysflash: Fix incorrect define exclud…
de-nordic Dec 11, 2023
3d53618
Revert "[nrf noup] zephyr: Add RAM flash configuration to cache for s…
de-nordic Dec 11, 2023
61d9ba8
Revert "[nrf fromtree] bootutil: Add shared data support for XIP with…
de-nordic Dec 11, 2023
57c2d47
Revert "[nrf fromtree] bootutil: Add mode for XIP with revert"
de-nordic Dec 11, 2023
ce8da0f
Revert "[nrf fromtree] boot_serial: Fix include"
de-nordic Dec 11, 2023
d5a5e6d
Revert "[nrf fromtree] zephyr: Fall back to minimal C library"
de-nordic Dec 11, 2023
18a6972
Revert "[nrf fromtree] zephyr: Fix boot serial extensions"
de-nordic Dec 11, 2023
1478f7e
Revert "[nrf noup] booutil: loader: Do not check reset vector for XIP…
de-nordic Dec 11, 2023
462c56b
Revert "[nrf noup] zephyr: Add support for three images"
de-nordic Dec 11, 2023
50c51f7
Revert "[nrf noup] booutil: loader: Fixup for NSIB and multi-image"
de-nordic Dec 11, 2023
ef0171c
Revert "[nrf noup] zephyr: Move partition manager definitions to pm_s…
de-nordic Dec 11, 2023
d12a734
Revert "[nrf noup] booutil: loader: Add support for NSIB and multi-im…
de-nordic Dec 11, 2023
06e56e0
Revert "[nrf fromtree] zephyr: Provide third image cases for direct i…
de-nordic Dec 11, 2023
bddbcf3
Revert "[nrf noup] boot: zephyr: Add ifdef protection for RAM locking"
de-nordic Dec 11, 2023
e36f811
Revert "[nrf noup] bootutil: Fix missing PCD define check"
de-nordic Dec 11, 2023
939cab4
Revert "[nrf noup] Fix path variables"
de-nordic Dec 11, 2023
8dc8d61
Revert "[nrf noup] bootloader: mcuboot: Fix wrong use of if defined"
de-nordic Dec 11, 2023
9db6377
Revert "[nrf noup] loader: Fix reading reset addr to support ext flash"
de-nordic Dec 11, 2023
ddb5250
Revert "[nrf noup] zephyr: Clean up non-secure RAM if enabled"
de-nordic Dec 11, 2023
b616e1c
Revert "[nrf noup] do_boot: clean peripherals state before boot"
de-nordic Dec 11, 2023
b103d4d
Revert "[nrf noup] boot: nrf53-specific customizations"
de-nordic Dec 11, 2023
c03575e
Revert "[nrf noup] treewide: add NCS partition manager support"
de-nordic Dec 11, 2023
a33a13f
Revert "[nrf noup] Restore default RTC user channel count"
de-nordic Dec 11, 2023
032b26b
[nrf mergeup] Merge upstream up to commit 212997395ed34ff1721f5f4461b…
de-nordic Dec 11, 2023
53c1009
[nrf noup] Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
fab404a
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
1ead686
[nrf noup] boot: nrf53-specific customizations
sigvartmh Aug 27, 2020
7489b10
[nrf noup] do_boot: clean peripherals state before boot
nvlsianpu Feb 27, 2020
4a6f6e0
[nrf noup] zephyr: Clean up non-secure RAM if enabled
sigvartmh Jan 6, 2023
352f95e
[nrf noup] loader: Fix reading reset addr to support ext flash
chrta Feb 10, 2022
c987bd0
[nrf noup] bootloader: mcuboot: Fix wrong use of if defined
osaether Jun 20, 2023
4a34302
[nrf noup] Fix path variables
nordicjm Jul 11, 2023
c052378
[nrf noup] bootutil: Fix missing PCD define check
nordicjm Aug 31, 2023
c0ec158
[nrf noup] boot: zephyr: Add ifdef protection for RAM locking
nordicjm Aug 31, 2023
08575cc
[nrf noup] booutil: loader: Add support for NSIB and multi-image
sigvartmh May 31, 2023
d44b986
[nrf noup] zephyr: Move partition manager definitions to pm_sysflash.h
de-nordic Aug 10, 2023
d9732b8
[nrf noup] booutil: loader: Fixup for NSIB and multi-image
sigvartmh Sep 15, 2023
7ce6393
[nrf noup] zephyr: Add support for three images
de-nordic Aug 11, 2023
e8b06a8
[nrf noup] booutil: loader: Do not check reset vector for XIP image
de-nordic Sep 22, 2023
8809c85
[nrf noup] zephyr: Add RAM flash configuration to cache for sysbuild
nordicjm Sep 18, 2023
4d68fd4
[nrf noup] sysflash: pm_sysflash: Fix incorrect define exclude for NSIB
sigvartmh Oct 16, 2023
fec6987
[nrf noup] boot: zephyr: Boot even if EXT_ABI is not provided
sigvartmh Oct 17, 2023
5b59dbf
[nrf noup] loader: Add firmware version check downgrade prevention
sigvartmh Sep 27, 2023
691f405
[nrf noup] crypto: ecdsa: Fix shared crypto MCUBoot EXT_ABI
sigvartmh Oct 10, 2023
75eae0e
[nrf noup] boards: thingy53: disable GPIO ISR support
nika-nordic Oct 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/sim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- "sig-rsa validate-primary-slot ram-load multiimage"
- "sig-rsa validate-primary-slot direct-xip multiimage"
- "sig-ecdsa hw-rollback-protection multiimage"
- "sig-ecdsa-psa,sig-ecdsa-psa sig-p384"
- "ram-load enc-aes256-kw multiimage"
- "ram-load enc-aes256-kw sig-ecdsa-mbedtls multiimage"
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Coverity Scan Build Status](https://scan.coverity.com/projects/12307/badge.svg)][coverity]
[![Build Status (Sim)](https://github.com/mcu-tools/mcuboot/workflows/Sim/badge.svg)][sim]
[![Build Status (Mynewt)](https://github.com/mcu-tools/mcuboot/workflows/Mynewt/badge.svg)][mynewt]
[![Build Status (Espressif)](https://github.com/mcu-tools/mcuboot/workflows/Espressif/badge.svg)][espressif]
[![Publishing Status (imgtool)](https://github.com/mcu-tools/mcuboot/workflows/imgtool/badge.svg)][imgtool]
[![Build Status (Travis CI)](https://img.shields.io/travis/mcu-tools/mcuboot/main.svg?label=travis-ci)][travis]
[![Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)][license]
Expand All @@ -12,11 +13,12 @@
[coverity]: https://scan.coverity.com/projects/mcuboot
[sim]: https://github.com/mcu-tools/mcuboot/actions?query=workflow:Sim
[mynewt]: https://github.com/mcu-tools/mcuboot/actions?query=workflow:Mynewt
[espressif]: https://github.com/mcu-tools/mcuboot/actions?query=workflow:Espressif
[imgtool]: https://github.com/mcu-tools/mcuboot/actions?query=workflow:imgtool
[travis]: https://travis-ci.org/mcu-tools/mcuboot
[license]: https://github.com/mcu-tools/mcuboot/blob/main/LICENSE

This is MCUboot version 1.11.0-dev
This is MCUboot version 2.1.0-dev

MCUboot is a secure bootloader for 32-bits microcontrollers. It defines a
common infrastructure for the bootloader and the system flash layout on
Expand Down
39 changes: 32 additions & 7 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ bs_list_img_ver(char *dst, int maxlen, struct image_version *ver)
(uint16_t)ver->iv_minor, ver->iv_revision);

if (ver->iv_build_num != 0 && len > 0 && len < maxlen) {
snprintf(&dst[len], (maxlen - len), "%u", ver->iv_build_num);
snprintf(&dst[len], (maxlen - len), ".%u", ver->iv_build_num);
}
}
#endif /* !MCUBOOT_USE_SNPRINTF */
Expand Down Expand Up @@ -259,7 +259,11 @@ bs_list(char *buf, int len)
int swap_status = boot_swap_type_multi(image_index);
#endif

#ifdef MCUBOOT_SINGLE_APPLICATION_SLOT
for (slot = 0; slot < 1; slot++) {
#else
for (slot = 0; slot < 2; slot++) {
#endif
FIH_DECLARE(fih_rc, FIH_FAILURE);
uint8_t tmpbuf[64];

Expand Down Expand Up @@ -289,15 +293,26 @@ bs_list(char *buf, int len)
fih_rc, image_index, slot);
if (FIH_EQ(fih_rc, FIH_BOOT_HOOK_REGULAR))
{
#ifdef MCUBOOT_ENC_IMAGES
if (IS_ENCRYPTED(&hdr)) {
#if defined(MCUBOOT_ENC_IMAGES)
#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
if (IS_ENCRYPTED(&hdr) && MUST_DECRYPT(fap, image_index, &hdr)) {
FIH_CALL(boot_image_validate_encrypted, fih_rc, fap,
&hdr, tmpbuf, sizeof(tmpbuf));
} else {
#endif
if (IS_ENCRYPTED(&hdr)) {
/*
* There is an image present which has an encrypted flag set but is
* not encrypted, therefore remove the flag from the header and run a
* normal image validation on it.
*/
hdr.ih_flags &= ~ENCRYPTIONFLAGS;
}
#endif

FIH_CALL(bootutil_img_validate, fih_rc, NULL, 0, &hdr,
fap, tmpbuf, sizeof(tmpbuf), NULL, 0, NULL);
#ifdef MCUBOOT_ENC_IMAGES
#if defined(MCUBOOT_ENC_IMAGES) && !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
}
#endif
}
Expand Down Expand Up @@ -1010,11 +1025,11 @@ boot_serial_input(char *buf, int len)
}
} else if (hdr->nh_group == MGMT_GROUP_ID_DEFAULT) {
switch (hdr->nh_id) {
case NMGR_ID_ECHO:
#ifdef MCUBOOT_BOOT_MGMT_ECHO
case NMGR_ID_ECHO:
bs_echo(buf, len);
#endif
break;
#endif
case NMGR_ID_CONS_ECHO_CTRL:
bs_rc_rsp(0);
break;
Expand Down Expand Up @@ -1189,6 +1204,10 @@ boot_serial_read_console(const struct boot_uart_funcs *f,int timeout_in_ms)
int max_input;
int elapsed_in_ms = 0;

#ifndef MCUBOOT_SERIAL_WAIT_FOR_DFU
bool allow_idle = true;
#endif

boot_uf = f;
max_input = sizeof(in_buf);

Expand All @@ -1200,14 +1219,20 @@ boot_serial_read_console(const struct boot_uart_funcs *f,int timeout_in_ms)
* from serial console (if single-thread mode is used).
*/
#ifndef MCUBOOT_SERIAL_WAIT_FOR_DFU
MCUBOOT_CPU_IDLE();
if (allow_idle == true) {
MCUBOOT_CPU_IDLE();
allow_idle = false;
}
#endif
MCUBOOT_WATCHDOG_FEED();
#ifdef MCUBOOT_SERIAL_WAIT_FOR_DFU
uint32_t start = k_uptime_get_32();
#endif
rc = f->read(in_buf + off, sizeof(in_buf) - off, &full_line);
if (rc <= 0 && !full_line) {
#ifndef MCUBOOT_SERIAL_WAIT_FOR_DFU
allow_idle = true;
#endif
goto check_timeout;
}
off += rc;
Expand Down
3 changes: 2 additions & 1 deletion boot/bootutil/include/bootutil/boot_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ enum mcuboot_mode {
MCUBOOT_MODE_SWAP_USING_MOVE,
MCUBOOT_MODE_DIRECT_XIP,
MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT,
MCUBOOT_MODE_RAM_LOAD
MCUBOOT_MODE_RAM_LOAD,
MCUBOOT_MODE_FIRMWARE_LOADER
};

enum mcuboot_signature_type {
Expand Down
4 changes: 3 additions & 1 deletion boot/bootutil/include/bootutil/bootutil_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ extern "C" {

#ifdef MCUBOOT_BOOT_MAX_ALIGN

#if defined(MCUBOOT_SWAP_USING_MOVE) || defined(MCUBOOT_SWAP_USING_SCRATCH)
_Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 32,
"Unsupported value for MCUBOOT_BOOT_MAX_ALIGN");
"Unsupported value for MCUBOOT_BOOT_MAX_ALIGN for SWAP upgrade modes");
#endif

#define BOOT_MAX_ALIGN MCUBOOT_BOOT_MAX_ALIGN
#define BOOT_MAGIC_ALIGN_SIZE ALIGN_UP(BOOT_MAGIC_SZ, BOOT_MAX_ALIGN)
Expand Down
1 change: 1 addition & 0 deletions boot/bootutil/include/bootutil/caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ uint32_t bootutil_get_caps(void);
#define BOOTUTIL_CAP_RAM_LOAD (1<<16)
#define BOOTUTIL_CAP_DIRECT_XIP (1<<17)
#define BOOTUTIL_CAP_HW_ROLLBACK_PROT (1<<18)
#define BOOTUTIL_CAP_ECDSA_P384 (1<<19)

/*
* Query the number of images this bootloader is configured for. This
Expand Down
7 changes: 4 additions & 3 deletions boot/bootutil/include/bootutil/crypto/ecdsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@
extern "C" {
#endif

#if defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || defined(MCUBOOT_USE_CC310) \
|| defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
#if (defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || \
defined(MCUBOOT_USE_CC310) || defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)) \
&& !defined(MCUBOOT_USE_PSA_CRYPTO)
/*
* Declaring these like this adds NULL termination.
*/
Expand Down Expand Up @@ -131,7 +132,7 @@ static int bootutil_import_key(uint8_t **cp, uint8_t *end)

return 0;
}
#endif /* MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310 */
#endif /* (MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310) && !MCUBOOT_USE_PSA_CRYPTO */

/*
* cp points to ASN1 string containing an integer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* the MCUBOOT_USE_PSA_CRYPTO will take precedence.
*/

#ifndef __BOOTUTIL_CRYPTO_SHA256_H_
#define __BOOTUTIL_CRYPTO_SHA256_H_
#ifndef __BOOTUTIL_CRYPTO_SHA_H_
#define __BOOTUTIL_CRYPTO_SHA_H_

#include "mcuboot_config/mcuboot_config.h"
#include "mcuboot_config/mcuboot_logging.h"
Expand All @@ -35,8 +35,16 @@
#error "One crypto backend must be defined: either CC310/MBED_TLS/TINYCRYPT/PSA_CRYPTO"
#endif

#if defined(MCUBOOT_SIGN_EC384)
#define IMAGE_HASH_SIZE (48)
#define EXPECTED_HASH_TLV IMAGE_TLV_SHA384
#else
#define IMAGE_HASH_SIZE (32)
#define EXPECTED_HASH_TLV IMAGE_TLV_SHA256
#endif /* MCUBOOT_SIGN_EC384 */

/* Universal defines for SHA-256 */
#define BOOTUTIL_CRYPTO_SHA256_BLOCK_SIZE (64)
#define BOOTUTIL_CRYPTO_SHA256_BLOCK_SIZE (64)
#define BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE (32)

#if defined(MCUBOOT_USE_PSA_CRYPTO)
Expand Down Expand Up @@ -70,119 +78,129 @@ extern "C" {

#if defined(MCUBOOT_USE_PSA_CRYPTO)

typedef psa_hash_operation_t bootutil_sha256_context;
typedef psa_hash_operation_t bootutil_sha_context;

static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
static inline int bootutil_sha_init(bootutil_sha_context *ctx)
{
*ctx = psa_hash_operation_init();
return (int)psa_hash_setup(ctx, PSA_ALG_SHA_256);
#if defined(MCUBOOT_SIGN_EC384)
psa_status_t status = psa_hash_setup(ctx, PSA_ALG_SHA_384);
#else
psa_status_t status = psa_hash_setup(ctx, PSA_ALG_SHA_256);
#endif
return (int)status;
}

static inline int bootutil_sha256_drop(bootutil_sha256_context *ctx)
static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
{
return (int)psa_hash_abort(ctx);
}

static inline int bootutil_sha256_update(bootutil_sha256_context *ctx,
const void *data,
uint32_t data_len)
static inline int bootutil_sha_update(bootutil_sha_context *ctx,
const void *data,
uint32_t data_len)
{
return (int)psa_hash_update(ctx, data, data_len);
}

static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
uint8_t *output)
static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
uint8_t *output)
{
size_t hash_length = 0;
/* Assumes the output buffer is at least the expected size of the hash */
#if defined(MCUBOOT_SIGN_EC384)
return (int)psa_hash_finish(ctx, output, PSA_HASH_LENGTH(PSA_ALG_SHA_384), &hash_length);
#else
return (int)psa_hash_finish(ctx, output, PSA_HASH_LENGTH(PSA_ALG_SHA_256), &hash_length);
#endif
}

#elif defined(MCUBOOT_USE_MBED_TLS)

typedef mbedtls_sha256_context bootutil_sha256_context;
typedef mbedtls_sha256_context bootutil_sha_context;

static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
static inline int bootutil_sha_init(bootutil_sha_context *ctx)
{
mbedtls_sha256_init(ctx);
return mbedtls_sha256_starts_ret(ctx, 0);
}

static inline int bootutil_sha256_drop(bootutil_sha256_context *ctx)
static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
{
/* XXX: config defines MBEDTLS_PLATFORM_NO_STD_FUNCTIONS so no need to free */
/* (void)mbedtls_sha256_free(ctx); */
(void)ctx;
return 0;
}

static inline int bootutil_sha256_update(bootutil_sha256_context *ctx,
const void *data,
uint32_t data_len)
static inline int bootutil_sha_update(bootutil_sha_context *ctx,
const void *data,
uint32_t data_len)
{
return mbedtls_sha256_update_ret(ctx, data, data_len);
}

static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
uint8_t *output)
static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
uint8_t *output)
{
return mbedtls_sha256_finish_ret(ctx, output);
}

#endif /* MCUBOOT_USE_MBED_TLS */

#if defined(MCUBOOT_USE_TINYCRYPT)
typedef struct tc_sha256_state_struct bootutil_sha256_context;
static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
typedef struct tc_sha256_state_struct bootutil_sha_context;

static inline int bootutil_sha_init(bootutil_sha_context *ctx)
{
tc_sha256_init(ctx);
return 0;
}

static inline int bootutil_sha256_drop(bootutil_sha256_context *ctx)
static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
{
(void)ctx;
return 0;
}

static inline int bootutil_sha256_update(bootutil_sha256_context *ctx,
const void *data,
uint32_t data_len)
static inline int bootutil_sha_update(bootutil_sha_context *ctx,
const void *data,
uint32_t data_len)
{
return tc_sha256_update(ctx, data, data_len);
}

static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
uint8_t *output)
static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
uint8_t *output)
{
return tc_sha256_final(output, ctx);
}
#endif /* MCUBOOT_USE_TINYCRYPT */

#if defined(MCUBOOT_USE_CC310)
static inline int bootutil_sha256_init(bootutil_sha256_context *ctx)
static inline int bootutil_sha_init(bootutil_sha_context *ctx)
{
cc310_sha256_init(ctx);
return 0;
}

static inline int bootutil_sha256_drop(bootutil_sha256_context *ctx)
static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
{
(void)ctx;
nrf_cc310_disable();
return 0;
}

static inline int bootutil_sha256_update(bootutil_sha256_context *ctx,
const void *data,
uint32_t data_len)
static inline int bootutil_sha_update(bootutil_sha_context *ctx,
const void *data,
uint32_t data_len)
{
cc310_sha256_update(ctx, data, data_len);
return 0;
}

static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
uint8_t *output)
static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
uint8_t *output)
{
cc310_sha256_finalize(ctx, output);
return 0;
Expand Down Expand Up @@ -224,4 +242,4 @@ static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
}
#endif

#endif /* __BOOTUTIL_CRYPTO_SHA256_H_ */
#endif /* __BOOTUTIL_CRYPTO_SHA_H_ */
2 changes: 1 addition & 1 deletion boot/bootutil/include/bootutil/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ struct flash_area;
* Image trailer TLV types.
*
* Signature is generated by computing signature over the image hash.
* Currently the only image hash type is SHA256.
*
* Signature comes in the form of 2 TLVs.
* 1st on identifies the public key which should be used to verify it.
Expand All @@ -89,6 +88,7 @@ struct flash_area;
#define IMAGE_TLV_KEYHASH 0x01 /* hash of the public key */
#define IMAGE_TLV_PUBKEY 0x02 /* public key */
#define IMAGE_TLV_SHA256 0x10 /* SHA256 of image hdr and body */
#define IMAGE_TLV_SHA384 0x11 /* SHA384 of image hdr and body */
#define IMAGE_TLV_RSA2048_PSS 0x20 /* RSA2048 of hash output */
#define IMAGE_TLV_ECDSA224 0x21 /* ECDSA of hash output - Not supported anymore */
#define IMAGE_TLV_ECDSA_SIG 0x22 /* ECDSA of hash output */
Expand Down
Loading