Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
ba56472
[nrf fromlist] bootutil: Move all encryption TLV helper identifiers i…
de-nordic May 29, 2025
4fb63a6
[nrf fromlist] bootutil: Remove redundant ALIGN definitions
de-nordic May 29, 2025
6e4285a
[nrf fromlist] bootutil: Replace local identifiers with common defini…
de-nordic May 30, 2025
884efca
[nrf fromlist] bootutil: Fix boot_scramble_region escaping flash area
de-nordic Jun 11, 2025
46980ce
[nrf fromtree] scripts: imgtool: Compression of no header-padded images
nordic-mik7 Jun 9, 2025
6a4025b
[nrf fromlist] zephyr: Fix pinreset trigger
tomchy Jun 16, 2025
57ceb53
[nrf fromtree] bootutil: loader: overwrite-only mode fix for trailer …
nordic-mik7 Jun 16, 2025
657e048
[nrf fromtree] boot: zephyr: Refactor DFU entry logic
sayoojkkarun Apr 23, 2025
b7f129b
[nrf fromtree] bootutil: Improve logging coverage
de-nordic May 15, 2025
eaa6a90
[nrf fromtree] zephyr: Improve logging
de-nordic May 15, 2025
0529cbe
[nrf fromtree] bootutil: Small cleanup in image.h
de-nordic May 28, 2025
860d366
[nrf fromtree] doc: Add information on supporting SHA512 with ECIES-X…
de-nordic May 7, 2025
736d33e
[nrf fromtree] bootutil: Add support for HAMC-SHA512 with ECIES-X25519
de-nordic May 8, 2025
1a457e3
[nrf fromtree] zephyr: Support for HKDF/HMAC with SHA512
de-nordic May 8, 2025
c4c82e2
[nrf fromtree] imgtool: Add support for HMAC/HKDF-SHA512 with ECIES-X…
de-nordic May 9, 2025
80f8e8c
[nrf fromtree] bootutil: Use flash base address for direct hash
tomchy Jul 1, 2025
2219997
[nrf fromlist] boot: zephyr: boards: Remove outdated nrf54l15pdk boar…
nordicjm Jul 8, 2025
422c637
[nrf fromlist] bootutil: Unify app_max_size() implementations
tomchy May 23, 2025
b0ad970
[nrf fromlist] zephyr: boards: nrf - remove redundant multithreading …
nordic-mik7 Jul 4, 2025
cf5187c
[nrf fromtree] boot: zephyr: RAM cleanup debug loop
michalek-no Jul 2, 2025
edbba12
[nrf fromlist] zephyr: Improve SHA support selectors
de-nordic Jul 16, 2025
d8bd928
[nrf fromtree] loader: Allow to specify slot number in version
tomchy Jun 16, 2025
7ad728f
[nrf fromtree] zephyr: Enable building ECDSA PSA variant
ahasztag Jul 21, 2025
727cc28
[nrf noup] github: Add a commit tags check workflow
carlescufi Oct 10, 2023
7ac4eeb
[nrf noup] zephyr: Remove duplication from cmake
sigvartmh Mar 26, 2019
54f2129
[nrf noup] zephyr: add 'minimal' configuration files
mbolivar-nordic Sep 3, 2021
313de9c
[nrf noup] boards: add support for Thingy:91
bjda Sep 20, 2019
abaff57
[nrf noup] zephyr: Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
19d7a4e
[nrf noup] boards: thingy91x: add board config
maxd-nordic Dec 8, 2023
89361bd
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
2cdbcb0
[nrf noup] boot: nrf53-specific customizations
sigvartmh Aug 27, 2020
0f2061b
[nrf noup] zephyr: clean peripherals state before boot
nvlsianpu Feb 27, 2020
c9f632d
[nrf noup] zephyr: Clean up non-secure RAM if enabled
sigvartmh Jan 6, 2023
c1cf5e4
[nrf noup] loader: Fix reading reset addr to support ext flash
chrta Feb 10, 2022
1ec17e9
[nrf noup] loader: Do not check reset vector for XIP image
de-nordic Sep 22, 2023
c8d8f5a
[nrf noup] zephyr: Add RAM flash configuration to cache for sysbuild
nordicjm Sep 18, 2023
d07555b
[nrf noup] zephyr: Boot even if EXT_ABI is not provided
sigvartmh Oct 17, 2023
420ac79
[nrf noup] loader: Add firmware version check downgrade prevention
sigvartmh Sep 27, 2023
937e0f6
[nrf noup] boards: thingy53: disable GPIO ISR support
nika-nordic Oct 9, 2023
470e7cb
[nrf noup] loader: work-around for multi-image builds
sigvartmh Mar 30, 2021
1ca64e9
[nrf noup] loader: Fix missing PCD define check
nordicjm Aug 31, 2023
75073fd
[nrf noup] boot: Add support for NSIB and multi-image
sigvartmh May 31, 2023
bc86df6
[nrf noup] sysflash: Move partition manager definitions to pm_sysflash.h
de-nordic Aug 10, 2023
3b3298d
[nrf noup] sysflash: Add support for three images
de-nordic Aug 11, 2023
bd97f58
[nrf noup] loader: introduced cleanup of unusable secondary slot
nvlsianpu Feb 15, 2024
271e505
[nrf noup] loader: remove cleanup for direct xip mode
gchwier May 17, 2024
f5f382f
[nrf noup] boards: thingy91x: enable serial recovery
maxd-nordic Mar 12, 2024
b8f6a06
[nrf noup] boot: zephyr: Disable boot banner if NCS_BOOT_BANNER is used
rlubos May 17, 2024
8949a6a
[nrf noup] boot/zephyr: fix fw_info search
nvlsianpu May 27, 2024
c41b4a8
[nrf noup] boot: zephyr: Add NCS boot banner
nordicjm Jun 11, 2024
bf14385
[nrf noup] boot/../loader: skip downgrade prevention for s1/s0
nvlsianpu Jun 13, 2024
674adc7
[nrf noup] boot/../loader: reboot after updating s0/s1
nvlsianpu Jun 18, 2024
1f364bf
[nrf noup] bootutil: loader: Fix netcore address checking
nordicjm Aug 29, 2024
62ddef3
[nrf noup] boards: nrf54l15dk: Disable FPROTECT
nvlsianpu Sep 18, 2024
2c64b71
[nrf noup] boot: Add shared crypto for ECDSA and SHA
sigvartmh Feb 14, 2019
599a1b9
[nrf noup] boot: zephyr: Do not lock PCD region with TF-M
MarkusLassila Aug 30, 2024
352b2a4
[nrf noup] treewide: Add support for sysbuild assigned images
nordicjm Sep 10, 2024
d5f373a
[nrf noup] boot: bootutil: loader: Add s0/s1 checking of MCUboot image
nordicjm Oct 15, 2024
be6d73e
[nrf noup] boards: Thingy:91 X release config
maxd-nordic Oct 23, 2024
e406849
[nrf noup] workflows: Add a backport workflow
carlescufi Oct 25, 2024
835b63f
[nrf noup] boot/zephyr: add nrf54l15dk ext flash configs
michalek-no Nov 7, 2024
a4457ac
[nrf noup] boot/zephyr/Kconfig: conditionally disable BOOT_MAX_IMG_SE…
nvlsianpu Sep 19, 2024
2f3b28c
[nrf noup] boot: zephyr: serial_recovery: Add nRF5340 Kconfig override
nordicjm Dec 9, 2024
9e2bba9
[nrf noup] boot: Remove child/parent references
nordicjm Dec 5, 2024
60dcc0d
[nrf noup] sysflash: Add missing _FLASH_0_ID definitions
de-nordic Jan 15, 2025
fd3ccd3
[nrf noup] boot: zephyr: boards: Disabled NCS boot banner for thingy 53
kkasperczyk-no Jan 24, 2025
1f1b7be
[nrf noup] partition_manager: Add support for internal flash netcore DFU
hellesvik-nordic Feb 6, 2025
f471000
[nrf noup] zephyr: sdk-nrf specific overrides on PSA Kconfigs
de-nordic Mar 4, 2025
791dd59
[nrf noup] zephyr: Fix path variables
nordicjm Jul 11, 2023
7f674d9
[nrf noup] zephyr: Use mbedTLS specific C functions with RSA
de-nordic Mar 14, 2025
c872f6a
[nrf noup] boot/zephyr: nrf54h20dk board support
nordic-mik7 Mar 10, 2025
31766fc
[nrf noup] boot/zephyr: nrf54h20dk cleanup adaptations
nordic-mik7 Mar 28, 2025
fac7ac4
[nrf noup] boot/zephyr/nrf_cleanup: cleanup uarte pins
nvlsianpu Mar 5, 2024
c6e2585
[nrf noup] boot/zephyr/Kconfig: fix MBEDTLS_CFG_FILE value
nvlsianpu Apr 1, 2025
5f6e119
[nrf noup] nrf_cleanup: nRF54l: disable cleanup on UARTE pins
nvlsianpu Apr 11, 2025
1aa8af0
[nrf noup] boot: zephyr: boards: nrf54lm20pdk
michalek-no Apr 23, 2025
b6c992e
[nrf noup] nrf_cleanup: nRF54h: fix missing peripheral cleanup
ahasztag Apr 28, 2025
898b9bc
[nrf noup] zephyr: Add support for compressed image updates
nordicjm Aug 22, 2024
0ae1441
[nrf noup] boot: zephyr: Add experimental selection to compression
nordicjm Nov 7, 2024
002515b
[nrf noup] decompression: Align to changes in nrfcompress API
nordic-mik7 May 13, 2025
9200785
[nrf noup] boot: zephyr: Add bm firmware loader code
nordicjm Jun 12, 2025
068718a
[nrf noup] boot: Provide default configuration for nRF54H20
tomchy Jul 3, 2025
a9e70e4
[nrf noup] boot: Add retry for image verification
adsz-nordic Jul 8, 2025
26192ca
[nrf noup] bootutil: Add support for KMU stored ED25519 signature key
de-nordic Sep 20, 2024
373038b
[nrf noup] boot: bootutil: Allow configuring number of KMU keys
nordicjm Dec 2, 2024
9dacf6d
[nrf noup] bootutil: key revocation
michalek-no Mar 17, 2025
2f7059e
[nrf noup] boot: zephyr: Kconfig dependencies for PSA LITE
michalek-no May 28, 2025
d69621e
[nrf noup] Added BOOT_SIGNATURE_USING_ITS for ecdsa configuration
ahasztag Jul 24, 2025
31c8554
[nrf fromtree] bootutil: Fix X25519 HMAC-SHA512
de-nordic Jul 29, 2025
2128ae5
[nrf fromtree] imgtool: Fix x25519 TLV HMAC tag
de-nordic Jul 29, 2025
8b2d04c
[nrf noup] zephyr: Enforce HMAC-SHA512 for NRF54L with X25519
de-nordic Jul 30, 2025
30e7326
[nrf noup] boot: Use NCS_ prefix for sdk-nrf specific Kconfigs
de-nordic Jul 31, 2025
4bfb139
[nrf noup] boot: Use NCS_ prefix for sdk-nrf specific Kconfigs
de-nordic Aug 1, 2025
58175b6
[nrf noup] boot/zephyr/nrf_cleanup: fix index error
nordic-auko Aug 4, 2025
37486f5
[nrf noup] workflows: Add manifest PRs creation
karhama Aug 8, 2025
bc5eb3f
[nrf fromlist] boot: zephyr: Fix including asn1 when ed25519 is used
nordicjm Aug 7, 2025
a184e32
[nrf noup] boot: zephyr: Fix bm IO button check
nordicjm Aug 7, 2025
edcad13
Revert "[nrf noup] boot: zephyr: Add NCS boot banner"
nordicjm Aug 7, 2025
b31a7c6
Revert "[nrf noup] zephyr: Restore default RTC user channel count"
nordicjm Aug 7, 2025
edc1c70
[nrf fromtree] boot: Switch to picolibc
keith-packard May 10, 2025
50e1caa
[nrf noup] zephyr: Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
8d31ad7
[nrf noup] boot: zephyr: Add NCS boot banner
nordicjm Jun 11, 2024
c72ed15
[nrf fromlist] boot/boot_serial: build-time skip of the erasing of im…
nvlsianpu Aug 8, 2025
95d384a
[nrf fromtree] bootutil: Fix scratch scrambling
nordic-mik7 Aug 8, 2025
6c096b8
[nrf noup] boot: zephyr: Adjust PSA requirements for PSA_CORE_LITE
Vge0rge Aug 8, 2025
4e46797
[nrf fromtree] bootutil: Fixed security counter overflow detected to …
ahasztag Aug 6, 2025
0fadab1
[nrf noup] zephyr: hw security counter limited set by default
ahasztag Aug 11, 2025
c03a815
[nrf fromlist] bootutil: Fix PureEdDSA when flash base is not 0x0
nordic-mik7 Aug 6, 2025
e032eb1
[nrf fromlist] zephyr: Fix FLASH_DEVICE_ID for nRF54H20 platform
nordic-mik7 Aug 7, 2025
1b102ec
[nrf fromtree] imgtool: Allow for AES256 encryption
ahasztag Jul 29, 2025
3b20ec3
[nrf fromtree] zephyr: Add support for AES256
ahasztag Jul 29, 2025
3adc1f2
[nrf noup] boot: zephyr: remove nonsecure ram cleanup
michalek-no Aug 19, 2025
1b1a37f
[nrf noup] boot: zephyr: Delay bm IO button check
nordicjm Aug 19, 2025
f9e4ce0
Revert "[nrf noup] boot: zephyr: Add NCS boot banner"
nordicjm Aug 26, 2025
446967f
Revert "[nrf noup] zephyr: Restore default RTC user channel count"
nordicjm Aug 26, 2025
c859608
[nrf noup] boot: zephyr: Add NCS boot banner
nordicjm Jun 11, 2024
ecc13ac
[nrf noup] boot: zephyr: firmware_loader: Allow GPIO usage in BM
nordicjm Aug 26, 2025
285fd59
[nrf noup] boot: zephyr: Disable self RWX
michalek-no Aug 5, 2025
20587e2
[nrf noup] boot/zephyr/nrf_cleanup: ensure UARTE RX disabled
nvlsianpu Sep 1, 2025
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
31 changes: 31 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Backport
on:
pull_request_target:
types:
- closed
- labeled
branches:
- main

