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

boot/bootutil: add the option to use custom definitions for all crypto inline functions #1870

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 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,9 @@
#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_CUSTOM_CRYPT)) != 1
#error "One crypto backend must be defined: either MBED_TLS, TINYCRYPT or CUSTOM_CRYPT"
#endif

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

#if defined (MCUBOOT_USE_CUSTOM_CRYPT)
#include "aes_ctr_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */

#include <stdint.h>

#ifdef __cplusplus
Expand Down
9 changes: 7 additions & 2 deletions boot/bootutil/include/bootutil/crypto/aes_kw.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#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_CUSTOM_CRYPT)) != 1
#error "One crypto backend must be defined: either MBED_TLS, TINYCRYPT or CUSTOM_CRYPT"
#endif

#if defined(MCUBOOT_USE_MBED_TLS)
Expand All @@ -30,6 +31,10 @@
#include <tinycrypt/constants.h>
#endif /* MCUBOOT_USE_TINYCRYPT */

#if defined (MCUBOOT_USE_CUSTOM_CRYPT)
#include "aes_kw_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */

#include <stdint.h>

#ifdef __cplusplus
Expand Down
8 changes: 6 additions & 2 deletions boot/bootutil/include/bootutil/crypto/ecdh_p256.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#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_CUSTOM_CRYPT)) != 1
#error "One crypto backend must be defined: either MBED_TLS, TINYCRYPT or CUSTOM_CRYPT"
#endif

#if defined(MCUBOOT_USE_MBED_TLS)
Expand All @@ -29,6 +30,9 @@
#define BOOTUTIL_CRYPTO_ECDH_P256_HASH_SIZE (4 * 8)
#endif /* MCUBOOT_USE_TINYCRYPT */

#if defined (MCUBOOT_USE_CUSTOM_CRYPT)
#include "ecdh_p256_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */
#ifdef __cplusplus
extern "C" {
#endif
Expand Down
8 changes: 6 additions & 2 deletions boot/bootutil/include/bootutil/crypto/ecdh_x25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
#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_CUSTOM_CRYPT)) != 1
#error "One crypto backend must be defined: either MBED_TLS, TINYCRYPT or CUSTOM_CRYPT"
#endif

#if defined(MCUBOOT_USE_CUSTOM_CRYPT)
#include "ecdh_x25519_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */
#ifdef __cplusplus
extern "C" {
#endif
Expand Down
11 changes: 8 additions & 3 deletions boot/bootutil/include/bootutil/crypto/ecdsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@

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

#if defined(MCUBOOT_USE_TINYCRYPT)
Expand All @@ -62,6 +63,10 @@
#define NUM_ECC_BYTES (256 / 8)
#endif

#if defined (MCUBOOT_USE_CUSTOM_CRYPT)
#include "ecdsa_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */

/* Universal defines */
#define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (32)

Expand All @@ -74,7 +79,7 @@
extern "C" {
#endif

#if (defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) || \
#if (defined(MCUBOOT_USE_TINYCRYPT) || defined(MCUBOOT_USE_MBED_TLS) ||\
defined(MCUBOOT_USE_CC310)) && !defined(MCUBOOT_USE_PSA_CRYPTO)
/*
* Declaring these like this adds NULL termination.
Expand Down
9 changes: 7 additions & 2 deletions boot/bootutil/include/bootutil/crypto/hmac_sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#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_CUSTOM_CRYPT)) != 1
#error "One crypto backend must be defined: either MBED_TLS, TINYCRYPT or CUSTOM_CRYPT"
#endif

#if defined(MCUBOOT_USE_MBED_TLS)
Expand All @@ -31,6 +32,10 @@
#include <tinycrypt/hmac.h>
#endif /* MCUBOOT_USE_TINYCRYPT */

#if defined (MCUBOOT_USE_CUSTOM_CRYPT)
#include "hmac_sha256_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */

#include <stdint.h>

#ifdef __cplusplus
Expand Down
5 changes: 4 additions & 1 deletion boot/bootutil/include/bootutil/crypto/rsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "mcuboot_config/mcuboot_config.h"

#if defined(MCUBOOT_USE_PSA_CRYPTO) || defined(MCUBOOT_USE_MBED_TLS)
#if defined(MCUBOOT_USE_PSA_CRYPTO) || defined(MCUBOOT_USE_MBED_TLS) || defined(MCUBOOT_USE_CUSTOM_CRYPT)
#define MCUBOOT_USE_PSA_OR_MBED_TLS
#endif /* MCUBOOT_USE_PSA_CRYPTO || MCUBOOT_USE_MBED_TLS */

Expand Down Expand Up @@ -57,6 +57,9 @@

#endif /* MCUBOOT_USE_MBED_TLS */

#if defined(MCUBOOT_USE_CUSTOM_CRYPT)
#include "rsa_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */
#include <stdint.h>

#ifdef __cplusplus
Expand Down
7 changes: 6 additions & 1 deletion boot/bootutil/include/bootutil/crypto/sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

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

Expand Down Expand Up @@ -69,6 +70,10 @@
#include <cc310_glue.h>
#endif /* MCUBOOT_USE_CC310 */

#if defined (MCUBOOT_USE_CUSTOM_CRYPT)
#include "sha_custom.h"
#endif /* MCUBOOT_USE_CUSTOM_CRYPT */

#include <stdint.h>

#ifdef __cplusplus
Expand Down