blob: cf4bd406406f73a28d6fc0138d9c9ebad537ddfa [file] [log] [blame]
George Becksteind82afbf2020-10-29 17:32:11 -04001/*
2 * Copyright (c) 2020 Embedded Planet
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License
16 */
17
18#include <bootutil/sign_key.h>
19#include <mcuboot_config/mcuboot_config.h>
20
21#if defined(MCUBOOT_SIGN_RSA)
22#define HAVE_KEYS
23extern const unsigned char rsa_pub_key[];
24extern unsigned int rsa_pub_key_len;
25#elif defined(MCUBOOT_SIGN_EC256)
26#define HAVE_KEYS
27extern const unsigned char ecdsa_pub_key[];
28extern unsigned int ecdsa_pub_key_len;
29#elif defined(MCUBOOT_SIGN_ED25519)
30#define HAVE_KEYS
31extern const unsigned char ed25519_pub_key[];
32extern unsigned int ed25519_pub_key_len;
33#else
34#error "No public key available for given signing algorithm."
35#endif
36
37/*
38 * Note: Keys for both signing and encryption must be provided by the application.
39 * mcuboot's imgtool utility can be used to generate these keys and convert them into compatible C code.
40 * See imgtool's documentation, specifically the section: "Incorporating the public key into the code" which can be found here:
41 * https://github.com/JuulLabs-OSS/mcuboot/blob/master/docs/imgtool.md#incorporating-the-public-key-into-the-code
42 */
43#if defined(HAVE_KEYS)
44const struct bootutil_key bootutil_keys[] = {
45 {
46#if defined(MCUBOOT_SIGN_RSA)
47 .key = rsa_pub_key,
48 .len = &rsa_pub_key_len,
49#elif defined(MCUBOOT_SIGN_EC256)
50 .key = ecdsa_pub_key,
51 .len = &ecdsa_pub_key_len,
52#elif defined(MCUBOOT_SIGN_ED25519)
53 .key = ed25519_pub_key,
54 .len = &ed25519_pub_key_len,
55#endif
56 },
57};
58const int bootutil_key_cnt = 1;
59
60#if defined(MCUBOOT_ENCRYPT_RSA)
61
62extern const unsigned char enc_priv_key[];
63extern const unsigned int enc_priv_key_len;
64
65const struct bootutil_key bootutil_enc_key = {
66 .key = enc_priv_key,
67 .len = &enc_priv_key_len,
68};
69#elif defined(MCUBOOT_ENCRYPT_KW)
70#error "Encrypted images with AES-KW is not implemented yet."
71#endif
72
73#endif