blob: ab403ddc38b87f68f018b17abb78c435a600a62c [file] [log] [blame]
David Brown5153bd62017-01-06 11:16:53 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#include <bootutil/sign_key.h>
21
Marti Bolivara4818a52018-04-12 13:02:38 -040022/*
23 * Even though this is in principle a Zephyr-specific file, the
24 * simulator builds it and uses it as well. Because of that, we can't
25 * use Kconfig symbols for key types, and have to rely on the MCUBoot
26 * symbols (which Zephyr provides via this header, and the simulator
27 * provides via the compiler command line).
28 */
29#include <mcuboot_config/mcuboot_config.h>
30
David Vincze03368b82020-04-01 12:53:53 +020031#if !defined(MCUBOOT_HW_KEY)
Jamie McCrae25d2f2c2023-07-17 14:17:53 +010032#if defined(MCUBOOT_SIGN_RSA) || defined(MCUBOOT_SIGN_EC256) || defined(MCUBOOT_SIGN_ED25519)
Marti Bolivara4818a52018-04-12 13:02:38 -040033#define HAVE_KEYS
Jamie McCrae25d2f2c2023-07-17 14:17:53 +010034#if defined(MCUBOOT_SIGN_RSA)
Fabio Utzig806af0e2018-04-26 10:53:54 -030035extern const unsigned char rsa_pub_key[];
36extern unsigned int rsa_pub_key_len;
Fabio Utzig19356bf2017-05-11 16:19:36 -030037#elif defined(MCUBOOT_SIGN_EC256)
Fabio Utzig806af0e2018-04-26 10:53:54 -030038extern const unsigned char ecdsa_pub_key[];
39extern unsigned int ecdsa_pub_key_len;
Fabio Utzig1171df92019-05-10 19:26:38 -030040#elif defined(MCUBOOT_SIGN_ED25519)
Fabio Utzig1171df92019-05-10 19:26:38 -030041extern const unsigned char ed25519_pub_key[];
42extern unsigned int ed25519_pub_key_len;
David Brown3869e762017-02-02 08:10:23 -070043#endif
Jamie McCrae25d2f2c2023-07-17 14:17:53 +010044#endif
David Brown5153bd62017-01-06 11:16:53 -070045
Fabio Utzig806af0e2018-04-26 10:53:54 -030046/*
47 * NOTE: *_pub_key and *_pub_key_len are autogenerated based on the provided
48 * key file. If no key file was configured, the array and length must be
49 * provided and added to the build manually.
50 */
Marti Bolivara4818a52018-04-12 13:02:38 -040051#if defined(HAVE_KEYS)
David Brown5153bd62017-01-06 11:16:53 -070052const struct bootutil_key bootutil_keys[] = {
David Brown0d0652a2017-04-11 17:33:30 -060053 {
Fabio Utzig806af0e2018-04-26 10:53:54 -030054#if defined(MCUBOOT_SIGN_RSA)
55 .key = rsa_pub_key,
56 .len = &rsa_pub_key_len,
57#elif defined(MCUBOOT_SIGN_EC256)
58 .key = ecdsa_pub_key,
59 .len = &ecdsa_pub_key_len,
Fabio Utzig1171df92019-05-10 19:26:38 -030060#elif defined(MCUBOOT_SIGN_ED25519)
61 .key = ed25519_pub_key,
62 .len = &ed25519_pub_key_len,
Fabio Utzig806af0e2018-04-26 10:53:54 -030063#endif
David Brown0d0652a2017-04-11 17:33:30 -060064 },
David Brown5153bd62017-01-06 11:16:53 -070065};
66const int bootutil_key_cnt = 1;
David Vincze03368b82020-04-01 12:53:53 +020067#endif /* HAVE_KEYS */
68#else
69unsigned int pub_key_len;
70struct bootutil_key bootutil_keys[1] = {
71 {
72 .key = 0,
73 .len = &pub_key_len,
74 }
75};
76const int bootutil_key_cnt = 1;
77#endif /* !MCUBOOT_HW_KEY */
Fabio Utzig5fe874c2018-08-31 07:41:50 -030078
Jamie McCrae25d2f2c2023-07-17 14:17:53 +010079#if defined(MCUBOOT_ENCRYPT_RSA) || defined(MCUBOOT_ENCRYPT_X25519) || defined(MCUBOOT_ENCRYPT_EC256)
Wouter Cappelle953a7612021-05-03 16:53:05 +020080extern const unsigned char enc_priv_key[];
81extern unsigned int enc_priv_key_len;
Fabio Utzig42cc29a2019-11-05 07:54:41 -030082const struct bootutil_key bootutil_enc_key = {
83 .key = enc_priv_key,
84 .len = &enc_priv_key_len,
85};
Fabio Utzig5fe874c2018-08-31 07:41:50 -030086#elif defined(MCUBOOT_ENCRYPT_KW)
87#error "Encrypted images with AES-KW is not implemented yet."
88#endif