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 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 31 #if !defined(MCUBOOT_HW_KEY) 32 #if defined(MCUBOOT_SIGN_RSA) || defined(MCUBOOT_SIGN_EC256) || defined(MCUBOOT_SIGN_ED25519) 33 #define HAVE_KEYS 34 #if defined(MCUBOOT_SIGN_RSA) 35 extern const unsigned char rsa_pub_key[]; 36 extern unsigned int rsa_pub_key_len; 37 #elif defined(MCUBOOT_SIGN_EC256) 38 extern const unsigned char ecdsa_pub_key[]; 39 extern unsigned int ecdsa_pub_key_len; 40 #elif defined(MCUBOOT_SIGN_ED25519) 41 extern const unsigned char ed25519_pub_key[]; 42 extern unsigned int ed25519_pub_key_len; 43 #endif 44 #endif 45 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 */ 51 #if defined(HAVE_KEYS) 52 const struct bootutil_key bootutil_keys[] = { 53 { 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, 60 #elif defined(MCUBOOT_SIGN_ED25519) 61 .key = ed25519_pub_key, 62 .len = &ed25519_pub_key_len, 63 #endif 64 }, 65 }; 66 const int bootutil_key_cnt = 1; 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 */ 78 79 #if defined(MCUBOOT_ENCRYPT_RSA) || defined(MCUBOOT_ENCRYPT_X25519) || defined(MCUBOOT_ENCRYPT_EC256) 80 extern const unsigned char enc_priv_key[]; 81 extern unsigned int enc_priv_key_len; 82 const struct bootutil_key bootutil_enc_key = { 83 .key = enc_priv_key, 84 .len = &enc_priv_key_len, 85 }; 86 #elif defined(MCUBOOT_ENCRYPT_KW) 87 #error "Encrypted images with AES-KW is not implemented yet." 88 #endif 89