1
0

testsuite.c 18 KB

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