Skip to content

Commit

Permalink
Merge pull request wolfSSL#8033 from douzzer/20241001-fixes
Browse files Browse the repository at this point in the history
20241001-fixes
  • Loading branch information
SparkiDev authored Oct 1, 2024
2 parents 5927951 + a04871f commit b8dff12
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 30 deletions.
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,7 @@ then
AM_CCASFLAGS="$AM_CCASFLAGS -DEXTERNAL_OPTS_OPENVPN"
ENABLED_ARMASM_CRYPTO=yes
ENABLED_ARMASM_NEON=yes
ENABLED_ARM_64=yes

# Check for and set -mstrict-align compiler flag
# Used to set assumption that Aarch64 systems will not handle
Expand All @@ -3010,6 +3011,7 @@ then
ENABLED_ARMASM_CRYPTO=no
ENABLED_AESGCM_STREAM=no # not yet implemented
ENABLED_ARMASM_NEON=yes
ENABLED_ARM_32=yes
AC_MSG_NOTICE([32bit ARMv7-a found, setting mfpu to neon])
if test "$ENABLED_FIPS" != "no" ||
test "$HAVE_FIPS_VERSION_MAJOR" -ge 5;
Expand All @@ -3028,6 +3030,8 @@ then
ENABLED_ARMASM_CRYPTO=no
ENABLED_AESGCM_STREAM=no # not yet implemented
ENABLED_ARMASM_NEON=no
ENABLED_ARM_THUMB=yes
ENABLED_ARM_32=yes
AC_MSG_NOTICE([32bit ARMv7-m found])
if test "$ENABLED_FIPS" != "no" ||
test "$HAVE_FIPS_VERSION_MAJOR" -ge 5;
Expand All @@ -3044,6 +3048,7 @@ then
ENABLED_ARMASM_CRYPTO=no
ENABLED_AESGCM_STREAM=no # not yet implemented
ENABLED_ARMASM_NEON=no
ENABLED_ARM_32=yes
AC_MSG_NOTICE([32bit ARMv6 found])
;;
armv4*)
Expand All @@ -3052,6 +3057,7 @@ then
ENABLED_ARMASM_CRYPTO=no
ENABLED_AESGCM_STREAM=no # not yet implemented
ENABLED_ARMASM_NEON=no
ENABLED_ARM_32=yes
AC_MSG_NOTICE([32bit ARMv4 found])
;;
*)
Expand All @@ -3060,6 +3066,7 @@ then
AM_CCASFLAGS="$AM_CCASFLAGS -DEXTERNAL_OPTS_OPENVPN"
ENABLED_ARMASM_CRYPTO=yes
ENABLED_ARMASM_NEON=yes
ENABLED_ARM_32=yes
AC_MSG_NOTICE([32bit ARMv8 found, setting mfpu to crypto-neon-fp-armv8])
;;
esac
Expand Down Expand Up @@ -8357,6 +8364,7 @@ if test "$ENABLED_SP_ASM" = "yes" && test "$ENABLED_SP" = "yes"; then
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_ARM_CORTEX_M_ASM"
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_ARM_CORTEX_M_ASM"
ENABLED_SP_ARM_CORTEX_ASM=yes
ENABLED_ARM_THUMB=yes
;;
*armv6*)
if test "$ENABLED_ARMASM" = "no"; then
Expand Down Expand Up @@ -8935,6 +8943,7 @@ case $host_cpu in
*arm*)
if test "$host_alias" = "thumb" || test "$ARM_TARGET" = "thumb"; then
AM_CFLAGS="$AM_CFLAGS -mthumb -march=armv6"
ENABLED_ARM_THUMB=yes
else
if test "$host_alias" = "cortex" || test "$ARM_TARGET" = "cortex"; then
AM_CFLAGS="$AM_CFLAGS -mcpu=cortex-r5"
Expand Down Expand Up @@ -9755,6 +9764,10 @@ AM_CONDITIONAL([BUILD_ARMASM],[test "x$ENABLED_ARMASM" = "xyes"])
AM_CONDITIONAL([BUILD_ARMASM_INLINE],[test "x$ENABLED_ARMASM_INLINE" = "xyes"])
AM_CONDITIONAL([BUILD_ARMASM_CRYPTO],[test "x$ENABLED_ARMASM_CRYPTO" = "xyes"])
AM_CONDITIONAL([BUILD_ARMASM_NEON],[test "x$ENABLED_ARMASM_NEON" = "xyes"])
AM_CONDITIONAL([BUILD_ARM_THUMB],[test "$ENABLED_ARM_THUMB" = "yes" || test "$ENABLED_USERSETTINGS" = "yes"])
AM_CONDITIONAL([BUILD_ARM_NONTHUMB],[test "$ENABLED_ARM_THUMB" != "yes" || test "$ENABLED_USERSETTINGS" = "yes"])
AM_CONDITIONAL([BUILD_ARM_32],[test "$ENABLED_ARM_32" = "yes" || test "$ENABLED_USERSETTINGS" = "yes"])
AM_CONDITIONAL([BUILD_ARM_64],[test "$ENABLED_ARM_64" = "yes" || test "$ENABLED_USERSETTINGS" = "yes"])
AM_CONDITIONAL([BUILD_RISCV_ASM],[test "x$ENABLED_RISCV_ASM" = "xyes"])
AM_CONDITIONAL([BUILD_XILINX],[test "x$ENABLED_XILINX" = "xyes"])
AM_CONDITIONAL([BUILD_AESNI],[test "x$ENABLED_AESNI" = "xyes"])
Expand Down
63 changes: 39 additions & 24 deletions examples/pem/pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ static int pemApp_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
/* Set data to new pointer. */
data = p;
}
/* Done with file. */
fclose(fp);
}

