2
0

wolfcrypt_test.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* wolfcrypt_test.c
  2. *
  3. * Copyright (C) 2006-2024 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 <stdio.h>
  22. #include "board.h"
  23. #include "peripherals.h"
  24. #include "pin_mux.h"
  25. #include "clock_config.h"
  26. #ifdef CPU_MIMXRT1176DVMAA_cm7
  27. #include "MIMXRT1176_cm7.h"
  28. #else
  29. #include "MIMXRT685S_cm33.h"
  30. #endif
  31. #include "fsl_debug_console.h"
  32. #include <wolfssl/wolfcrypt/wc_port.h>
  33. #include <wolfssl/wolfcrypt/logging.h>
  34. #include "wolfcrypt/test/test.h"
  35. #if defined(FREESCALE_KSDK_2_0_TRNG) && defined(FREESCALE_RTC)
  36. #include "fsl_rtc.h"
  37. #include "fsl_trng.h"
  38. /* start the RTC and TRNG */
  39. static void setup()
  40. {
  41. rtc_datetime_t date;
  42. trng_config_t trngConfig;
  43. status_t status;
  44. RTC_Init(RTC);
  45. /* setup a default start date */
  46. date.year = 2022U;
  47. date.month = 8U;
  48. date.day = 17U;
  49. date.hour = 15U;
  50. date.minute = 10;
  51. date.second = 0;
  52. RTC_EnableTimer(RTC, false);
  53. RTC_SetDatetime(RTC, &date);
  54. RTC_EnableTimer(RTC, true);
  55. TRNG_GetDefaultConfig(&trngConfig);
  56. /* Commented in example NXP TRNG as an optional, better random mode */
  57. trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
  58. /* Initialize TRNG */
  59. status = TRNG_Init(TRNG0, &trngConfig);
  60. if (status != kStatus_Success) {
  61. PRINTF("Issues starting TRNG\n");
  62. }
  63. }
  64. #elif defined(FREESCALE_SNVS_RTC)
  65. #include "fsl_snvs_hp.h"
  66. static void setup()
  67. {
  68. snvs_hp_rtc_datetime_t rtcDate;
  69. snvs_hp_rtc_config_t snvsRtcConfig;
  70. /* Init SNVS */
  71. /*
  72. * snvsConfig->rtccalenable = false;
  73. * snvsConfig->rtccalvalue = 0U;
  74. * snvsConfig->srtccalenable = false;
  75. * snvsConfig->srtccalvalue = 0U;
  76. * snvsConfig->PIFreq = 0U;
  77. */
  78. SNVS_HP_RTC_GetDefaultConfig(&snvsRtcConfig);
  79. SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);
  80. PRINTF("SNVS HP example:\r\n");
  81. /* Set a start date time and start RT */
  82. rtcDate.year = 2014U;
  83. rtcDate.month = 12U;
  84. rtcDate.day = 25U;
  85. rtcDate.hour = 19U;
  86. rtcDate.minute = 0;
  87. rtcDate.second = 0;
  88. /* Set RTC time to default time and date and start the RTC */
  89. SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate);
  90. }
  91. #else
  92. static void setup()
  93. {
  94. /* no clock or trng to setup */
  95. }
  96. #endif
  97. int main(void)
  98. {
  99. volatile int i = 0;
  100. int ret;
  101. /* Init board hardware. */
  102. BOARD_InitBootPins();
  103. BOARD_InitBootClocks();
  104. BOARD_InitBootPeripherals();
  105. #ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
  106. /* Init FSL debug console. */
  107. BOARD_InitDebugConsole();
  108. #endif
  109. setup(); /* set the RTC and start the TRNG */
  110. /* initialize wolfCrypt and run tests */
  111. if (wolfCrypt_Init() == 0) {
  112. PRINTF("Running wolfcrypt tests....\r\n");
  113. wolfSSL_Debugging_ON();
  114. ret = wolfcrypt_test(NULL);
  115. PRINTF("Return of wolfcrypt_test = %d\r\n", ret);
  116. wolfCrypt_Cleanup();
  117. }
  118. else {
  119. PRINTF("Failed to initialize wolfCrypt\r\n");
  120. }
  121. #if defined(FREESCALE_KSDK_2_0_TRNG) && defined(FREESCALE_RTC)
  122. TRNG_Deinit(TRNG0);
  123. #endif
  124. while(1) {
  125. i++;
  126. __asm volatile ("nop");
  127. }
  128. return 0 ;
  129. }