1 /*
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Copyright (c) 2018-2019 JUUL Labs
5  * Copyright (c) 2019-2021 Arm Limited
6  * Copyright (c) 2021 Nordic Semiconductor ASA
7  *
8  * Original license:
9  *
10  * Licensed to the Apache Software Foundation (ASF) under one
11  * or more contributor license agreements.  See the NOTICE file
12  * distributed with this work for additional information
13  * regarding copyright ownership.  The ASF licenses this file
14  * to you under the Apache License, Version 2.0 (the
15  * "License"); you may not use this file except in compliance
16  * with the License.  You may obtain a copy of the License at
17  *
18  *  http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing,
21  * software distributed under the License is distributed on an
22  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23  * KIND, either express or implied.  See the License for the
24  * specific language governing permissions and limitations
25  * under the License.
26  */
27 
28 #ifndef BOOTUTIL_ENC_KEY_PUBLIC_H
29 #define BOOTUTIL_ENC_KEY_PUBLIC_H
30 #include <mcuboot_config/mcuboot_config.h>
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef ALIGN_UP
36 #define ALIGN_UP(num, align)    (((num) + ((align) - 1)) & ~((align) - 1))
37 #endif
38 
39 #ifdef MCUBOOT_AES_256
40 #define BOOT_ENC_KEY_SIZE       32
41 #else
42 #define BOOT_ENC_KEY_SIZE       16
43 #endif
44 
45 #define BOOT_ENC_KEY_ALIGN_SIZE ALIGN_UP(BOOT_ENC_KEY_SIZE, BOOT_MAX_ALIGN)
46 
47 #define TLV_ENC_RSA_SZ    256
48 #define TLV_ENC_KW_SZ     (BOOT_ENC_KEY_SIZE + 8)
49 #define TLV_ENC_EC256_SZ  (65 + 32 + BOOT_ENC_KEY_SIZE)
50 #define TLV_ENC_X25519_SZ (32 + 32 + BOOT_ENC_KEY_SIZE)
51 
52 #if defined(MCUBOOT_ENCRYPT_RSA)
53 #define BOOT_ENC_TLV_SIZE TLV_ENC_RSA_SZ
54 #elif defined(MCUBOOT_ENCRYPT_EC256)
55 #define BOOT_ENC_TLV_SIZE TLV_ENC_EC256_SZ
56 #elif defined(MCUBOOT_ENCRYPT_X25519)
57 #define BOOT_ENC_TLV_SIZE TLV_ENC_X25519_SZ
58 #else
59 #define BOOT_ENC_TLV_SIZE TLV_ENC_KW_SZ
60 #endif
61 
62 #ifdef __cplusplus
63 }
64 #endif
65 
66 #endif /* BOOTUTIL_ENC_KEY_PUBLIC_H */
67