jobs:
backport:
name: Backport
runs-on: ubuntu-22.04
# Only react to merged PRs for security reasons.
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
if: >
github.event.pull_request.merged &&
(
github.event.action == 'closed' ||
(
github.event.action == 'labeled' &&
contains(github.event.label.name, 'backport')
)
)
steps:
- name: Backport
uses: zephyrproject-rtos/[email protected]
with:
github_token: ${{ secrets.NCS_GITHUB_TOKEN }}
issue_labels: Backport
labels_template: '["Backport"]'
28 changes: 28 additions & 0 deletions .github/workflows/commit-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Commit tags

on:
pull_request:
types: [synchronize, opened, reopened, edited, labeled, unlabeled,
milestoned, demilestoned, assigned, unassigned, ready_for_review,
review_requested]

jobs:
commit_tags:
runs-on: ubuntu-22.04
name: Run commit tags checks on patch series (PR)
steps:
- name: Update PATH for west
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Checkout the code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Run the commit tags
uses: nrfconnect/action-commit-tags@main
with:
target: .
upstream: mcu-tools/mcuboot/main
17 changes: 17 additions & 0 deletions .github/workflows/manifest-PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: handle manifest PR
on:
pull_request_target:
types: [opened, synchronize, closed]
branches:
- main


jobs:
call-manifest-pr-action:
runs-on: ubuntu-latest
steps:
- name: handle manifest PR
uses: nrfconnect/action-manifest-pr@main
with:
token: ${{ secrets.NCS_GITHUB_TOKEN }}
manifest-pr-title-details: ${{ github.event.pull_request.title }}
12 changes: 10 additions & 2 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@

