Skip to content

Commit 0636e7d

Browse files
committed
Added option WOLFBOOT_UNIVERSAL_KEYSTORE
- Allows keys with different algorithms and sizes to be imported/generated - Skips check for keys matching type/length in keystore
1 parent 04c8e89 commit 0636e7d

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

include/wolfboot/wolfboot.h

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,35 +175,53 @@ extern "C" {
175175
/* Authentication configuration */
176176
#if defined(WOLFBOOT_NO_SIGN)
177177
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_NONE
178-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_NONE
178+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
179+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_NONE
180+
# endif
179181
#elif defined(WOLFBOOT_SIGN_ED25519)
180182
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_ED25519
181-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ED25519
183+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
184+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ED25519
185+
# endif
182186
#elif defined(WOLFBOOT_SIGN_ED448)
183187
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_ED448
184-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ED448
188+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
189+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ED448
190+
# endif
185191
#elif defined(WOLFBOOT_SIGN_ECC256)
186192
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_ECC256
187-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC256
193+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
194+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC256
195+
# endif
188196
#elif defined(WOLFBOOT_SIGN_ECC384)
189197
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_ECC384
190-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC384
198+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
199+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_ECC384
200+
# endif
191201
#elif defined(WOLFBOOT_SIGN_ECC521)
192202
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_ECC521
193203
# error "ECC521 curves not yet supported in this version of wolfBoot. " \
194204
"Please select a valid SIGN= option."
195205
#elif defined(WOLFBOOT_SIGN_RSA2048)
196206
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_RSA2048
197-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_RSA2048
207+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
208+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_RSA2048
209+
# endif
198210
#elif defined(WOLFBOOT_SIGN_RSA3072)
199211
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_RSA3072
200-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_RSA3072
212+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
213+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_RSA3072
214+
# endif
201215
#elif defined(WOLFBOOT_SIGN_RSA4096)
202216
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_RSA4096
203-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_RSA4096
217+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
218+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_RSA4096
219+
# endif
204220
#elif defined(WOLFBOOT_SIGN_LMS)
205221
# define HDR_IMG_TYPE_AUTH HDR_IMG_TYPE_AUTH_LMS
206-
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_LMS
222+
# ifndef WOLFBOOT_UNIVERSAL_KEYSTORE
223+
# define KEYSTORE_PUBKEY_SIZE KEYSTORE_PUBKEY_SIZE_LMS
224+
# endif
207225
#else
208226
# error "No valid authentication mechanism selected. " \
209227
"Please select a valid SIGN= option."

options.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ ifeq ($(64BIT),1)
657657
CFLAGS+=-DWOLFBOOT_64BIT
658658
endif
659659

660+
ifeq ($(WOLFBOOT_UNIVERSAL_KEYSTORE),1)
661+
CFLAGS+=-DWOLFBOOT_UNIVERSAL_KEYSTORE
662+
endif
663+
660664
ifeq ($(DISK_LOCK),1)
661665
CFLAGS+=-DWOLFBOOT_ATA_DISK_LOCK
662666
ifneq ($(DISK_LOCK_PASSWORD),)

tools/config.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ifeq ($(ARCH),)
5353
MEASURED_BOOT?=0
5454
WOLFBOOT_TPM_SEAL?=0
5555
WOLFBOOT_TPM_KEYSTORE?=0
56+
WOLFBOOT_UNIVERSAL_KEYSTORE?=0
5657
TZEN?=0
5758
WOLFCRYPT_TZ?=0
5859
WOLFCRYPT_TZ_PKCS11?=0
@@ -91,4 +92,5 @@ CONFIG_VARS:= ARCH TARGET SIGN HASH MCUXSDK MCUXPRESSO MCUXPRESSO_CPU MCUXPRESSO
9192
WOLFBOOT_HUGE_STACK FORCE_32BIT\
9293
ENCRYPT_WITH_CHACHA ENCRYPT_WITH_AES128 ENCRYPT_WITH_AES256 ARMORED \
9394
LMS_LEVELS LMS_HEIGHT LMS_WINTERNITZ \
95+
WOLFBOOT_UNIVERSAL_KEYSTORE \
9496
ELF

tools/keytools/keygen.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int force = 0;
9898
static WC_RNG rng;
9999

100100
#ifndef KEYSLOT_MAX_PUBKEY_SIZE
101-
#define KEYSLOT_MAX_PUBKEY_SIZE 2048
101+
#define KEYSLOT_MAX_PUBKEY_SIZE 576
102102
#endif
103103

104104
struct keystore_slot {
@@ -263,6 +263,16 @@ const char KName[][8] = {
263263
"LMS"
264264
};
265265

266+
#define MAX_PUBKEYS 64
267+
#define MAX_KEYPAIRS 64
268+
static char *imported_pubkeys[MAX_PUBKEYS];
269+
static int imported_pubkeys_type[MAX_PUBKEYS];
270+
static int n_imported = 0;
271+
272+
static char *generated_keypairs[MAX_KEYPAIRS];
273+
static int generated_keypairs_type[MAX_KEYPAIRS];
274+
static int n_generated = 0;
275+
266276
static uint32_t get_pubkey_size(uint32_t keyType)
267277
{
268278
uint32_t size = 0;
@@ -776,11 +786,17 @@ int main(int argc, char** argv)
776786
key_gen_check(argv[i + 1]);
777787
i++;
778788
n_pubkeys++;
789+
generated_keypairs[n_generated] = argv[i];
790+
generated_keypairs_type[n_generated] = keytype;
791+
n_generated++;
779792
continue;
780793
}
781794
else if (strcmp(argv[i], "-i") == 0) {
782795
i++;
783796
n_pubkeys++;
797+
imported_pubkeys[n_imported] = argv[i];
798+
imported_pubkeys_type[n_imported] = keytype;
799+
n_imported++;
784800
continue;
785801
}
786802
else if (strcmp(argv[i], "-keystoreDir") == 0) {
@@ -811,17 +827,12 @@ int main(int argc, char** argv)
811827
wc_InitRng(&rng);
812828
fprintf(fpub, Cfile_Banner, KName[keytype]);
813829
fprintf(fpub, Store_hdr, n_pubkeys);
814-
for (i = 1; i < argc - 1; i++) {
815-
if (strcmp(argv[i], "-i") == 0) {
816-
printf("Imp %s\n", argv[i + 1]);
817-
key_import(keytype, argv[i + 1]);
818-
i++;
819-
}
820-
else if (strcmp(argv[i], "-g") == 0) {
821-
printf("Gen %s\n", argv[i + 1]);
822-
key_generate(keytype, argv[i + 1]);
823-
i++;
824-
}
830+
831+
for (i = 0; i < n_imported; i++) {
832+
key_import(imported_pubkeys_type[i], imported_pubkeys[i]);
833+
}
834+
for (i = 0; i < n_generated; i++) {
835+
key_generate(generated_keypairs_type[i], generated_keypairs[i]);
825836
}
826837
wc_FreeRng(&rng);
827838
fprintf(fpub, Store_footer);

0 commit comments

Comments
 (0)