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

Upmerge review PR #2

Draft
wants to merge 60 commits into
base: meta-upmerge-base
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
00f5860
[nrf noup] github: Add a commit tags check workflow
carlescufi Oct 10, 2023
6bc65a9
[nrf noup] zephyr: Remove duplication from cmake
sigvartmh Mar 26, 2019
bee9475
[nrf noup] zephyr: add 'minimal' configuration files
mbolivar-nordic Sep 3, 2021
49e2872
[nrf noup] boards: add support for Thingy:91
bjda Sep 20, 2019
93bb567
[nrf noup] zephyr: Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
c473f8e
[nrf noup] boards: thingy91x: add board config
maxd-nordic Dec 8, 2023
6facec9
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
56934f9
[nrf noup] boot: nrf53-specific customizations
sigvartmh Aug 27, 2020
50c5cdb
[nrf noup] zephyr: clean peripherals state before boot
nvlsianpu Feb 27, 2020
d04dd27
[nrf noup] zephyr: Clean up non-secure RAM if enabled
sigvartmh Jan 6, 2023
a3a50e7
[nrf noup] loader: Fix reading reset addr to support ext flash
chrta Feb 10, 2022
76d0d9a
[nrf noup] zephyr: Fix path variables
nordicjm Jul 11, 2023
5a8e708
[nrf noup] loader: Do not check reset vector for XIP image
de-nordic Sep 22, 2023
9599724
[nrf noup] zephyr: Add RAM flash configuration to cache for sysbuild
nordicjm Sep 18, 2023
5b37400
[nrf noup] zephyr: Boot even if EXT_ABI is not provided
sigvartmh Oct 17, 2023
2011395
[nrf noup] loader: Add firmware version check downgrade prevention
sigvartmh Sep 27, 2023
39bbebf
[nrf noup] boards: thingy53: disable GPIO ISR support
nika-nordic Oct 9, 2023
6f3eb68
[nrf noup] boot/zephyr/boards: nRF54l15pdk ext flash cfg
nvlsianpu Apr 11, 2024
6f9c198
[nrf noup] loader: work-around for multi-image builds
sigvartmh Mar 30, 2021
dced866
[nrf noup] loader: Fix missing PCD define check
nordicjm Aug 31, 2023
a7cea4e
[nrf noup] boot: Add support for NSIB and multi-image
sigvartmh May 31, 2023
fbe4075
[nrf noup] sysflash: Move partition manager definitions to pm_sysflash.h
de-nordic Aug 10, 2023
e80e793
[nrf noup] sysflash: Add support for three images
de-nordic Aug 11, 2023
51e36d8
[nrf noup] loader: introduced cleanup of unusable secondary slot
nvlsianpu Feb 15, 2024
592a0f1
[nrf noup] boards: nrf54l15: Disable FPROTECT
gchwier Apr 16, 2024
948c3ad
[nrf noup] loader: remove cleanup for direct xip mode
gchwier May 17, 2024
a3545cd
[nrf noup] zephyr: Clean up non-secure RAM if enabled
de-nordic Apr 19, 2024
1347dfb
[nrf noup] boot/zephyr/boards: nrf54l15pdk ext-flash partition
nvlsianpu Apr 15, 2024
8b7d37f
[nrf noup] boot/zephyr/boards: nrf54l15pdk ext-flash update
nvlsianpu May 20, 2024
6b95cd6
[nrf noup] boards: thingy91x: enable serial recovery
maxd-nordic Mar 12, 2024
220096b
[nrf noup] boot: zephyr: Disable boot banner if NCS_BOOT_BANNER is used
rlubos May 17, 2024
592f636
[nrf noup] boot/zephyr: fix fw_info search
nvlsianpu May 27, 2024
ad75809
[nrf noup] Revert of zephyr: arm: Update reading the flash image rese…
de-nordic May 28, 2024
48e6e27
[nrf noup] zephyr/boards: fix nrf54l15pdk ext flash dts overlay
nvlsianpu Jun 5, 2024
0148f96
[nrf noup] boot: zephyr: Add NCS boot banner
nordicjm Jun 11, 2024
cc78118
[nrf noup] boot/../loader: skip downgrade prevention for s1/s0
nvlsianpu Jun 13, 2024
29fdb63
[nrf noup] boot/../loader: reboot after updating s0/s1
nvlsianpu Jun 18, 2024
28fdae8
[nrf noup] Remove secure boot debug Kconfig
nordicjm Sep 4, 2024
fcf0a31
[nrf noup] bootutil: loader: Fix netcore address checking
nordicjm Aug 29, 2024
123454f
[nrf noup] boards: nrf54l15dk: Disable FPROTECT
nvlsianpu Sep 18, 2024
a242e91
[nrf noup] zephyr: Add support for compressed image updates
nordicjm Aug 22, 2024
756c5bf
[nrf fromtree] boot: SHA512 verification
michalek-no May 20, 2024
4e0dee6
[nrf noup] boot: Add shared crypto for ECDSA and SHA
sigvartmh Feb 14, 2019
3a28585
[nrf fromlist] imgtool: Add support for calculating SHA512
de-nordic Aug 22, 2024
18781c5
[nrf fromlist] boot: Replace boot_encrypt by boot_enc_encrypt and boo…
de-nordic Jul 18, 2024
6400cc8
[nrf noup] PSA configuration required changes
de-nordic Jul 24, 2024
e874cf8
[nrf noup] PSA implementation of x25519 and ed25519 verification
de-nordic May 29, 2024
2d7b4a6
[nrf noup] Exclude PSA source on non-PSA crypto configuration
de-nordic Oct 1, 2024
ccb9552
[nrf noup] bootutil: Provide support for SHA512 with ED25519
de-nordic Aug 2, 2024
258b369
[nrf noup] bootutil: Enable hash calculation directly on storage
de-nordic Sep 5, 2024
d1b85af
[nrf noup] bootutil: PureEdDSA using ED25519
de-nordic Sep 6, 2024
910045d
[nrf noup] There is only one SHA supported at once
de-nordic Oct 2, 2024
4a5d2ae
[nrf noup] bootutil: Fix typo in identifier
de-nordic Oct 2, 2024
237b8b9
[nrf fromlist] scripts: imgtool: compression
michalek-no Aug 9, 2024
f3a288d
[nrf noup] boot: zephyr: kconfig: Select PM_USE_CONFIG_SRAM_SIZE when…
nordicjm Oct 2, 2024
c020cd0
[nrf noup] Add missing selection of MBEDTLS_PSA_CRYPTO_C
de-nordic Oct 1, 2024
12e9928
[nrf noup] boot/zephyr/Kconfig: conditionally disable BOOT_MAX_IMG_SE…
nvlsianpu Sep 19, 2024
e295db1
[nrf fromlist] zephyr/Kconfig.serial_recovery: limit Slot info command
nvlsianpu Sep 24, 2024
d44d7bc
[nrf fromtree] boot: bootutil: loader: Fix slot info for directXIP/RA…
nordicjm Sep 25, 2024
22adc04
[nrf fromtree] boot: bootutil: loader: Fix issue with using pointers
nordicjm Sep 27, 2024
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/commit-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Commit tags