BOOT_LOG_MODULE_DECLARE(mcuboot);

#if !(defined(MCUBOOT_SINGLE_APPLICATION_SLOT) || \
defined(MCUBOOT_FIRMWARE_LOADER) || \
defined(MCUBOOT_SINGLE_APPLICATION_SLOT_RAM_LOAD))
#define BOOT_IMAGE_HAS_STATUS_FIELDS
#endif

#ifndef ARRAY_SIZE
#define ARRAY_SIZE ZCBOR_ARRAY_SIZE
#endif
Expand Down Expand Up @@ -914,8 +920,10 @@ bs_upload(char *buf, int len)
* erase has stopped to let us know whether erase
* is needed to be able to write current chunk.
*/
#ifdef BOOT_IMAGE_HAS_STATUS_FIELDS
static struct flash_sector status_sector;
#endif
#endif /* MCUBOOT_ERASE_PROGRESSIVELY */
#ifdef MCUBOOT_SWAP_USING_OFFSET
static uint32_t start_off = 0;
#endif
Expand Down Expand Up @@ -988,7 +996,7 @@ bs_upload(char *buf, int len)
#endif

curr_off = 0;
#ifdef MCUBOOT_ERASE_PROGRESSIVELY
#if defined(MCUBOOT_ERASE_PROGRESSIVELY) && defined(BOOT_IMAGE_HAS_STATUS_FIELDS)
/* Get trailer sector information; this is done early because inability to get
* that sector information means that upload will not work anyway.
* TODO: This is single occurrence issue, it should get detected during tests
Expand Down Expand Up @@ -1167,7 +1175,7 @@ bs_upload(char *buf, int len)
if (rc == 0) {
curr_off += img_chunk_len + rem_bytes;
if (curr_off == img_size) {
#ifdef MCUBOOT_ERASE_PROGRESSIVELY
#if defined(MCUBOOT_ERASE_PROGRESSIVELY) && defined(BOOT_IMAGE_HAS_STATUS_FIELDS)
/* Assure that sector for image trailer was erased. */
/* Check whether it was erased during previous upload. */
off_t start = flash_sector_get_off(&status_sector);
Expand Down
19 changes: 19 additions & 0 deletions boot/bootutil/include/bootutil/bootutil_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
*/

