123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #include "xil_printf.h"
- #include "xrtcpsu.h"
- #ifdef FREERTOS
- #include "FreeRTOS.h"
- #include "task.h"
- #include "queue.h"
- #include "timers.h"
- #endif
- #include "wolfssl/wolfcrypt/settings.h"
- #include "wolfssl/wolfcrypt/wc_port.h"
- #include "wolfssl/wolfcrypt/error-crypt.h"
- #include "wolfssl/wolfcrypt/logging.h"
- #include "wolfcrypt/test/test.h"
- #include "wolfcrypt/benchmark/benchmark.h"
- typedef struct func_args
- {
- int argc;
- char **argv;
- int return_code;
- } func_args;
- const char menu1[] = "\n"
- "\tb. WolfCrypt Benchmark\n"
- "\tt. WolfCrypt Test\n"
- "\n"
- "\tc. Command mode\n";
- #if !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
- unsigned char my_rng_seed_gen(void)
- {
- static unsigned int kTestSeed = 1;
- return kTestSeed++;
- }
- #endif
- #ifdef FREERTOS
- static void wolfssl_task( void *pvParameters );
- static TaskHandle_t xWolfsslTask;
- int main( void )
- {
- xil_printf("\nStarting up FreeRTOS\n");
- xTaskCreate(wolfssl_task,
- (const char*) "Tx",
- configMINIMAL_STACK_SIZE,
- NULL,
- tskIDLE_PRIORITY,
- &xWolfsslTask);
-
- vTaskStartScheduler();
-
- for (;;)
- ;
- }
- static void wolfssl_task( void *pvParameters )
- #else
- int main()
- #endif
- {
- uint8_t cmd[128], c;
- char *arg[sizeof(cmd)/2 + 1];
- size_t cmdlen, argnum, n;
- func_args args;
- int (*func)(int argc, char** argv);
- int command_mode = 0;
- #ifdef DEBUG_WOLFSSL
- wolfSSL_Debugging_ON();
- #endif
-
- wolfCrypt_Init();
- while (1) {
- memset(&args, 0, sizeof(args));
- args.return_code = NOT_COMPILED_IN;
- if (!command_mode) {
- xil_printf("\n\t\t\t\tMENU\n");
- xil_printf(menu1);
- xil_printf("Please select one of the above options:\n");
- xil_printf("Both 'b' and 't' allow arguments as if you'd call the regular shell version.\n");
- }
- cmdlen = 0;
- do {
- c = inbyte();
- cmd[cmdlen] = c;
- if (!command_mode) outbyte(c);
- cmdlen++;
- cmdlen %= sizeof(cmd);
- } while (c != '\n' && c != '\r');
- if (cmdlen > 2) {
- outbyte('\n');
-
- XMEMSET(arg, 0, sizeof(arg));
- if (cmd[1] == ' ') {
- if (cmd[0] == 'b') {
- arg[0] = "wolfcrypt_benchmark";
- func = wolfcrypt_benchmark_main;
- } else if (cmd[0] == 't') {
- arg[0] = "wolfcrypt_test";
- func = wolfcrypt_test_main;
- }
- if (arg[0] != NULL) {
- argnum = 1;
- for (n = 2; n < cmdlen; ++n) {
- switch (cmd[n]) {
- case ' ':
- case '\t':
- case '\r':
- case '\n':
- cmd[n] = '\0';
- if (arg[argnum] != NULL)
- argnum++;
- break;
- default:
- if (arg[argnum] == NULL)
- arg[argnum] = (char*)&cmd[n];
- break;
- }
- }
- func(argnum, arg);
- }
- }
- } else {
- switch (cmd[0]) {
- case 't':
- xil_printf("Running wolfCrypt Tests...\n");
- #ifndef NO_CRYPT_TEST
- args.return_code = 0;
- wolfcrypt_test(&args);
- #endif
- xil_printf("Crypt Test: Return code %d\n", args.return_code);
- break;
- case 'b':
- xil_printf("Running wolfCrypt Benchmarks...\n");
- #ifndef NO_CRYPT_BENCHMARK
- args.return_code = 0;
- benchmark_test(&args);
- #endif
- xil_printf("Benchmark Test: Return code %d\n", args.return_code);
- break;
- case 'c':
- if (!command_mode) xil_printf("Entering command mode, enter 'c<enter>' to return to manual mode\n");
- command_mode ^= 1;
- break;
- default:
- if (!command_mode) xil_printf("\nSelection out of range\n");
- break;
- }
- }
- }
- wolfCrypt_Cleanup();
- #ifndef FREERTOS
- return 0;
- #endif
- }
|