if (data != NULL) {
Expand Down Expand Up @@ -161,8 +159,6 @@ static int WriteFile(FILE* fp, const char* data, word32 len)
fprintf(stderr, "Failed to write\n");
ret = 1;
}
/* Close file. */
fclose(fp);

return ret;
}
Expand Down Expand Up @@ -766,7 +762,8 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No type string provided\n");
return 1;
ret = 1;
goto out;
}
type_str = argv[0];
}
Expand All @@ -776,16 +773,19 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No filename provided\n");
return 1;
ret = 1;
goto out;
}
if (in_file != stdin) {
fprintf(stderr, "At most one input file can be supplied.\n");
return 1;
ret = 1;
goto out;
}
in_file = fopen(argv[0], "r");
if (in_file == NULL) {
fprintf(stderr, "File not able to be read: %s\n", argv[0]);
return 1;
ret = 1;
goto out;
}
}
/* Name of output file. */
Expand All @@ -794,7 +794,8 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No filename provided\n");
return 1;
ret = 1;
goto out;
}
out_name = argv[0];
}
Expand All @@ -805,7 +806,8 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No filename provided\n");
return 1;
ret = 1;
goto out;
}
offset = (word32)strtoul(argv[0], NULL, 10);
}
Expand All @@ -817,7 +819,8 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No password provided\n");
return 1;
ret = 1;
goto out;
}
info.passwd_cb = password_from_userdata;
info.passwd_userdata = argv[0];
Expand Down Expand Up @@ -846,10 +849,12 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No PBE version provided\n");
return 1;
ret = 1;
goto out;
}
if (StringToPbeVer(argv[0], &pbe_ver) != 0) {
return 1;
ret = 1;
goto out;
}
}
/* PBE algorithm. */
Expand All @@ -859,10 +864,12 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No PBE provided\n");
return 1;
ret = 1;
goto out;
}
if (StringToPbe(argv[0], &pbe) != 0) {
return 1;
ret = 1;
goto out;
}
}
/* PBES2 algorithm. */
Expand All @@ -872,10 +879,12 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No PBE algorithm provided\n");
return 1;
ret = 1;
goto out;
}
if (StringToPbeAlg(argv[0], &pbe_alg) != 0) {
return 1;
ret = 1;
goto out;
}
}
/* Number of PBE iterations. */
Expand All @@ -885,7 +894,8 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No filename provided\n");
return 1;
ret = 1;
goto out;
}
iterations = (unsigned int)strtoul(argv[0], NULL, 10);
}
Expand All @@ -896,13 +906,15 @@ int main(int argc, char* argv[])
argv++;
if (argc == 0) {
fprintf(stderr, "No salt size provided\n");
return 1;
ret = 1;
goto out;
}
salt_sz = (unsigned int)strtoul(argv[0], NULL, 10);
if (salt_sz > SALT_MAX_LEN) {
fprintf(stderr, "Salt size must be no bigger than %d: %d\n",
SALT_MAX_LEN, salt_sz);
return 1;
ret = 1;
goto out;
}
}
#endif /* WOLFSSL_ENCRYPTED_KEYS !NO_PWDBASED */
Expand All @@ -918,12 +930,14 @@ int main(int argc, char* argv[])
else if ((strcmp(argv[0], "-?") == 0) ||
(strcmp(argv[0], "--help") == 0)) {
Usage();
return 0;
ret = 0;
goto out;
}
else {
fprintf(stderr, "Bad option: %s\n", argv[0]);
Usage();
return 1;
ret = 1;
goto out;
}

/* Move on to next command line argument. */
Expand Down Expand Up @@ -1005,6 +1019,7 @@ int main(int argc, char* argv[])
}
}

out:
/* Dispose of allocated data. */
if (der != NULL) {
wc_FreeDer(&der);
Expand All @@ -1025,10 +1040,10 @@ int main(int argc, char* argv[])
fprintf(stderr, "%s\n", wc_GetErrorString(ret));
}

if (in_file != stdin)
if ((in_file != stdin) && (in_file != NULL))
(void)fclose(in_file);

if (out_file != stdout)
if ((out_file != stdout) && (out_file != NULL))
(void)fclose(out_file);

return (ret == 0) ? 0 : 1;
Expand Down
Loading

0 comments on commit b8dff12

Please sign in to comment.