#ifndef H_BOOTUTIL_MACROS
#define H_BOOTUTIL_MACROS

#ifndef ALIGN_UP
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
#endif

#ifndef ALIGN_DOWN
#define ALIGN_DOWN(num, align) ((num) & ~((align) - 1))
#endif

#endif
15 changes: 7 additions & 8 deletions boot/bootutil/include/bootutil/bootutil_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,13 @@
#include <string.h>
#include <flash_map_backend/flash_map_backend.h>
#include <mcuboot_config/mcuboot_config.h>
#include <bootutil/bootutil_macros.h>
#include <bootutil/image.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef ALIGN_UP
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
#endif

#ifndef ALIGN_DOWN
#define ALIGN_DOWN(num, align) ((num) & ~((align) - 1))
#endif

/** Attempt to boot the contents of the primary slot. */
#define BOOT_SWAP_TYPE_NONE 1

Expand Down Expand Up @@ -302,6 +295,12 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm);
/**
* Attempts to load image header from flash; verifies flash header fields.
*
* The selected update method (i.e. swap move) may impose additional restrictions
* on the image size (i.e. due to the presence of the image trailer).
* Such restrictions are not verified by this function.
* These checks are implemented as part of the boot_image_validate(..) that uses
* sizes from the bootutil_max_image_size(..).
*
* @param[in] fa_p flash area pointer
* @param[out] hdr buffer for image header
*
Expand Down
116 changes: 110 additions & 6 deletions boot/bootutil/include/bootutil/crypto/ecdsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#if (defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_CC310) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_PSA_OR_MBED_TLS)) != 1
#error "One crypto backend must be defined: either CC310/TINYCRYPT/MBED_TLS/PSA_CRYPTO"
#endif
Expand Down Expand Up @@ -70,12 +71,18 @@
#include "bootutil/sign_key.h"
#include "common.h"

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
#include <bl_crypto.h>
#define NUM_ECC_BYTES (256 / 8)
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
extern "C" {
#endif

#if (defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || \
defined(MCUBOOT_USE_CC310)) && !defined(MCUBOOT_USE_PSA_CRYPTO)
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 @@ -127,8 +134,7 @@ static int bootutil_import_key(uint8_t **cp, uint8_t *end)
}
#endif /* (MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310) && !MCUBOOT_USE_PSA_CRYPTO */