on: pull_request

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: Install python dependencies
run: |
pip3 install setuptools
pip3 install wheel
pip3 install gitlint

- name: Run the commit tags
uses: nrfconnect/action-commit-tags@main
with:
target: '.'
baserev: origin/${{ github.base_ref }}
revrange: 'none'
2 changes: 1 addition & 1 deletion boot/boot_serial/src/boot_serial_encryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ decrypt_region_inplace(struct boot_loader_state *state,
blk_sz = tlv_off - (off + bytes_copied);
}
}
boot_encrypt(BOOT_CURR_ENC(state), slot,
boot_enc_decrypt(BOOT_CURR_ENC(state), slot,
(off + bytes_copied + idx) - hdr->ih_hdr_size, blk_sz,
blk_off, &buf[idx]);
}
Expand Down
38 changes: 36 additions & 2 deletions boot/bootutil/include/bootutil/crypto/aes_ctr.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "mcuboot_config/mcuboot_config.h"

#if (defined(MCUBOOT_USE_MBED_TLS) + \
defined(MCUBOOT_USE_TINYCRYPT)) != 1
#error "One crypto backend must be defined: either MBED_TLS or TINYCRYPT"
defined(MCUBOOT_USE_TINYCRYPT) + defined(MCUBOOT_USE_PSA_CRYPTO)) != 1
#error "One crypto backend must be defined: either MBED_TLS or TINYCRYPT or PSA"
#endif

