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

Do Not Review, Do Not Merge: Prototype for single file PSA/Legacy Mbed TLS configs #289

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cf90d55
[nrf noup] zephyr: Remove duplication from cmake
sigvartmh Mar 26, 2019
5b6e0b2
[nrf noup] boot: add 'minimal' configuration files
mbolivar-nordic Sep 3, 2021
74bb73a
[nrf noup] boot: zephyr: add support for Thingy:91
bjda Sep 20, 2019
4c1d75f
[nrf noup] boot: zephyr: Enable zeroize ALT func
Vge0rge Feb 3, 2022
8ba5c7f
[nrf noup] Restore default RTC user channel count
Damian-Nordic Mar 21, 2022
39f179d
[nrf noup] ci: add downstream-only NCS customizations
thst-nordic Nov 23, 2018
e02925a
[nrf noup] bootutil: loader: work-around for multi-image builds
sigvartmh Mar 30, 2021
16fd63c
[nrf noup] treewide: add NCS partition manager support
SebastianBoe Dec 12, 2018
5f71e80
[nrf noup] boot: bootutil: Add shared crypto for ECDSA and SHA
sigvartmh Feb 14, 2019
0030544
[nrf noup] boot: nrf53-specific customizations
sigvartmh Aug 27, 2020
1f14ccb
[nrf noup] do_boot: clean peripherals state before boot
nvlsianpu Feb 27, 2020
a47c9c4
[nrf noup] zephyr: Clean up non-secure RAM if enabled
sigvartmh Jan 6, 2023
c8e7fbd
[nrf noup] zephyr: Set at least provide EXT_API
Vge0rge Nov 8, 2021
48ad055
[nrf noup] loader: Fix reading reset addr to support ext flash
chrta Feb 10, 2022
685c58e
[nrf noup] boot: bootutil: Add required signature decoding
de-nordic Apr 21, 2023
09bad48
[nrf noup] bootloader: mcuboot: Fix wrong use of if defined
osaether Jun 20, 2023
5777337
[nrf noup] Fix path variables
nordicjm Jul 11, 2023
815fa3a
[nrf noup] bootutil: Fix missing PCD define check
nordicjm Aug 31, 2023
52997e1
[nrf noup] boot: zephyr: Add ifdef protection for RAM locking
nordicjm Aug 31, 2023
a0c919b
[nrf fromtree] zephyr: Provide third image cases for direct image upload
de-nordic Sep 4, 2023
b518e13
[nrf noup] booutil: loader: Add support for NSIB and multi-image
sigvartmh May 31, 2023
0383b7c
[nrf noup] zephyr: Move partition manager definitions to pm_sysflash.h
de-nordic Aug 10, 2023
745cf4e
[nrf noup] booutil: loader: Fixup for NSIB and multi-image
sigvartmh Sep 15, 2023
5822244
[nrf noup] zephyr: Add support for three images
de-nordic Aug 11, 2023
4fe70b6
[nrf noup] booutil: loader: Do not check reset vector for XIP image
de-nordic Sep 22, 2023
100ea3d
[nrf fromtree] zephyr: Fix boot serial extensions
nordicjm Aug 29, 2023
1e6532a
[nrf fromtree] zephyr: Fall back to minimal C library
nordicjm Sep 12, 2023
ec0aa5f
[nrf fromtree] boot_serial: Fix include
nordicjm Sep 12, 2023
c15589e
[nrf fromtree] bootutil: Add mode for XIP with revert
nordicjm Sep 27, 2023
eb1ff87
[nrf fromtree] bootutil: Add shared data support for XIP with revert …
nordicjm Sep 27, 2023
d9ed9a6
[nrf noup] github: Add a commit tags check workflow
carlescufi Oct 10, 2023
9cd1de1
[nrf noup] zephyr: Add RAM flash configuration to cache for sysbuild
nordicjm Sep 18, 2023
862bca5
[nrf noup] sysflash: pm_sysflash: Fix incorrect define exclude for NSIB
sigvartmh Oct 16, 2023
01f17eb
[nrf noup] boot: zephyr: Boot even if EXT_ABI is not provided
sigvartmh Oct 17, 2023
4d9859a
[nrf noup] loader: Add firmware version check downgrade prevention
sigvartmh Sep 27, 2023
2891664
[nrf noup] crypto: ecdsa: Fix shared crypto MCUBoot EXT_ABI
sigvartmh Oct 10, 2023
adab597
[nrf noup] boards: thingy53: disable GPIO ISR support
nika-nordic Oct 9, 2023
ab8db16
[nrf noup] bootutil: Add usage of nrf_security
frkv Nov 2, 2023
0d6f667
Enabling RSA for BOOT_SIGNATURE_TYPE_RSA
frkv Dec 1, 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
19 changes: 19 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Backport
on:
pull_request:
types:
- closed
- labeled

