1 /*
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Copyright (c) 2017 Linaro Limited
5  * Copyright (c) 2021-2023 Arm Limited
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #include <bootutil/caps.h>
21 #include "mcuboot_config/mcuboot_config.h"
22 
bootutil_get_caps(void)23 uint32_t bootutil_get_caps(void)
24 {
25     uint32_t res = 0;
26 
27 #if defined(MCUBOOT_SIGN_RSA)
28 #if MCUBOOT_SIGN_RSA_LEN == 2048
29     res |= BOOTUTIL_CAP_RSA2048;
30 #endif
31 #if MCUBOOT_SIGN_RSA_LEN == 3072
32     res |= BOOTUTIL_CAP_RSA3072;
33 #endif
34 #endif
35 #if defined(MCUBOOT_SIGN_EC256)
36     res |= BOOTUTIL_CAP_ECDSA_P256;
37 #endif
38 #if defined(MCUBOOT_SIGN_EC384)
39     res |= BOOTUTIL_CAP_ECDSA_P384;
40 #endif
41 #if defined(MCUBOOT_SIGN_ED25519)
42     res |= BOOTUTIL_CAP_ED25519;
43 #endif
44 #if defined(MCUBOOT_OVERWRITE_ONLY)
45     res |= BOOTUTIL_CAP_OVERWRITE_UPGRADE;
46 #elif defined(MCUBOOT_SWAP_USING_MOVE)
47     res |= BOOTUTIL_CAP_SWAP_USING_MOVE;
48 #else
49     res |= BOOTUTIL_CAP_SWAP_USING_SCRATCH;
50 #endif
51 #if defined(MCUBOOT_ENCRYPT_RSA)
52     res |= BOOTUTIL_CAP_ENC_RSA;
53 #endif
54 #if defined(MCUBOOT_ENCRYPT_KW)
55     res |= BOOTUTIL_CAP_ENC_KW;
56 #endif
57 #if defined(MCUBOOT_ENCRYPT_EC256)
58     res |= BOOTUTIL_CAP_ENC_EC256;
59 #endif
60 #if defined(MCUBOOT_ENCRYPT_X25519)
61     res |= BOOTUTIL_CAP_ENC_X25519;
62 #endif
63 #if defined(MCUBOOT_VALIDATE_PRIMARY_SLOT)
64     res |= BOOTUTIL_CAP_VALIDATE_PRIMARY_SLOT;
65 #endif
66 #if defined(MCUBOOT_DOWNGRADE_PREVENTION)
67     res |= BOOTUTIL_CAP_DOWNGRADE_PREVENTION;
68 #endif
69 #if defined(MCUBOOT_BOOTSTRAP)
70     res |= BOOTUTIL_CAP_BOOTSTRAP;
71 #endif
72 #if defined(MCUBOOT_AES_256)
73     res |= BOOTUTIL_CAP_AES256;
74 #endif
75 #if defined(MCUBOOT_RAM_LOAD)
76     res |= BOOTUTIL_CAP_RAM_LOAD;
77 #endif
78 #if defined(MCUBOOT_DIRECT_XIP)
79     res |= BOOTUTIL_CAP_DIRECT_XIP;
80 #endif
81 #if defined(MCUBOOT_HW_ROLLBACK_PROT)
82     res |= BOOTUTIL_CAP_HW_ROLLBACK_PROT;
83 #endif
84 
85     return res;
86 }
87 
bootutil_get_num_images(void)88 uint32_t bootutil_get_num_images(void)
89 {
90 #if defined(MCUBOOT_IMAGE_NUMBER)
91     return MCUBOOT_IMAGE_NUMBER;
92 #else
93     return 1;
94 #endif
95 }
96