-
Notifications
You must be signed in to change notification settings - Fork 251
Add support for AES plain encryption + with all additional needed changes #586
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
Draft
de-nordic
wants to merge
18
commits into
nrfconnect:main
Choose a base branch
from
de-nordic:aes-plain
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+620
−346
Draft
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
115c7bc
[nrf fromtree] imgtool: support producing images in test mode
danieldegrasse 530f60f
[nrf fromtree] bootutil: Refactor boot_read_enc_key
de-nordic 00656da
[nrf fromtree] bootutil: In boot_swap_image add return check from boo…
de-nordic 278e1f7
[nrf fromtree] boot: zephyr: Allow disabling default multiple RAM reg…
nordicjm 1f0ad35
[nrf fromtree] boot: zephyr: Remove weird custom key directory handling
thedjnK 1825735
[nrf fromtree] boot: zephyr: kconfig: Only show signature file when n…
thedjnK 014e1e0
[nrf fromtree] bootutil: Split header with encryption functions
de-nordic 728deab
[nrf fromtree] bootutil: Allow using psa_key_id_t in AES crypto context
de-nordic a04481e
[nrf fromtree] bootutil: Add boot_loader_state_init
de-nordic 8215f7b
[nrf fromtree] boot_serial: Initialize state with boot_state_init
de-nordic 4cf9c00
[nrf fromtree] bootutil: Use boot_state_init instead of boot_state_clear
de-nordic 53e3ad3
[nrf fromtree] bootutil: Remove NULL state logic from boot_state_clear
de-nordic 6a8c5fc
[nrf fromtree] bootutil: Fix encryption context de initialization in …
de-nordic 0812a81
[nrf fromtree] bootutil: Temporarly drop mem cleanup from boot_state_…
de-nordic d8bcee0
[nrf noup] imgtool: Add support for encrypting image with raw AES key
de-nordic b37f991
[nrf noup] bootutil: Provide support for embedded AES keys
de-nordic f308c37
[nrf noup] zephyr: Add support for embedded AES key
de-nordic 894ec54
[nrf noup] bootutil: Use boot_state_init/clear in loader manifest
de-nordic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * This module provides a thin abstraction over some of the crypto | ||
| * primitives to make it easier to swap out the used crypto library. | ||
| * | ||
| * At this point, there are two choices: MCUBOOT_USE_MBED_TLS, or | ||
| * MCUBOOT_USE_TINYCRYPT. It is a compile error there is not exactly | ||
| * one of these defined. | ||
| */ | ||
|
|
||
| #ifndef __BOOTUTIL_CRYPTO_AES_CTR_MBEDTLS_H_ | ||
| #define __BOOTUTIL_CRYPTO_AES_CTR_MBEDTLS_H_ | ||
|
|
||
| #include <string.h> | ||
| #include <stdint.h> | ||
| #include "mcuboot_config/mcuboot_config.h" | ||
| #include "bootutil/enc_key_public.h" | ||
| #include <mbedtls/aes.h> | ||
|
|
||
| #define BOOT_ENC_BLOCK_SIZE (16) | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| typedef mbedtls_aes_context bootutil_aes_ctr_context; | ||
|
|
||
| static inline void bootutil_aes_ctr_init(bootutil_aes_ctr_context *ctx) | ||
| { | ||
| (void)mbedtls_aes_init(ctx); | ||
| } | ||
|
|
||
| static inline void bootutil_aes_ctr_drop(bootutil_aes_ctr_context *ctx) | ||
| { | ||
| mbedtls_aes_free(ctx); | ||
| } | ||
|
|
||
| static inline int bootutil_aes_ctr_set_key(bootutil_aes_ctr_context *ctx, const uint8_t *k) | ||
| { | ||
| return mbedtls_aes_setkey_enc(ctx, k, BOOT_ENC_KEY_SIZE * 8); | ||
| } | ||
|
|
||
| static inline 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) | ||
| { | ||
| uint8_t stream_block[BOOT_ENC_BLOCK_SIZE]; | ||
| return mbedtls_aes_crypt_ctr(ctx, mlen, &blk_off, counter, stream_block, m, c); | ||
| } | ||
|
|
||
| static inline 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) | ||
| { | ||
| uint8_t stream_block[BOOT_ENC_BLOCK_SIZE]; | ||
| return mbedtls_aes_crypt_ctr(ctx, clen, &blk_off, counter, stream_block, c, m); | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __BOOTUTIL_CRYPTO_AES_CTR_MBEDTLS_H_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * This module provides a thin abstraction over some of the crypto | ||
| * primitives to make it easier to swap out the used crypto library. | ||
| * | ||
| * At this point, there are two choices: MCUBOOT_USE_MBED_TLS, or | ||
| * MCUBOOT_USE_TINYCRYPT. It is a compile error there is not exactly | ||
| * one of these defined. | ||
| */ | ||
|
|
||
| #ifndef __BOOTUTIL_CRYPTO_AES_CTR_PSA_H_ | ||
| #define __BOOTUTIL_CRYPTO_AES_CTR_PSA_H_ | ||
|
|
||
| #include <string.h> | ||
| #include <stdint.h> | ||
| #include "mcuboot_config/mcuboot_config.h" | ||
| #include "bootutil/enc_key_public.h" | ||
| #include <psa/crypto.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| typedef struct { | ||
| psa_key_id_t key; | ||
| } bootutil_aes_ctr_context; | ||
|
|
||
| void bootutil_aes_ctr_init(bootutil_aes_ctr_context *ctx); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be great to see some docs for these functions.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in commit directly taken from upstream. |
||
|
|
||
| void bootutil_aes_ctr_drop(bootutil_aes_ctr_context *ctx); | ||
| int bootutil_aes_ctr_set_key(bootutil_aes_ctr_context *ctx, const uint8_t *k); | ||
|
|
||
| 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); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __BOOTUTIL_CRYPTO_AES_CTR_H_ */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * This module provides a thin abstraction over some of the crypto | ||
| * primitives to make it easier to swap out the used crypto library. | ||
| * | ||
| * At this point, there are two choices: MCUBOOT_USE_MBED_TLS, or | ||
| * MCUBOOT_USE_TINYCRYPT. It is a compile error there is not exactly | ||
| * one of these defined. | ||
| */ | ||
|
|
||
| #ifndef __BOOTUTIL_CRYPTO_AES_CTR_TINYCRYPT_H_ | ||
| #define __BOOTUTIL_CRYPTO_AES_CTR_TINYCRYPT_H_ | ||
|
|
||
| #include <string.h> | ||
| #include <stdint.h> | ||
| #include "mcuboot_config/mcuboot_config.h" | ||
| #include "bootutil/enc_key_public.h" | ||
|
|
||
| #include <tinycrypt/aes.h> | ||
| #include <tinycrypt/ctr_mode.h> | ||
| #include <tinycrypt/constants.h> | ||
|
|
||
| #if defined(MCUBOOT_AES_256) || (BOOT_ENC_KEY_SIZE != TC_AES_KEY_SIZE) | ||
| #error "Cannot use AES-256 for encryption with Tinycrypt library." | ||
| #endif | ||
|
|
||
| #define BOOT_ENC_BLOCK_SIZE TC_AES_BLOCK_SIZE | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| typedef struct tc_aes_key_sched_struct bootutil_aes_ctr_context; | ||
| static inline void bootutil_aes_ctr_init(bootutil_aes_ctr_context *ctx) | ||
| { | ||
| (void)ctx; | ||
| } | ||
|
|
||
| static inline void bootutil_aes_ctr_drop(bootutil_aes_ctr_context *ctx) | ||
| { | ||
| (void)ctx; | ||
| } | ||
|
|
||
| static inline int bootutil_aes_ctr_set_key(bootutil_aes_ctr_context *ctx, const uint8_t *k) | ||
| { | ||
| int rc; | ||
| rc = tc_aes128_set_encrypt_key(ctx, k); | ||
| if (rc != TC_CRYPTO_SUCCESS) { | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| static int common_bootutil_aes_ctr_crypt(bootutil_aes_ctr_context *ctx, uint8_t *counter, const uint8_t *in, uint32_t inlen, uint32_t blk_off, uint8_t *out) | ||
| { | ||
| int rc; | ||
| rc = tc_ctr_mode(out, inlen, in, inlen, counter, &blk_off, ctx); | ||
| if (rc != TC_CRYPTO_SUCCESS) { | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| static inline int bootutil_aes_ctr_encrypt(bootutil_aes_ctr_context *ctx, uint8_t *counter, const uint8_t *m, uint32_t mlen, uint32_t blk_off, uint8_t *c) | ||
| { | ||
| return common_bootutil_aes_ctr_crypt(ctx, counter, m, mlen, blk_off, c); | ||
| } | ||
|
|
||
| static inline int bootutil_aes_ctr_decrypt(bootutil_aes_ctr_context *ctx, uint8_t *counter, const uint8_t *c, uint32_t clen, uint32_t blk_off, uint8_t *m) | ||
| { | ||
| return common_bootutil_aes_ctr_crypt(ctx, counter, c, clen, blk_off, m); | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __BOOTUTIL_CRYPTO_AES_CTR_TINYCRYPT_H_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't that be
boot_take_enc_key?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh. I can not figure out how come I keep on bringing this bug. I thought that I have already fixed this two times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is in upstream again. I think I have messed up moving commits. Need to look through what ales get broken.