David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 1 | /* |
| 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 Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 22 | /* |
| 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 Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 31 | #if !defined(MCUBOOT_HW_KEY) |
Jamie McCrae | 25d2f2c | 2023-07-17 14:17:53 +0100 | [diff] [blame] | 32 | #if defined(MCUBOOT_SIGN_RSA) || defined(MCUBOOT_SIGN_EC256) || defined(MCUBOOT_SIGN_ED25519) |
Marti Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 33 | #define HAVE_KEYS |
Jamie McCrae | 25d2f2c | 2023-07-17 14:17:53 +0100 | [diff] [blame] | 34 | #if defined(MCUBOOT_SIGN_RSA) |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 35 | extern const unsigned char rsa_pub_key[]; |
| 36 | extern unsigned int rsa_pub_key_len; |
Fabio Utzig | 19356bf | 2017-05-11 16:19:36 -0300 | [diff] [blame] | 37 | #elif defined(MCUBOOT_SIGN_EC256) |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 38 | extern const unsigned char ecdsa_pub_key[]; |
| 39 | extern unsigned int ecdsa_pub_key_len; |
Fabio Utzig | 1171df9 | 2019-05-10 19:26:38 -0300 | [diff] [blame] | 40 | #elif defined(MCUBOOT_SIGN_ED25519) |
Fabio Utzig | 1171df9 | 2019-05-10 19:26:38 -0300 | [diff] [blame] | 41 | extern const unsigned char ed25519_pub_key[]; |
| 42 | extern unsigned int ed25519_pub_key_len; |
David Brown | 3869e76 | 2017-02-02 08:10:23 -0700 | [diff] [blame] | 43 | #endif |
Jamie McCrae | 25d2f2c | 2023-07-17 14:17:53 +0100 | [diff] [blame] | 44 | #endif |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 45 | |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 46 | /* |
| 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 Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 51 | #if defined(HAVE_KEYS) |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 52 | const struct bootutil_key bootutil_keys[] = { |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 53 | { |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 54 | #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 Utzig | 1171df9 | 2019-05-10 19:26:38 -0300 | [diff] [blame] | 60 | #elif defined(MCUBOOT_SIGN_ED25519) |
| 61 | .key = ed25519_pub_key, |
| 62 | .len = &ed25519_pub_key_len, |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 63 | #endif |
David Brown | 0d0652a | 2017-04-11 17:33:30 -0600 | [diff] [blame] | 64 | }, |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 65 | }; |
| 66 | const int bootutil_key_cnt = 1; |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 67 | #endif /* HAVE_KEYS */ |
| 68 | #else |
| 69 | unsigned int pub_key_len; |
| 70 | struct bootutil_key bootutil_keys[1] = { |
| 71 | { |
| 72 | .key = 0, |
| 73 | .len = &pub_key_len, |
| 74 | } |
| 75 | }; |
| 76 | const int bootutil_key_cnt = 1; |
| 77 | #endif /* !MCUBOOT_HW_KEY */ |
Fabio Utzig | 5fe874c | 2018-08-31 07:41:50 -0300 | [diff] [blame] | 78 | |
Jamie McCrae | 25d2f2c | 2023-07-17 14:17:53 +0100 | [diff] [blame] | 79 | #if defined(MCUBOOT_ENCRYPT_RSA) || defined(MCUBOOT_ENCRYPT_X25519) || defined(MCUBOOT_ENCRYPT_EC256) |
Wouter Cappelle | 953a761 | 2021-05-03 16:53:05 +0200 | [diff] [blame] | 80 | extern const unsigned char enc_priv_key[]; |
| 81 | extern unsigned int enc_priv_key_len; |
Fabio Utzig | 42cc29a | 2019-11-05 07:54:41 -0300 | [diff] [blame] | 82 | const struct bootutil_key bootutil_enc_key = { |
| 83 | .key = enc_priv_key, |
| 84 | .len = &enc_priv_key_len, |
| 85 | }; |
Fabio Utzig | 5fe874c | 2018-08-31 07:41:50 -0300 | [diff] [blame] | 86 | #elif defined(MCUBOOT_ENCRYPT_KW) |
| 87 | #error "Encrypted images with AES-KW is not implemented yet." |
| 88 | #endif |