wolfssl_example.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* wolfssl_example.c
  2. *
  3. * Copyright (C) 2006-2022 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 "xil_printf.h"
  22. #include "xrtcpsu.h"
  23. #include "wolfssl/wolfcrypt/settings.h"
  24. #include "wolfssl/wolfcrypt/wc_port.h"
  25. #include "wolfssl/wolfcrypt/error-crypt.h"
  26. #include "wolfssl/wolfcrypt/logging.h"
  27. #include "wolfcrypt/test/test.h"
  28. #include "wolfcrypt/benchmark/benchmark.h"
  29. /*****************************************************************************
  30. * Configuration
  31. ****************************************************************************/
  32. /*****************************************************************************
  33. * Private types/enumerations/variables
  34. ****************************************************************************/
  35. /*****************************************************************************
  36. * Public types/enumerations/variables
  37. ****************************************************************************/
  38. typedef struct func_args {
  39. int argc;
  40. char** argv;
  41. int return_code;
  42. } func_args;
  43. const char menu1[] = "\n"
  44. "\tt. WolfCrypt Test\n"
  45. "\tb. WolfCrypt Benchmark\n";
  46. /*****************************************************************************
  47. * Private functions
  48. ****************************************************************************/
  49. /* Test RNG Seed Function */
  50. /* TODO: Must provide real seed to RNG */
  51. unsigned char my_rng_seed_gen(void)
  52. {
  53. static unsigned int kTestSeed = 1;
  54. return kTestSeed++;
  55. }
  56. /*****************************************************************************
  57. * Public functions
  58. ****************************************************************************/
  59. int main()
  60. {
  61. uint8_t cmd;
  62. func_args args;
  63. #ifdef DEBUG_WOLFSSL
  64. wolfSSL_Debugging_ON();
  65. #endif
  66. /* initialize wolfSSL */
  67. wolfCrypt_Init();
  68. while (1) {
  69. memset(&args, 0, sizeof(args));
  70. args.return_code = NOT_COMPILED_IN; /* default */
  71. xil_printf("\n\t\t\t\tMENU\n");
  72. xil_printf(menu1);
  73. xil_printf("Please select one of the above options:\n");
  74. do {
  75. cmd = inbyte();
  76. } while (cmd == '\n' || cmd == '\r');
  77. switch (cmd) {
  78. case 't':
  79. xil_printf("Running wolfCrypt Tests...\n");
  80. #ifndef NO_CRYPT_TEST
  81. args.return_code = 0;
  82. wolfcrypt_test(&args);
  83. #endif
  84. xil_printf("Crypt Test: Return code %d\n", args.return_code);
  85. break;
  86. case 'b':
  87. xil_printf("Running wolfCrypt Benchmarks...\n");
  88. #ifndef NO_CRYPT_BENCHMARK
  89. args.return_code = 0;
  90. benchmark_test(&args);
  91. #endif
  92. xil_printf("Benchmark Test: Return code %d\n", args.return_code);
  93. break;
  94. default:
  95. xil_printf("\nSelection out of range\n");
  96. break;
  97. }
  98. }
  99. wolfCrypt_Cleanup();
  100. return 0;
  101. }