2
0

wolf_tasks.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* wolf-tasks.c
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #include <wolfssl/wolfcrypt/settings.h>
  22. #include <wolfcrypt/test/test.h>
  23. #include <wolfssl/wolfcrypt/error-crypt.h>
  24. #include <wolfssl/wolfcrypt/fips_test.h>
  25. #ifdef FUSION_RTOS
  26. #include <fcl_os.h>
  27. #define RESULT_BUF_SIZE 1024
  28. typedef struct {
  29. int isRunning;
  30. u8 buf[RESULT_BUF_SIZE];
  31. int len;
  32. } wolf_result_t;
  33. static wolf_result_t _result = {0};
  34. static void myFipsCb(int ok, int err, const char* hash);
  35. static void myFipsCb(int ok, int err, const char* hash)
  36. {
  37. FCL_PRINTF("in my Fips callback, ok = %d, err = %d\n", ok, err);
  38. FCL_PRINTF("message = %s\n", wc_GetErrorString(err));
  39. FCL_PRINTF("hash = %s\n", hash);
  40. if (err == IN_CORE_FIPS_E) {
  41. FCL_PRINTF("In core integrity hash check failure, copy above hash\n");
  42. FCL_PRINTF("into verifyCore[] in fips_test.c and rebuild\n");
  43. }
  44. }
  45. static fclThreadHandle _task = NULL;
  46. #define WOLF_TASK_STACK_SIZE (1024 * 100)
  47. fclThreadPriority WOLF_TASK_PRIORITY = (fclThreadPriority) (FCL_THREAD_PRIORITY_TIME_CRITICAL+1);
  48. int wolfcrypt_test_taskEnter(void *args)
  49. {
  50. int ret;
  51. wolfCrypt_SetCb_fips(myFipsCb);
  52. ret = wolfcrypt_test(args);
  53. printf("Result of test was %d\n", ret);
  54. _result.isRunning = 0;
  55. fosTaskDelete(_task);
  56. return 0;
  57. }
  58. /* Was only needed for CAVP testing purposes, not required for release.
  59. int wolfcrypt_harness_taskEnter(void *args)
  60. {
  61. wolfCrypt_SetCb_fips(myFipsCb);
  62. wolfcrypt_harness(args);
  63. _result.isRunning = 0;
  64. fosTaskDelete(_task);
  65. return 0;
  66. }
  67. */
  68. int wolf_task_start(void* voidinfo, char* argline)
  69. {
  70. char optionA[] = "wolfcrypt_test";
  71. fssShellInfo *info = (fssShellInfo*)voidinfo;
  72. struct wolfArgs args;
  73. if (_result.isRunning) {
  74. fssShellPuts(info, "previous task still running\r\n");
  75. return 1;
  76. }
  77. _result.isRunning = 1;
  78. if (FCL_STRNCMP(argline, optionA, FCL_STRLEN(optionA)) == 0) {
  79. _task = fclThreadCreate(wolfcrypt_test_taskEnter,
  80. &args,
  81. WOLF_TASK_STACK_SIZE,
  82. WOLF_TASK_PRIORITY);
  83. } else if (FCL_STRNCMP(argline, optionB, FCL_STRLEN(optionB)) == 0) {
  84. _task = fclThreadCreate(wolfcrypt_harness_taskEnter,
  85. &args,
  86. WOLF_TASK_STACK_SIZE,
  87. WOLF_TASK_PRIORITY);
  88. } else {
  89. printf("Invalid input: %s\n", argline);
  90. printf("Please try with either wolfcrypt_test or wolfcrypt_harness\n");
  91. return -1;
  92. }
  93. FCL_ASSERT(_task != FCL_THREAD_HANDLE_INVALID);
  94. return 0;
  95. }
  96. #endif /* FUSION_RTOS */