jobs:
backport:
runs-on: ubuntu-18.04
name: Backport
steps:
- name: Backport Bot
uses: Gaurav0/[email protected]
with:
bot_username: NordicBuilder
bot_token: 151a9b45052f9ee8be5a59963d31ad7b92c3ecb5
bot_token_key: 67bb1f1f998d546859786a4088917c65415c0ebd
github_token: ${{ secrets.GITHUB_TOKEN }}
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'
57 changes: 57 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# All these sections are optional, edit this file as you like.
[general]
ignore=title-trailing-punctuation, T3, title-max-length, T1, body-hard-tab, B3, B1
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
verbosity = 3
# By default gitlint will ignore merge commits. Set to 'false' to disable.
ignore-merge-commits=true
# Enable debug mode (prints more output). Disabled by default
debug = false

# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
extra-path=../../zephyr/scripts/gitlint

[title-max-length-no-revert]
line-length=72

[body-min-line-count]
min-line-count=1

[body-max-line-count]
max-line-count=200

[title-starts-with-subsystem]
regex = ^(?!subsys:)(([^:]+):)(\s([^:]+):)*\s(.+)$

[title-must-not-contain-word]
# Comma-separated list of words that should not occur in the title. Matching is case
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
# will not cause a violation, but "WIP: my title" will.
words=wip

[title-match-regex]
# python like regex (https://docs.python.org/2/library/re.html) that the
# commit-msg title must be matched to.
# Note that the regex can contradict with other rules if not used correctly
# (e.g. title-must-not-contain-word).
#regex=^US[0-9]*

[max-line-length-with-exceptions]
# B1 = body-max-line-length
line-length=72

[body-min-length]
min-length=3

[body-is-missing]
# Whether to ignore this rule on merge commits (which typically only have a title)
# default = True
ignore-merge-commits=false

[body-changed-file-mention]
# List of files that need to be explicitly mentioned in the body when they are changed
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
#files=gitlint/rules.py,README.md
6 changes: 6 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Library("CI_LIB") _

def pipeline = new ncs.sdk_mcuboot.Main()

pipeline.run(JOB_NAME)

5 changes: 1 addition & 4 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@
#include "boot_serial/boot_serial.h"
#include "boot_serial_priv.h"
#include "mcuboot_config/mcuboot_config.h"

#ifdef MCUBOOT_ERASE_PROGRESSIVELY
#include "bootutil_priv.h"
#endif
#include "../src/bootutil_priv.h"

#ifdef MCUBOOT_ENC_IMAGES
#include "boot_serial/boot_serial_encryption.h"
Expand Down
1 change: 1 addition & 0 deletions boot/bootutil/include/bootutil/boot_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ enum mcuboot_mode {
MCUBOOT_MODE_UPGRADE_ONLY,
MCUBOOT_MODE_SWAP_USING_MOVE,
MCUBOOT_MODE_DIRECT_XIP,
MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT,
MCUBOOT_MODE_RAM_LOAD
};

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,11 +71,17 @@
#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)
#if defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || defined(MCUBOOT_USE_CC310) \
|| defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)
/*
* Declaring these like this adds NULL termination.
*/
Expand Down Expand Up @@ -126,8 +133,6 @@ static int bootutil_import_key(uint8_t **cp, uint8_t *end)
}
#endif /* MCUBOOT_USE_TINYCRYPT || MCUBOOT_USE_MBED_TLS || MCUBOOT_USE_CC310 */

#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 @@ -177,8 +182,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 @@ -247,16 +252,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 @@ -593,6 +602,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
32 changes: 32 additions & 0 deletions boot/bootutil/include/bootutil/crypto/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#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
Expand Down Expand Up @@ -188,6 +189,37 @@ static inline int bootutil_sha256_finish(bootutil_sha256_context *ctx,
}
#endif /* MCUBOOT_USE_CC310 */

#if defined(MCUBOOT_USE_NRF_EXTERNAL_CRYPTO)

#include <bl_crypto.h>

typedef bl_sha256_ctx_t bootutil_sha256_context;

static inline void bootutil_sha256_init(bootutil_sha256_context *ctx)
{
bl_sha256_init(ctx);
}

static inline void bootutil_sha256_drop(bootutil_sha256_context *ctx)
{
(void)ctx;
}

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

static inline int bootutil_sha256_finish(bootutil_sha256_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: 4 additions & 0 deletions boot/bootutil/src/boot_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
#elif defined(MCUBOOT_SWAP_USING_MOVE)
uint8_t mode = MCUBOOT_MODE_SWAP_USING_MOVE;
#elif defined(MCUBOOT_DIRECT_XIP)
#if defined(MCUBOOT_DIRECT_XIP_REVERT)
uint8_t mode = MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT;
#else
uint8_t mode = MCUBOOT_MODE_DIRECT_XIP;
#endif
#elif defined(MCUBOOT_RAM_LOAD)
uint8_t mode = MCUBOOT_MODE_RAM_LOAD;
#else
Expand Down
Loading
Loading