@@ -208,6 +208,12 @@ static int decrypt_header(const uint8_t *src, uint8_t *dst)
208208 return 0 ;
209209}
210210
211+ static void disk_crypto_clear (void )
212+ {
213+ ForceZero (disk_encrypt_key , sizeof (disk_encrypt_key ));
214+ ForceZero (disk_encrypt_nonce , sizeof (disk_encrypt_nonce ));
215+ }
216+
211217#endif /* DISK_ENCRYPT */
212218
213219extern int wolfBoot_get_dts_size (void * dts_addr );
@@ -254,11 +260,13 @@ void RAMFUNCTION wolfBoot_start(void)
254260#ifdef DISK_ENCRYPT
255261 /* Initialize encryption - this sets up the cipher with key from storage */
256262 if (wolfBoot_initialize_encryption () != 0 ) {
263+ disk_crypto_clear ();
257264 wolfBoot_printf ("Error initializing encryption\r\n" );
258265 wolfBoot_panic ();
259266 }
260267 /* Retrieve encryption key and nonce for disk decryption */
261268 if (wolfBoot_get_encrypt_key (disk_encrypt_key , disk_encrypt_nonce ) != 0 ) {
269+ disk_crypto_clear ();
262270 wolfBoot_printf ("Error getting encryption key\r\n" );
263271 wolfBoot_panic ();
264272 }
@@ -267,10 +275,16 @@ void RAMFUNCTION wolfBoot_start(void)
267275
268276 ret = disk_init (BOOT_DISK );
269277 if (ret != 0 ) {
278+ #ifdef DISK_ENCRYPT
279+ disk_crypto_clear ();
280+ #endif
270281 wolfBoot_panic ();
271282 }
272283
273284 if (disk_open (BOOT_DISK ) < 0 ) {
285+ #ifdef DISK_ENCRYPT
286+ disk_crypto_clear ();
287+ #endif
274288 wolfBoot_printf ("Error opening disk %d\r\n" , BOOT_DISK );
275289 wolfBoot_panic ();
276290 }
@@ -306,6 +320,9 @@ void RAMFUNCTION wolfBoot_start(void)
306320 }
307321
308322 if ((pB_ver == 0 ) && (pA_ver == 0 )) {
323+ #ifdef DISK_ENCRYPT
324+ disk_crypto_clear ();
325+ #endif
309326 wolfBoot_printf ("No valid OS image found in either partition %d or %d\r\n" ,
310327 BOOT_PART_A , BOOT_PART_B );
311328 wolfBoot_panic ();
@@ -409,6 +426,7 @@ void RAMFUNCTION wolfBoot_start(void)
409426 wolfBoot_printf ("Decrypting image..." );
410427 BENCHMARK_START ();
411428 if ((IMAGE_HEADER_SIZE % ENCRYPT_BLOCK_SIZE ) != 0 ) {
429+ disk_crypto_clear ();
412430 wolfBoot_printf ("Encrypted disk images require aligned header size\r\n" );
413431 wolfBoot_panic ();
414432 }
@@ -456,6 +474,9 @@ void RAMFUNCTION wolfBoot_start(void)
456474 } while (failures < MAX_FAILURES );
457475
458476 if (failures ) {
477+ #ifdef DISK_ENCRYPT
478+ disk_crypto_clear ();
479+ #endif
459480 wolfBoot_printf ("Unable to find a valid partition!\r\n" );
460481 wolfBoot_panic ();
461482 }
@@ -512,6 +533,9 @@ void RAMFUNCTION wolfBoot_start(void)
512533
513534#ifdef WOLFBOOT_HOOK_BOOT
514535 wolfBoot_hook_boot (& os_image );
536+ #endif
537+ #ifdef DISK_ENCRYPT
538+ disk_crypto_clear ();
515539#endif
516540 do_boot ((uint32_t * )load_address
517541 #ifdef MMU
0 commit comments