#if defined(MCUBOOT_USE_TINYCRYPT)
#ifndef MCUBOOT_ECDSA_NEED_ASN1_SIG
#ifndef MCUBOOT_USE_PSA_CRYPTO
/*
* cp points to ASN1 string containing an integer.
* Verify the tag, and that the length is 32 bytes. Helper function.
Expand Down Expand Up @@ -178,8 +184,9 @@ static int bootutil_decode_sig(uint8_t signature[NUM_ECC_BYTES * 2], uint8_t *cp
}
return 0;
}
#endif /* not MCUBOOT_ECDSA_NEED_ASN1_SIG */
#endif /* !MCUBOOT_USE_PSA_CRYPTO */

#if defined(MCUBOOT_USE_TINYCRYPT)
typedef uintptr_t bootutil_ecdsa_context;
static inline void bootutil_ecdsa_init(bootutil_ecdsa_context *ctx)
{
Expand Down Expand Up @@ -248,16 +255,20 @@ static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
{
(void)ctx;
(void)pk_len;
(void)sig_len;
(void)hash_len;
uint8_t dsig[2 * NUM_ECC_BYTES];

if (bootutil_decode_sig(dsig, sig, sig + sig_len)) {
return -1;
}

/* Only support uncompressed keys. */
if (pk[0] != 0x04) {
return -1;
}
pk++;

return cc310_ecdsa_verify_secp256r1(hash, pk, sig, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE);
return cc310_ecdsa_verify_secp256r1(hash, pk, dsig, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE);
}

static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
Expand Down Expand Up @@ -462,6 +473,7 @@ static int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
}
#endif /* !MCUBOOT_BUILTIN_KEY */