#if defined(MCUBOOT_USE_MBED_TLS)
Expand All @@ -38,12 +38,46 @@
#define BOOTUTIL_CRYPTO_AES_CTR_BLOCK_SIZE TC_AES_BLOCK_SIZE
#endif /* MCUBOOT_USE_TINYCRYPT */


#if defined(MCUBOOT_USE_PSA_CRYPTO)
#include <psa/crypto.h>
#include "bootutil/enc_key_public.h"
#define BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE BOOT_ENC_KEY_SIZE
#define BOOTUTIL_CRYPTO_AES_CTR_BLOCK_SIZE (16)
#endif

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#if defined(MCUBOOT_USE_PSA_CRYPTO)
typedef struct {
/* Fixme: This should not be, here, psa_key_id should be passed */
uint8_t key[BOOT_ENC_KEY_SIZE];
} bootutil_aes_ctr_context;

void bootutil_aes_ctr_init(bootutil_aes_ctr_context *ctx);

static inline void bootutil_aes_ctr_drop(bootutil_aes_ctr_context *ctx)
{
memset(ctx, 0, sizeof(ctx));
}

static inline int bootutil_aes_ctr_set_key(bootutil_aes_ctr_context *ctx, const uint8_t *k)
{
memcpy(ctx->key, k, sizeof(ctx->key));

return 0;
}

int bootutil_aes_ctr_encrypt(bootutil_aes_ctr_context *ctx, uint8_t *counter,
const uint8_t *m, uint32_t mlen, size_t blk_off, uint8_t *c);
int bootutil_aes_ctr_decrypt(bootutil_aes_ctr_context *ctx, uint8_t *counter,
const uint8_t *c, uint32_t clen, size_t blk_off, uint8_t *m);
#endif

#if defined(MCUBOOT_USE_MBED_TLS)
typedef mbedtls_aes_context bootutil_aes_ctr_context;
static inline void bootutil_aes_ctr_init(bootutil_aes_ctr_context *ctx)
Expand Down
64 changes: 58 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,6 @@ 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
/*
* 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 +183,8 @@ static int bootutil_decode_sig(uint8_t signature[NUM_ECC_BYTES * 2], uint8_t *cp
}
return 0;
}
#endif /* not MCUBOOT_ECDSA_NEED_ASN1_SIG */

#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 +253,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 @@ -613,6 +622,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
47 changes: 43 additions & 4 deletions boot/bootutil/include/bootutil/crypto/sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@

#if (defined(MCUBOOT_USE_PSA_OR_MBED_TLS) + \
defined(MCUBOOT_USE_TINYCRYPT) + \
defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO) + \
defined(MCUBOOT_USE_CC310)) != 1
#error "One crypto backend must be defined: either CC310/MBED_TLS/TINYCRYPT/PSA_CRYPTO"
#endif

#if defined(MCUBOOT_SIGN_EC384)
#if defined(MCUBOOT_SHA512)
#define IMAGE_HASH_SIZE (64)
#define EXPECTED_HASH_TLV IMAGE_TLV_SHA512
#elif 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 */
#endif /* MCUBOOT_SIGN */

