testsuite.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /* testsuite.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. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #ifndef WOLFSSL_USER_SETTINGS
  26. #include <wolfssl/options.h>
  27. #endif
  28. #undef TEST_OPENSSL_COEXIST /* can't use this option with this example */
  29. #undef OPENSSL_COEXIST /* can't use this option with this example */
  30. #include <wolfssl/wolfcrypt/types.h>
  31. #include <wolfssl/ssl.h>
  32. #include <wolfssl/test.h>
  33. #include <wolfcrypt/test/test.h>
  34. #ifndef SINGLE_THREADED
  35. #ifdef OPENSSL_EXTRA
  36. #include <wolfssl/openssl/ssl.h>
  37. #endif
  38. #include <wolfssl/wolfcrypt/sha256.h>
  39. #include <wolfssl/wolfcrypt/ecc.h>
  40. #include <examples/echoclient/echoclient.h>
  41. #include <examples/echoserver/echoserver.h>
  42. #include <examples/server/server.h>
  43. #include <examples/client/client.h>
  44. #include "tests/utils.h"
  45. #ifndef NO_SHA256
  46. void file_test(const char* file, byte* check);
  47. #endif
  48. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  49. #ifdef HAVE_STACK_SIZE
  50. static THREAD_RETURN simple_test(func_args *args);
  51. #else
  52. static void simple_test(func_args *args);
  53. #endif
  54. static int test_tls(func_args* server_args);
  55. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  56. defined(HAVE_CRL) && defined(HAVE_CRL_MONITOR)
  57. static int test_crl_monitor(void);
  58. #endif
  59. static void show_ciphers(void);
  60. static void cleanup_output(void);
  61. static int validate_cleanup_output(void);
  62. enum {
  63. NUMARGS = 3
  64. };
  65. static const char *outputName;
  66. #endif
  67. int myoptind = 0;
  68. char* myoptarg = NULL;
  69. #ifndef NO_TESTSUITE_MAIN_DRIVER
  70. static int testsuite_test(int argc, char** argv);
  71. int main(int argc, char** argv)
  72. {
  73. return testsuite_test(argc, argv);
  74. }
  75. #endif /* NO_TESTSUITE_MAIN_DRIVER */
  76. #ifdef HAVE_STACK_SIZE
  77. /* Wrap TLS echo client to free thread locals. */
  78. static void *echoclient_test_wrapper(void* args) {
  79. echoclient_test(args);
  80. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  81. wc_ecc_fp_free(); /* free per thread cache */
  82. #endif
  83. return (void *)0;
  84. }
  85. #endif
  86. int testsuite_test(int argc, char** argv)
  87. {
  88. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  89. (!defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC))
  90. func_args server_args;
  91. tcp_ready ready;
  92. #if !defined(NETOS)
  93. THREAD_TYPE serverThread;
  94. int ret;
  95. #endif
  96. #ifndef USE_WINDOWS_API
  97. const char *tempDir = NULL;
  98. char tempName[128];
  99. int tempName_len;
  100. int tempName_Xnum;
  101. #else
  102. char tempName[] = "fnXXXXXX";
  103. const int tempName_len = 8;
  104. const int tempName_Xnum = 6;
  105. #endif
  106. #ifdef HAVE_STACK_SIZE
  107. void *serverThreadStackContext = NULL;
  108. #endif
  109. #ifndef USE_WINDOWS_API
  110. #ifdef XGETENV
  111. tempDir = XGETENV("TMPDIR");
  112. if (tempDir == NULL)
  113. #endif
  114. {
  115. tempDir = "/tmp";
  116. }
  117. XSTRLCPY(tempName, tempDir, sizeof(tempName));
  118. XSTRLCAT(tempName, "/testsuite-output-XXXXXX", sizeof(tempName));
  119. tempName_len = (int)XSTRLEN(tempName);
  120. tempName_Xnum = 6;
  121. #endif /* !USE_WINDOWS_API */
  122. #ifdef HAVE_WNR
  123. if (wc_InitNetRandom(wnrConfig, NULL, 5000) != 0) {
  124. err_sys("Whitewood netRandom global config failed");
  125. return -1237;
  126. }
  127. #endif /* HAVE_WNR */
  128. StartTCP();
  129. server_args.argc = argc;
  130. server_args.argv = argv;
  131. wolfSSL_Init();
  132. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  133. wolfSSL_Debugging_ON();
  134. #endif
  135. #if !defined(WOLFSSL_TIRTOS)
  136. ChangeToWolfRoot();
  137. #endif
  138. #ifdef WOLFSSL_TIRTOS
  139. fdOpenSession(Task_self());
  140. #endif
  141. server_args.signal = &ready;
  142. InitTcpReady(&ready);
  143. #ifndef NO_CRYPT_TEST
  144. /* wc_ test */
  145. #ifdef HAVE_STACK_SIZE
  146. StackSizeCheck(&server_args, wolfcrypt_test);
  147. #else
  148. wolfcrypt_test(&server_args);
  149. #endif
  150. if (server_args.return_code != 0) return server_args.return_code;
  151. #endif
  152. /* Simple wolfSSL client server test */
  153. #ifdef HAVE_STACK_SIZE
  154. StackSizeCheck(&server_args, (THREAD_RETURN (*)(void *))simple_test);
  155. #else
  156. simple_test(&server_args);
  157. #endif
  158. if (server_args.return_code != 0) return server_args.return_code;
  159. #if !defined(NETOS)
  160. /* Echo input wolfSSL client server test */
  161. #ifdef HAVE_STACK_SIZE
  162. StackSizeCheck_launch(&server_args, echoserver_test, &serverThread,
  163. &serverThreadStackContext);
  164. #else
  165. start_thread(echoserver_test, &server_args, &serverThread);
  166. #endif
  167. /* Create unique file name */
  168. outputName = mymktemp(tempName, tempName_len, tempName_Xnum);
  169. if (outputName == NULL) {
  170. printf("Could not create unique file name");
  171. return EXIT_FAILURE;
  172. }
  173. ret = test_tls(&server_args);
  174. if (ret != 0) {
  175. cleanup_output();
  176. return ret;
  177. }
  178. /* Server won't quit unless TLS test has worked. */
  179. #ifdef HAVE_STACK_SIZE
  180. fputs("reaping echoserver_test: ", stdout);
  181. StackSizeCheck_reap(serverThread, serverThreadStackContext);
  182. #else
  183. join_thread(serverThread);
  184. #endif
  185. if (server_args.return_code != 0) {
  186. cleanup_output();
  187. return server_args.return_code;
  188. }
  189. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  190. defined(HAVE_CRL) && defined(HAVE_CRL_MONITOR)
  191. ret = test_crl_monitor();
  192. if (ret != 0) {
  193. cleanup_output();
  194. return ret;
  195. }
  196. #endif
  197. #endif /* !NETOS */
  198. show_ciphers();
  199. #if !defined(NETOS)
  200. ret = validate_cleanup_output();
  201. if (ret != 0)
  202. return EXIT_FAILURE;
  203. #endif
  204. wolfSSL_Cleanup();
  205. FreeTcpReady(&ready);
  206. #ifdef WOLFSSL_TIRTOS
  207. fdCloseSession(Task_self());
  208. #endif
  209. #ifdef HAVE_WNR
  210. if (wc_FreeNetRandom() < 0)
  211. err_sys("Failed to free netRandom context");
  212. #endif /* HAVE_WNR */
  213. printf("\nAll tests passed!\n");
  214. #else
  215. (void)argc;
  216. (void)argv;
  217. #endif /* !NO_WOLFSSL_SERVER && !NO_WOLFSSL_CLIENT */
  218. return EXIT_SUCCESS;
  219. }
  220. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  221. defined(HAVE_CRL) && defined(HAVE_CRL_MONITOR)
  222. #define CRL_MONITOR_TEST_ROUNDS 6
  223. #define CRL_MONITOR_REM_FILE_ATTEMPTS 20
  224. static int test_crl_monitor(void)
  225. {
  226. func_args server_args;
  227. func_args client_args;
  228. THREAD_TYPE serverThread;
  229. tcp_ready ready;
  230. char buf[128];
  231. char tmpDir[16];
  232. char rounds[4];
  233. char portNum[8];
  234. const char* serverArgv[] = {
  235. "testsuite",
  236. "-A", "certs/ca-cert.pem",
  237. "--crl-dir", tmpDir,
  238. "-C", rounds,
  239. "--quieter",
  240. "-x",
  241. "-p", "0"
  242. };
  243. const char* clientArgv[] = {
  244. "testsuite",
  245. "-C",
  246. "-c", "certs/server-cert.pem",
  247. "-k", "certs/server-key.pem",
  248. "--quieter",
  249. "-H", "exitWithRet",
  250. "-p", portNum
  251. };
  252. int ret = -1;
  253. int i = -1, j;
  254. printf("\nRunning CRL monitor test\n");
  255. (void)XSNPRINTF(rounds, sizeof(rounds), "%d", CRL_MONITOR_TEST_ROUNDS);
  256. XMEMSET(&server_args, 0, sizeof(func_args));
  257. XMEMSET(&client_args, 0, sizeof(func_args));
  258. /* Create temp dir */
  259. if (create_tmp_dir(tmpDir, sizeof(tmpDir) - 1) == NULL) {
  260. fprintf(stderr, "Failed to create tmp dir");
  261. goto cleanup;
  262. }
  263. server_args.argv = (char**)serverArgv;
  264. server_args.argc = sizeof(serverArgv) / sizeof(*serverArgv);
  265. client_args.signal = server_args.signal = &ready;
  266. client_args.argv = (char**)clientArgv;
  267. client_args.argc = sizeof(clientArgv) / sizeof(*clientArgv);
  268. InitTcpReady(&ready);
  269. start_thread(server_test, &server_args, &serverThread);
  270. wait_tcp_ready(&server_args);
  271. (void)XSNPRINTF(portNum, sizeof(portNum), "%d", server_args.signal->port);
  272. for (i = 0; i < CRL_MONITOR_TEST_ROUNDS; i++) {
  273. int expectFail;
  274. if (i % 2 == 0) {
  275. /* succeed on even rounds */
  276. (void)XSNPRINTF(buf, sizeof(buf), "%s/%s", tmpDir, "crl.pem");
  277. if (STAGE_FILE("certs/crl/crl.pem", buf) != 0) {
  278. fprintf(stderr, "[%d] Failed to copy file to %s\n", i, buf);
  279. goto cleanup;
  280. }
  281. (void)XSNPRINTF(buf, sizeof(buf), "%s/%s", tmpDir, "crl.revoked");
  282. /* The monitor can be holding the file handle and this will cause
  283. * the remove call to fail. Let's give the monitor a some time to
  284. * finish up. */
  285. for (j = 0; j < CRL_MONITOR_REM_FILE_ATTEMPTS; j++) {
  286. /* i == 0 since there is nothing to delete in the first round */
  287. if (i == 0 || rem_file(buf) == 0)
  288. break;
  289. XSLEEP_MS(100);
  290. }
  291. if (j == CRL_MONITOR_REM_FILE_ATTEMPTS) {
  292. fprintf(stderr, "[%d] Failed to remove file %s\n", i, buf);
  293. goto cleanup;
  294. }
  295. expectFail = 0;
  296. }
  297. else {
  298. /* fail on odd rounds */
  299. (void)XSNPRINTF(buf, sizeof(buf), "%s/%s", tmpDir, "crl.revoked");
  300. if (STAGE_FILE("certs/crl/crl.revoked", buf) != 0) {
  301. fprintf(stderr, "[%d] Failed to copy file to %s\n", i, buf);
  302. goto cleanup;
  303. }
  304. (void)XSNPRINTF(buf, sizeof(buf), "%s/%s", tmpDir, "crl.pem");
  305. /* The monitor can be holding the file handle and this will cause
  306. * the remove call to fail. Let's give the monitor a some time to
  307. * finish up. */
  308. for (j = 0; j < CRL_MONITOR_REM_FILE_ATTEMPTS; j++) {
  309. if (rem_file(buf) == 0)
  310. break;
  311. XSLEEP_MS(100);
  312. }
  313. if (j == CRL_MONITOR_REM_FILE_ATTEMPTS) {
  314. fprintf(stderr, "[%d] Failed to remove file %s\n", i, buf);
  315. goto cleanup;
  316. }
  317. expectFail = 1;
  318. }
  319. /* Give server a moment to register the file change */
  320. XSLEEP_MS(100);
  321. client_args.return_code = 0;
  322. client_test(&client_args);
  323. if (!expectFail) {
  324. if (client_args.return_code != 0) {
  325. fprintf(stderr, "[%d] Incorrect return %d\n", i,
  326. client_args.return_code);
  327. goto cleanup;
  328. }
  329. }
  330. else {
  331. if (client_args.return_code == 0) {
  332. fprintf(stderr, "[%d] Expected failure\n", i);
  333. goto cleanup;
  334. }
  335. }
  336. }
  337. join_thread(serverThread);
  338. ret = 0;
  339. cleanup:
  340. if (ret != 0 && i >= 0)
  341. fprintf(stderr, "test_crl_monitor failed on iteration %d\n", i);
  342. (void)XSNPRINTF(buf, sizeof(buf), "%s/%s", tmpDir, "crl.pem");
  343. rem_file(buf);
  344. (void)XSNPRINTF(buf, sizeof(buf), "%s/%s", tmpDir, "crl.revoked");
  345. rem_file(buf);
  346. (void)rem_dir(tmpDir);
  347. return ret;
  348. }
  349. #endif
  350. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  351. (!defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC))
  352. /* Perform a basic TLS handshake.
  353. *
  354. * First connection to echo a file.
  355. * Second to tell TLS server to quit.
  356. *
  357. * @param [in,out] server_args Object sent to server thread.
  358. * @return 0 on success.
  359. * @return echoclient error return code on failure.
  360. */
  361. static int test_tls(func_args* server_args)
  362. {
  363. func_args echo_args;
  364. char* myArgv[NUMARGS];
  365. char arg[3][128];
  366. printf("\nRunning TLS test\n");
  367. /* Set up command line arguments for echoclient to send input file
  368. * and write echoed data to temporary output file. */
  369. myArgv[0] = arg[0];
  370. myArgv[1] = arg[1];
  371. myArgv[2] = arg[2];
  372. echo_args.argc = 3;
  373. echo_args.argv = myArgv;
  374. XSTRLCPY(arg[0], "testsuite", sizeof(arg[0]));
  375. XSTRLCPY(arg[1], "input", sizeof(arg[1]));
  376. XSTRLCPY(arg[2], outputName, sizeof(arg[2]));
  377. /* Share the signal, it has the new port number in it. */
  378. echo_args.signal = server_args->signal;
  379. /* Ready to execute client - wait for server to be ready. */
  380. wait_tcp_ready(server_args);
  381. /* Do a client TLS connection. */
  382. #ifdef HAVE_STACK_SIZE
  383. fputs("echoclient_test #1: ", stdout);
  384. StackSizeCheck(&echo_args, echoclient_test_wrapper);
  385. #else
  386. echoclient_test(&echo_args);
  387. #endif
  388. if (echo_args.return_code != 0)
  389. return echo_args.return_code;
  390. #ifdef WOLFSSL_DTLS
  391. /* Ensure server is ready for UDP data. */
  392. wait_tcp_ready(server_args);
  393. #endif
  394. /* Next client connection - send quit to shutdown server. */
  395. echo_args.argc = 2;
  396. XSTRLCPY(arg[1], "quit", sizeof(arg[1]));
  397. /* Do a client TLS connection. */
  398. #ifdef HAVE_STACK_SIZE
  399. fputs("echoclient_test #2: ", stdout);
  400. StackSizeCheck(&echo_args, echoclient_test_wrapper);
  401. #else
  402. echoclient_test(&echo_args);
  403. #endif
  404. if (echo_args.return_code != 0)
  405. return echo_args.return_code;
  406. return 0;
  407. }
  408. /* Show cipher suites available. */
  409. static void show_ciphers(void)
  410. {
  411. char ciphers[WOLFSSL_CIPHER_LIST_MAX_SIZE];
  412. XMEMSET(ciphers, 0, sizeof(ciphers));
  413. wolfSSL_get_ciphers(ciphers, sizeof(ciphers)-1);
  414. printf("ciphers = %s\n", ciphers);
  415. }
  416. /* Cleanup temporary output file. */
  417. static void cleanup_output(void)
  418. {
  419. remove(outputName);
  420. }
  421. /* Validate output equals input using a hash. Remove temporary output file.
  422. *
  423. * @return 0 on success.
  424. * @return 1 on failure.
  425. */
  426. static int validate_cleanup_output(void)
  427. {
  428. #ifndef NO_SHA256
  429. byte input[WC_SHA256_DIGEST_SIZE];
  430. byte output[WC_SHA256_DIGEST_SIZE];
  431. file_test("input", input);
  432. file_test(outputName, output);
  433. #endif
  434. cleanup_output();
  435. #ifndef NO_SHA256
  436. if (memcmp(input, output, sizeof(input)) != 0)
  437. return 1;
  438. #endif
  439. return 0;
  440. }
  441. /* Simple server.
  442. *
  443. * @param [in] args Object for server data in thread.
  444. * @return Return code.
  445. */
  446. #ifdef HAVE_STACK_SIZE
  447. static THREAD_RETURN simple_test(func_args* args)
  448. #else
  449. static void simple_test(func_args* args)
  450. #endif
  451. {
  452. THREAD_TYPE serverThread;
  453. int i;
  454. func_args svrArgs;
  455. char *svrArgv[9];
  456. char argvs[9][32];
  457. func_args cliArgs;
  458. char *cliArgv[NUMARGS];
  459. char argvc[3][32];
  460. printf("\nRunning simple test\n");
  461. for (i = 0; i < 9; i++)
  462. svrArgv[i] = argvs[i];
  463. for (i = 0; i < 3; i++)
  464. cliArgv[i] = argvc[i];
  465. XSTRLCPY(argvs[0], "SimpleServer", sizeof(argvs[0]));
  466. svrArgs.argc = 1;
  467. svrArgs.argv = svrArgv;
  468. svrArgs.return_code = 0;
  469. #if !defined(USE_WINDOWS_API) && !defined(WOLFSSL_SNIFFER) && \
  470. !defined(WOLFSSL_TIRTOS)
  471. XSTRLCPY(argvs[svrArgs.argc++], "-p", sizeof(argvs[svrArgs.argc]));
  472. XSTRLCPY(argvs[svrArgs.argc++], "0", sizeof(argvs[svrArgs.argc]));
  473. #endif
  474. /* Set the last arg later, when it is known. */
  475. args->return_code = 0;
  476. svrArgs.signal = args->signal;
  477. start_thread(server_test, &svrArgs, &serverThread);
  478. wait_tcp_ready(&svrArgs);
  479. /* Setting the actual port number. */
  480. XSTRLCPY(argvc[0], "SimpleClient", sizeof(argvc[0]));
  481. cliArgs.argv = cliArgv;
  482. cliArgs.return_code = 0;
  483. #ifndef USE_WINDOWS_API
  484. cliArgs.argc = NUMARGS;
  485. XSTRLCPY(argvc[1], "-p", sizeof(argvc[1]));
  486. (void)snprintf(argvc[2], sizeof(argvc[2]), "%d", (int)svrArgs.signal->port);
  487. #else
  488. cliArgs.argc = 1;
  489. #endif
  490. client_test(&cliArgs);
  491. if (cliArgs.return_code != 0) {
  492. args->return_code = cliArgs.return_code;
  493. #ifdef HAVE_STACK_SIZE
  494. return (THREAD_RETURN)0;
  495. #else
  496. return;
  497. #endif
  498. }
  499. join_thread(serverThread);
  500. if (svrArgs.return_code != 0) args->return_code = svrArgs.return_code;
  501. #ifdef HAVE_STACK_SIZE
  502. return (THREAD_RETURN)0;
  503. #endif
  504. }
  505. #endif /* !NO_WOLFSSL_SERVER && !NO_WOLFSSL_CLIENT */
  506. #ifndef NO_SHA256
  507. /* Create SHA-256 hash of the file based on filename.
  508. *
  509. * @param [in] file Name of file.
  510. * @param [out] check Buffer to hold SHA-256 hash.
  511. */
  512. void file_test(const char* file, byte* check)
  513. {
  514. FILE* f;
  515. int i = 0, j, ret;
  516. wc_Sha256 sha256;
  517. byte buf[1024];
  518. byte shasum[WC_SHA256_DIGEST_SIZE];
  519. ret = wc_InitSha256(&sha256);
  520. if (ret != 0) {
  521. printf("Can't wc_InitSha256 %d\n", ret);
  522. return;
  523. }
  524. if( !( f = fopen( file, "rb" ) )) {
  525. printf("Can't open %s\n", file);
  526. return;
  527. }
  528. while( ( i = (int)fread(buf, 1, sizeof(buf), f )) > 0 ) {
  529. if (ferror(f)) {
  530. printf("I/O error reading %s\n", file);
  531. fclose(f);
  532. return;
  533. }
  534. ret = wc_Sha256Update(&sha256, buf, (word32)i);
  535. if (ret != 0) {
  536. printf("Can't wc_Sha256Update %d\n", ret);
  537. fclose(f);
  538. return;
  539. }
  540. if (feof(f))
  541. break;
  542. }
  543. ret = wc_Sha256Final(&sha256, shasum);
  544. wc_Sha256Free(&sha256);
  545. if (ret != 0) {
  546. printf("Can't wc_Sha256Final %d\n", ret);
  547. fclose(f);
  548. return;
  549. }
  550. XMEMCPY(check, shasum, sizeof(shasum));
  551. for(j = 0; j < WC_SHA256_DIGEST_SIZE; ++j )
  552. printf( "%02x", shasum[j] );
  553. printf(" %s\n", file);
  554. fclose(f);
  555. }
  556. #endif
  557. #else /* SINGLE_THREADED */
  558. int myoptind = 0;
  559. char* myoptarg = NULL;
  560. int main(int argc, char** argv)
  561. {
  562. func_args wolfcrypt_test_args;
  563. wolfcrypt_test_args.argc = argc;
  564. wolfcrypt_test_args.argv = argv;
  565. wolfSSL_Init();
  566. ChangeToWolfRoot();
  567. /* No TLS - only doing cryptographic algorithm testing. */
  568. wolfcrypt_test(&wolfcrypt_test_args);
  569. if (wolfcrypt_test_args.return_code != 0)
  570. return wolfcrypt_test_args.return_code;
  571. wolfSSL_Cleanup();
  572. printf("\nAll tests passed!\n");
  573. return EXIT_SUCCESS;
  574. }
  575. #endif /* SINGLE_THREADED */