|
2 | 2 | * SPDX-License-Identifier: Apache-2.0 |
3 | 3 | * |
4 | 4 | * Copyright (c) 2023-2025 Arm Limited |
| 5 | + * Copyright (c) 2026 Infineon Technologies AG, or an affiliate of Infineon |
| 6 | + * Technologies AG |
5 | 7 | */ |
6 | 8 |
|
7 | 9 | /* |
8 | 10 | * This module provides a thin abstraction over some of the crypto |
9 | 11 | * primitives to make it easier to swap out the used crypto library. |
10 | 12 | * |
11 | 13 | * At this point, the choices are: MCUBOOT_USE_TINYCRYPT, MCUBOOT_USE_CC310, |
12 | | - * MCUBOOT_USE_MBED_TLS, MCUBOOT_USE_PSA_CRYPTO. Note that support for |
13 | | - * MCUBOOT_USE_PSA_CRYPTO is still experimental and it might not support all |
14 | | - * the crypto abstractions that MCUBOOT_USE_MBED_TLS supports. For this |
15 | | - * reason, it's allowed to have both of them defined, and for crypto modules |
16 | | - * that support both abstractions, the MCUBOOT_USE_PSA_CRYPTO will take |
17 | | - * precedence. |
| 14 | + * MCUBOOT_USE_MBED_TLS, MCUBOOT_USE_PSA_CRYPTO, MCUBOOT_USE_CUSTOM_CRYPTO. |
| 15 | + * Note that support for MCUBOOT_USE_PSA_CRYPTO is still experimental and it |
| 16 | + * might not support all the crypto abstractions that MCUBOOT_USE_MBED_TLS |
| 17 | + * supports. For this reason, it's allowed to have both of them defined, and |
| 18 | + * for crypto modules that support both abstractions, the MCUBOOT_USE_PSA_CRYPTO |
| 19 | + * will take precedence. MCUBOOT_USE_CUSTOM_CRYPTO delegates all operations to |
| 20 | + * a platform-supplied <mcuboot_custom_crypto.h> resolved via the include path. |
18 | 21 | */ |
19 | 22 |
|
20 | 23 | #ifndef __BOOTUTIL_CRYPTO_ECDSA_H_ |
|
27 | 30 | #define MCUBOOT_USE_PSA_OR_MBED_TLS |
28 | 31 | #endif /* MCUBOOT_USE_PSA_CRYPTO || MCUBOOT_USE_MBED_TLS */ |
29 | 32 |
|
| 33 | +#if defined(MCUBOOT_USE_CUSTOM_CRYPTO) && defined(MCUBOOT_USE_PSA_OR_MBED_TLS) |
| 34 | + #error "MCUBOOT_USE_CUSTOM_CRYPTO is mutually exclusive with MCUBOOT_USE_PSA_CRYPTO and MCUBOOT_USE_MBED_TLS" |
| 35 | +#endif |
| 36 | + |
30 | 37 | #if defined(MCUBOOT_SIGN_EC384) && \ |
31 | 38 | !defined(MCUBOOT_USE_PSA_CRYPTO) |
32 | 39 | #error "P384 requires PSA_CRYPTO to be defined" |
33 | 40 | #endif |
34 | 41 |
|
35 | 42 | #if (defined(MCUBOOT_USE_TINYCRYPT) + \ |
36 | 43 | defined(MCUBOOT_USE_CC310) + \ |
37 | | - defined(MCUBOOT_USE_PSA_OR_MBED_TLS)) != 1 |
38 | | - #error "One crypto backend must be defined: either CC310/TINYCRYPT/MBED_TLS/PSA_CRYPTO" |
| 44 | + defined(MCUBOOT_USE_PSA_OR_MBED_TLS) + \ |
| 45 | + defined(MCUBOOT_USE_CUSTOM_CRYPTO)) != 1 |
| 46 | + #error "One crypto backend must be defined: either CC310/TINYCRYPT/MBED_TLS/PSA_CRYPTO/CUSTOM_CRYPTO" |
39 | 47 | #endif |
40 | 48 |
|
41 | 49 | #if defined(MCUBOOT_USE_TINYCRYPT) |
|
47 | 55 | #include <cc310_glue.h> |
48 | 56 | #endif /* MCUBOOT_USE_CC310 */ |
49 | 57 |
|
| 58 | +#if defined(MCUBOOT_USE_CUSTOM_CRYPTO) |
| 59 | + #include "mcuboot_custom_crypto.h" |
| 60 | +#endif /* MCUBOOT_USE_CUSTOM_CRYPTO */ |
| 61 | + |
50 | 62 | #if defined(MCUBOOT_USE_PSA_CRYPTO) |
51 | 63 | #include <psa/crypto.h> |
52 | 64 | #include <string.h> |
|
66 | 78 | #define BOOTUTIL_CRYPTO_ECDSA_P256_HASH_SIZE (32) |
67 | 79 |
|
68 | 80 | #include "bootutil/sign_key.h" |
69 | | -#if !defined(MCUBOOT_USE_PSA_CRYPTO) |
| 81 | +#if !defined(MCUBOOT_USE_PSA_CRYPTO) && !defined(MCUBOOT_USE_CUSTOM_CRYPTO) |
70 | 82 | #include "bootutil/crypto/common.h" |
71 | 83 | #include "mbedtls/asn1.h" |
72 | 84 | #include "mbedtls/oid.h" |
@@ -615,6 +627,10 @@ static inline int bootutil_ecdsa_parse_public_key(bootutil_ecdsa_context *ctx, |
615 | 627 |
|
616 | 628 | #endif /* MCUBOOT_USE_MBED_TLS */ |
617 | 629 |
|
| 630 | +/* When MCUBOOT_USE_CUSTOM_CRYPTO is defined, bootutil_ecdsa_context and all |
| 631 | + * bootutil_ecdsa_* functions are provided by <mcuboot_custom_crypto.h> which is |
| 632 | + * included above via the platform-specific include path. */ |
| 633 | + |
618 | 634 | #ifdef __cplusplus |
619 | 635 | } |
620 | 636 | #endif |
|
0 commit comments