3131#include "hal/stm32h5.h"
3232#include "uart_drv.h"
3333#include "wolfboot/wolfboot.h"
34- #include "wolfcrypt/benchmark/benchmark.h"
35- #include "wolfcrypt/test/test.h"
3634#include "keystore.h"
3735
3836#ifdef SECURE_PKCS11
3937#include "wcs/user_settings.h"
40- #include <wolfssl/wolfcrypt/settings.h>
41- #include <wolfssl/wolfcrypt/wc_pkcs11.h>
42- #include <wolfssl/wolfcrypt/random.h>
38+ #include "wolfssl/wolfcrypt/settings.h"
39+ #include "wolfssl/wolfcrypt/wc_pkcs11.h"
40+ #include "wolfssl/wolfcrypt/random.h"
41+ #include "wolfcrypt/benchmark/benchmark.h"
42+ #include "wolfcrypt/test/test.h"
4343extern const char pkcs11_library_name [];
4444extern const CK_FUNCTION_LIST wolfpkcs11nsFunctionList ;
4545#endif
@@ -487,6 +487,7 @@ static int cmd_success(const char *args)
487487
488488static int cmd_random (const char * args )
489489{
490+ #ifdef WOLFCRYPT_SECURE_MODE
490491 WC_RNG rng ;
491492 int ret ;
492493 uint32_t rand ;
@@ -505,6 +506,9 @@ static int cmd_random(const char *args)
505506 printf ("Today's lucky number: 0x%08lX\r\n" , rand );
506507 printf ("Brought to you by wolfCrypt's DRBG fed by HW TRNG in Secure world\r\n" );
507508 wc_FreeRng (& rng );
509+ #else
510+ printf ("Feature only supported with WOLFCRYPT_TZ=1\n" );
511+ #endif
508512 return 0 ;
509513}
510514
@@ -521,6 +525,7 @@ static int cmd_timestamp(const char *args)
521525static int cmd_login_pkcs11 (const char * args )
522526{
523527 int ret = -1 ;
528+ #ifdef SECURE_PKCS11
524529 unsigned int devId = 0 ;
525530 Pkcs11Token token ;
526531 Pkcs11Dev PKCS11_d ;
@@ -535,7 +540,6 @@ static int cmd_login_pkcs11(const char *args)
535540 return 0 ;
536541 }
537542
538- #ifdef SECURE_PKCS11
539543 printf ("PKCS11 Login\r\n" );
540544
541545 printf ("Initializing wolfCrypt..." );
@@ -608,26 +612,30 @@ static int cmd_login_pkcs11(const char *args)
608612 }
609613#endif
610614 }
611-
612- #endif /* SECURE_PKCS11 */
613615 if (ret == 0 ) {
614616 printf ("PKCS11 initialization completed successfully.\r\n" );
615617 pkcs11_initialized = 1 ;
616618 }
619+ #else
620+ printf ("Feature only supported with WOLFCRYPT_TZ=1\n" );
621+ #endif /* SECURE_PKCS11 */
617622 return ret ;
618623}
619624
620625static int cmd_benchmark (const char * args )
621626{
622-
627+ #ifdef WOLFCRYPT_SECURE_MODE
623628 benchmark_test (NULL );
629+ #endif
624630 return 0 ;
625631}
626632
627633/* Test command */
628634static int cmd_test (const char * args )
629635{
636+ #ifdef WOLFCRYPT_SECURE_MODE
630637 wolfcrypt_test (NULL );
638+ #endif
631639 return 0 ;
632640}
633641
@@ -836,3 +844,27 @@ int _fstat(int file, struct stat *st)
836844 return 0 ;
837845}
838846
847+ #ifndef WOLFCRYPT_SECURE_MODE
848+ /* Back-end for malloc, used for token handling */
849+ extern unsigned int _start_heap ; /* From linker script: heap memory */
850+ extern unsigned int _heap_size ; /* From linker script: heap limit */
851+
852+ void * _sbrk (unsigned int incr )
853+ {
854+ static unsigned char * heap = (unsigned char * )& _start_heap ;
855+ static uint32_t heapsize = (uint32_t )(& _heap_size );
856+ void * old_heap = heap ;
857+ if (((incr >> 2 ) << 2 ) != incr )
858+ incr = ((incr >> 2 ) + 1 ) << 2 ;
859+
860+ if (heap == NULL )
861+ heap = (unsigned char * )& _start_heap ;
862+ else
863+ heap += incr ;
864+ if (((uint32_t )heap - (uint32_t )(& _start_heap )) > heapsize ) {
865+ heap -= incr ;
866+ return NULL ;
867+ }
868+ return old_heap ;
869+ }
870+ #endif
0 commit comments