#if !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
/* Verify the signature against the provided hash. The signature gets parsed from
* the encoding first, then PSA Crypto has a dedicated API for ECDSA verification
*/
Expand All @@ -480,6 +492,55 @@ static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
return (int) psa_verify_hash(ctx->key_id, PSA_ALG_ECDSA(ctx->required_algorithm),
hash, hlen, reformatted_signature, 2*ctx->curve_byte_count);
}
#else /* !CONFIG_NCS_BOOT_SIGNATURE_USING_ITS */

static const psa_key_id_t builtin_key_ids[] = {
0x40022100,
0x40022101,
0x40022102,
0x40022103
};

#define BOOT_SIGNATURE_BUILTIN_KEY_SLOTS ARRAY_SIZE(builtin_key_ids)

static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
uint8_t *pk, size_t pk_len,
uint8_t *hash, size_t hlen,
uint8_t *sig, size_t slen)
{
(void)pk;
(void)pk_len;
(void)slen;
psa_status_t status = PSA_ERROR_BAD_STATE;

/* Initialize PSA Crypto */
status = psa_crypto_init();
if (status != PSA_SUCCESS) {
BOOT_LOG_ERR("PSA crypto init failed %d", status);
return 1;
}

uint8_t reformatted_signature[96] = {0}; /* Enough for P-384 signature sizes */
parse_signature_from_rfc5480_encoding(sig, ctx->curve_byte_count, reformatted_signature);

status = PSA_ERROR_BAD_STATE;

for (int i = 0; i < BOOT_SIGNATURE_BUILTIN_KEY_SLOTS; ++i) {
psa_key_id_t kid = builtin_key_ids[i];

status = psa_verify_hash(kid, PSA_ALG_ECDSA(ctx->required_algorithm),
hash, hlen, reformatted_signature, 2*ctx->curve_byte_count);
if (status == PSA_SUCCESS) {
break;
}
BOOT_LOG_ERR("ECDSA signature verification failed %d", status);
}

return status == PSA_SUCCESS ? 0 : 2;
}

#endif /* !CONFIG_NCS_BOOT_SIGNATURE_USING_ITS */

#elif defined(MCUBOOT_USE_MBED_TLS)

typedef mbedtls_ecdsa_context bootutil_ecdsa_context;
Expand Down Expand Up @@ -613,6 +674,49 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,

#endif /* MCUBOOT_USE_MBED_TLS */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
typedef uintptr_t bootutil_ecdsa_context;
static inline void bootutil_ecdsa_init(bootutil_ecdsa_context *ctx)
{
(void)ctx;
}

static inline void bootutil_ecdsa_drop(bootutil_ecdsa_context *ctx)
{
(void)ctx;
}

static inline int bootutil_ecdsa_verify(bootutil_ecdsa_context *ctx,
uint8_t *pk, size_t pk_len,
uint8_t *hash, size_t hash_len,
uint8_t *sig, size_t sig_len)
{
(void)ctx;
(void)pk_len;
(void)hash_len;
uint8_t dsig[2 * NUM_ECC_BYTES];

if (bootutil_decode_sig(dsig, sig, sig + sig_len)) {
return -1;
}

/* Only support uncompressed keys. */
if (pk[0] != 0x04) {
return -1;
}
pk++;

return bl_secp256r1_validate(hash, BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE, pk, dsig);
}

static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx,
uint8_t **cp,uint8_t *end)
{
(void)ctx;
return bootutil_import_key(cp, end);
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions boot/bootutil/include/bootutil/crypto/rsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ static int bootutil_rsa_oaep_decrypt(
return -1;
}
size_t input_size = PSA_BITS_TO_BYTES(psa_get_key_bits(&key_attr));
if (input_size != TLV_ENC_RSA_SZ) {
if (input_size != BOOT_ENC_TLV_SIZE) {
return -1;
}

status = psa_asymmetric_decrypt(ctx->key_id, PSA_ALG_RSA_OAEP(PSA_ALG_SHA_256),
input, TLV_ENC_RSA_SZ, NULL, 0,
input, BOOT_ENC_TLV_SIZE, NULL, 0,
output, output_max_len, olen);
return (int)status;
}
Expand Down
Loading