Skip to content

Commit 353a379

Browse files
authored
Merge pull request #10262 from douzzer/20260420-test-fixes
20260420-test-fixes
2 parents 967780f + 956f057 commit 353a379

4 files changed

Lines changed: 464 additions & 188 deletions

File tree

examples/pem/pem.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
#if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
4141

42+
static const char *progname;
43+
4244
/* Increment allocated data by this much. */
4345
#define DATA_INC_LEN 256
4446
/* Maximum block size of a cipher. */
@@ -554,15 +556,20 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password,
554556
if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
555557
ret = 0;
556558
}
557-
else if (ret == 0) {
558-
ret = 1;
559+
else {
560+
fprintf(stderr,
561+
"%s: wc_CreateEncryptedPKCS8Key() with enc_alg_id %d: "
562+
"unexpected retval: %s.\n",
563+
progname, enc_alg_id, wc_GetErrorString(ret));
564+
if (ret == 0)
565+
ret = 1;
559566
}
560567
}
561568
if (ret == 0) {
562569
/* Allocate memory for encrypted DER data. */
563570
*enc = (unsigned char*)XMALLOC(*enc_len, NULL, DYNAMIC_TYPE_TMP_BUFFER);
564571
if (*enc == NULL) {
565-
ret = 1;
572+
ret = MEMORY_E;
566573
}
567574
}
568575
if (ret == 0) {
@@ -748,6 +755,13 @@ int main(int argc, char* argv[])
748755
#ifdef DEBUG_WOLFSSL
749756
int log = 0;
750757
#endif
758+
int wolfcrypt_inited = 0;
759+
760+
progname = strrchr(argv[0], '/');
761+
if (progname)
762+
++progname;
763+
else
764+
progname = argv[0];
751765

752766
memset(&info, 0, sizeof(info));
753767

@@ -951,6 +965,23 @@ int main(int argc, char* argv[])
951965
}
952966
#endif
953967

968+
#ifdef WC_RNG_SEED_CB
969+
ret = wc_SetSeed_Cb(WC_GENERATE_SEED_DEFAULT);
970+
if (ret != 0) {
971+
fprintf(stderr, "%s: wc_SetSeed_Cb() failed: %s.\n",
972+
progname, wc_GetErrorString(ret));
973+
exit(1);
974+
}
975+
#endif
976+
977+
ret = wolfCrypt_Init();
978+
if (ret != 0) {
979+
fprintf(stderr, "%s: wolfCrypt_Init() failed: %s.\n",
980+
progname, wc_GetErrorString(ret));
981+
exit(1);
982+
}
983+
wolfcrypt_inited = 1;
984+
954985
/* Convert PEM type string to value. */
955986
if (type_str != NULL) {
956987
ret = StringToType(type_str, &type);
@@ -1037,7 +1068,7 @@ int main(int argc, char* argv[])
10371068
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
10381069
}
10391070
if (ret < 0) {
1040-
fprintf(stderr, "%s\n", wc_GetErrorString(ret));
1071+
fprintf(stderr, "%s: %s\n", progname, wc_GetErrorString(ret));
10411072
}
10421073

10431074
if ((in_file != stdin) && (in_file != NULL))
@@ -1046,6 +1077,14 @@ int main(int argc, char* argv[])
10461077
if ((out_file != stdout) && (out_file != NULL))
10471078
(void)fclose(out_file);
10481079

1080+
if (wolfcrypt_inited) {
1081+
ret = wolfCrypt_Cleanup();
1082+
if (ret != 0) {
1083+
fprintf(stderr, "%s: wolfCrypt_Cleanup() failed: %s.\n",
1084+
progname, wc_GetErrorString(ret));
1085+
}
1086+
}
1087+
10491088
return (ret == 0) ? 0 : 1;
10501089
}
10511090

linuxkm/module_hooks.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,11 @@ static int wolfssl_init(void)
925925
#endif
926926

927927
WOLFSSL_ATOMIC_STORE(*conTestFailure_ptr, 0);
928-
for (i = 0; i < FIPS_CAST_COUNT; ++i)
929-
fipsCastStatus_put(i, FIPS_CAST_STATE_INIT);
928+
{
929+
int i;
930+
for (i = 0; i < FIPS_CAST_COUNT; ++i)
931+
fipsCastStatus_put(i, FIPS_CAST_STATE_INIT);
932+
}
930933
/* note, must call fipsEntry() here, not wolfCrypt_IntegrityTest_fips(),
931934
* because wc_GetCastStatus_fips(FIPS_CAST_HMAC_SHA2_256) isn't available
932935
* anymore.

0 commit comments

Comments
 (0)