/* Universal defines for SHA-256 */
#define BOOTUTIL_CRYPTO_SHA256_BLOCK_SIZE (64)
Expand Down Expand Up @@ -82,7 +86,9 @@ typedef psa_hash_operation_t bootutil_sha_context;
static inline int bootutil_sha_init(bootutil_sha_context *ctx)
{
*ctx = psa_hash_operation_init();
#if defined(MCUBOOT_SIGN_EC384)
#if defined(MCUBOOT_SHA512)
psa_status_t status = psa_hash_setup(ctx, PSA_ALG_SHA_512);
#elif 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);
Expand All @@ -107,7 +113,9 @@ static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
{
size_t hash_length = 0;
/* Assumes the output buffer is at least the expected size of the hash */
#if defined(MCUBOOT_SIGN_EC384)
#if defined(MCUBOOT_SHA512)
return (int)psa_hash_finish(ctx, output, PSA_HASH_LENGTH(PSA_ALG_SHA_512), &hash_length);
#elif 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);
Expand Down Expand Up @@ -206,6 +214,37 @@ static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
}
#endif /* MCUBOOT_USE_CC310 */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)

#include <bl_crypto.h>

typedef bl_sha256_ctx_t bootutil_sha_context;

static inline void bootutil_sha_init(bootutil_sha_context *ctx)
{
bl_sha256_init(ctx);
}

static inline void bootutil_sha_drop(bootutil_sha_context *ctx)
{
(void)ctx;
}

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

static inline int bootutil_sha_finish(bootutil_sha_context *ctx,
uint8_t *output)
{
bl_sha256_finalize(ctx, output);
return 0;
}
#endif /* MCUBOOT_USE_NRF_EXTERNAL_CRYPTO */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion boot/bootutil/include/bootutil/enc_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ int boot_enc_load(struct enc_key_data *enc_state, int slot,
const struct image_header *hdr, const struct flash_area *fap,
struct boot_status *bs);
bool boot_enc_valid(struct enc_key_data *enc_state, int slot);
void boot_encrypt(struct enc_key_data *enc_state, int slot,
void boot_enc_encrypt(struct enc_key_data *enc_state, int slot,
uint32_t off, uint32_t sz, uint32_t blk_off, uint8_t *buf);
void boot_enc_decrypt(struct enc_key_data *enc_state, int slot,
uint32_t off, uint32_t sz, uint32_t blk_off, uint8_t *buf);
void boot_enc_zeroize(struct enc_key_data *enc_state);

Expand Down
4 changes: 4 additions & 0 deletions boot/bootutil/include/bootutil/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ struct flash_area;
#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_SHA512 0x12 /* SHA512 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 */
#define IMAGE_TLV_RSA3072_PSS 0x23 /* RSA3072 of hash output */
#define IMAGE_TLV_ED25519 0x24 /* ed25519 of hash output */
#define IMAGE_TLV_SIG_PURE 0x25 /* Whatever signature has been selected, it will be used
* as "pure" where signature is verified over entire
* image rather than hash of an image */
#define IMAGE_TLV_ENC_RSA2048 0x30 /* Key encrypted with RSA-OAEP-2048 */
#define IMAGE_TLV_ENC_KW 0x31 /* Key encrypted with AES-KW 128 or 256*/
#define IMAGE_TLV_ENC_EC256 0x32 /* Key encrypted with ECIES-EC256 */
Expand Down
3 changes: 3 additions & 0 deletions boot/bootutil/src/bootutil_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ struct boot_loader_state {
fih_ret bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig,
size_t slen, uint8_t key_id);

fih_ret bootutil_verify_img(const uint8_t *img, uint32_t size,
uint8_t *sig, size_t slen, uint8_t key_id);

fih_ret boot_fih_memequal(const void *s1, const void *s2, size_t n);

int boot_find_status(int image_index, const struct flash_area **fap);
Expand Down
Loading
Loading