Commit Graph
81 Commits
Author SHA1 Message Date
David Garske b6be0c878d wolfcrypt: add WOLFSSL_WIDE_BYTE support for CHAR_BIT != 8 targets (TI C2000 C28x) - core types, misc octet helpers, base64, DRBG 2026-08-06 16:55:09 -07:00
Daniele Lacamera 413fcc5505 coding: remove unreachable in operand in Base16_Decode
Premise:  coding.c:660 `if (in == NULL || out == NULL || outLen == NULL)
          return BAD_FUNC_ARG;` establishes in != NULL unconditionally -- note
          it is stronger than the Base64 entry checks, which only reject a NULL
          input when inLen > 0.
Claim:    coding.c:663 `if (inLen == 1 && *outLen && in)` -- the `in` operand.
Proof:    in is a parameter and is never reassigned; reaching :663 implies the
          :660 check did not fire, hence in != NULL. The operand is invariantly
          true and its independence pair is unreachable.
Scope:    the whole function is inside a single WOLFSSL_BASE16 block with no
          nested #if in the span, so the argument holds in every configuration
          that compiles it.
Evidence: llvm-cov MC/DC records this condition's pair as uncovered
          (reports/coding/GAPS.md row 663:9:663:36:2).

Compiler cross-check: gcc -O2 emits byte-identical code for this file before
and after this commit -- the optimiser had already folded the removed
condition, independently confirming it was dead.
2026-07-31 15:37:10 +02:00
Daniele Lacamera 03e40fdc25 coding: remove unreachable out operand in the Base64 decoders
Premise:  coding.c:177 (Base64_Decode_nonCT) and coding.c:298 (Base64_Decode)
          both open with
            if ((in == NULL && inLen > 0) || out == NULL || outLen == NULL)
                return BAD_FUNC_ARG;
          which establishes out != NULL for the rest of each function.
Claim:    coding.c:281 and coding.c:395, `if (out && *outLen > i)` -- the `out`
          operand in both.
Proof:    out is a parameter and is never reassigned in either function; the
          only uses between the entry check and the null-terminator write are
          subscripted stores (out[i]). Reaching :281 / :395 therefore implies
          out != NULL, so the operand is invariantly true and its independence
          pair is unreachable.
Scope:    neither function contains an #if/#ifdef in the span. Base64_Decode_nonCT
          is compiled under !BASE64_NO_TABLE and aliased to Base64_Decode under
          BASE64_NO_TABLE (:404-408); both variants carry the same entry check,
          so the argument holds either way.
Evidence: llvm-cov MC/DC records both conditions' pairs as uncovered
          (reports/coding/GAPS.md rows 281:9:281:27:0 and 395:9:395:27:0).

Deliberately untouched: the textually identical line in DoBase64_Encode
(coding.c:608). There out == NULL is the documented size-query mode
(`getSzOnly = (out == NULL)` at :520, returning LENGTH_ONLY_E), so that operand
is live and load-bearing -- base64_test exercises it.

Compiler cross-check: gcc -O2 emits byte-identical code for this file before
and after this commit -- the optimiser had already folded the removed
condition, independently confirming it was dead.
2026-07-31 15:37:05 +02:00
Daniele Lacamera 00f098e6ed coding: remove unreachable len operand in Base64_SkipNewline
Premise:  coding.c:127 `if (len == 0) { return BUFFER_E; }` establishes len >= 1
          on every path that continues.
Claim:    coding.c:137 `if (len && (curChar == '\r' || curChar == '\n'))` --
          the `len` operand.
Proof:    len is only written between :127 and :137 by the loop at :132,
          `while (len > 1 && curChar == ' ') { ...; len--; }`, whose guard
          admits the decrement only when len > 1. So the loop preserves
          len >= 1, and len >= 1 => the `len` operand is invariantly true.
          Its false half, and therefore its MC/DC independence pair, is
          unreachable.
Scope:    no #if/#ifdef occurs between :120 and :166; the whole function sits
          inside one uniform WOLFSSL_BASE64_DECODE block. The argument holds
          in every configuration that compiles the function.
Evidence: llvm-cov MC/DC records this condition's pair as uncovered
          (reports/coding/GAPS.md row 137:9:137:52:0).

The later `if (len)` at :141/:151 and `while (len && ...)` at :155 stay: the
decrements at :139/:143 can drive len to 0 before those are evaluated.

Compiler cross-check: gcc -O2 emits byte-identical code for this file before
and after this commit -- the optimiser had already folded the removed
condition, independently confirming it was dead.
2026-07-31 15:21:09 +02:00
philljj 98f4d6f955 Merge pull request #10721 from JacobBarthelmeh/dev_2
Defensive code additions for sanity checks on input arguments with Base64, PEM write, mp_read_unsigned_bin
2026-07-17 15:34:35 -05:00
David Garske a962793323 Merge pull request #10704 from aidangarske/length-width-hardening
Length Width Hardening
2026-07-10 08:00:39 -07:00
JacobBarthelmeh a3e8bab10c hardening against potential overflow cases 2026-07-07 16:03:30 -06:00
Daniel Pouzzner 2af2a2967f fix F-3085 "Base64_Decode silently returns success with outLen=0 when input is a 1-3 byte truncated base64 fragment, violating decode(encode(x)) roundtrip for inputs producing 2-3 base64 chars without padding"
wolfcrypt/src/coding.c: in Base64_Decode() and Base64_Decode_nonCT(), check for non-whitespace characters past the end and return ASN_INPUT_E if found;

wolfcrypt/test/test.c: in base64_test(), remove ';' from goodChar[], and add trailing*[] test strings and N_BYTE_TRAILING_TEST(), for positive and negative testing of new checks.
2026-06-29 23:48:36 -05:00
aidan garske 699744c8b6 Guard Base16_Encode output sizing against word32 wraparound 2026-06-16 12:38:26 -07:00
Jeremiah Mackey 3aa9a58b74 move length check before dispatch 2026-04-13 15:52:45 +00:00
Jeremiah Mackey 362eda5b25 add NULL checks to Base64 encode/decode 2026-04-13 15:50:52 +00:00
JacobBarthelmeh a156ed7bc7 update Copyright year 2026-02-18 09:52:21 -07:00
Daniel Pouzzner 7fe890d5e7 wolfcrypt/src/coding.c: clean up comment in Base64_Decode(), per peer review. 2025-08-13 18:00:36 -05:00
Daniel Pouzzner 344db9d7f7 wolfcrypt/src/coding.c: in Base64_Decode_nonCT() and Base64_Decode(), remove overly restrictive preamble check on outLen; return BUFFER_E, not BAD_FUNC_ARG, when output buffer is too short (similarly fixed in Base16_Decode());
wolfcrypt/test/test.c: add N_BYTE_TEST() and test vectors to test all input and output length scenarios.
2025-08-13 17:43:33 -05:00
JacobBarthelmeh 629c5b4cf6 updating license from GPLv2 to GPLv3 2025-07-10 16:11:36 -06:00
Daniel Pouzzner c401f5caf2 move the newly added wolfcrypt/src/wolfssl_sources.h to wolfssl/wolfcrypt/libwolfssl_sources.h, and likewise for wolfssl_sources_asm.h; revert changes to IDE/ project files. 2025-04-04 18:44:12 -05:00
Daniel Pouzzner 217440c885 Add wolfcrypt/src/wolfssl_sources.h and wolfcrypt/src/wolfssl_sources_asm.h,
which force on BUILDING_WOLFSSL and do boilerplate includes, and update library
  sources to include them at the top.

  wolfssl_sources.h includes types.h, error-crypt.h, and logging.h, and
  conditionally, config.h.  settings.h and wc_port.h are unconditionally
  included at the top of types.h.

  wolfssl_sources_asm.h includes settings.h, and conditionally, config.h.

Add wolfssl_sources*.h to wolfcrypt/src/include.am, and to several IDE/ project
  files.

Also added a TEST_WOLFSSL_SOURCES_INCLUSION_SEQUENCE clause in
  wolfssl/wolfcrypt/settings.h to allow coverage testing.

In wolfcrypt/src/misc.c, retain existing ad hoc boilerplate includes, and use
  them if WOLFSSL_VIS_FOR_TESTS, otherwise include the new wolfssl_sources.h.

Define WOLFSSL_VIS_FOR_TESTS at top of wolfcrypt/test/test.c.

Also renamed WOLFSSL_NEED_LINUX_CURRENT to WOLFSSL_LINUXKM_NEED_LINUX_CURRENT,
  for clarity.
2025-04-04 16:51:04 -05:00
Daniel Pouzzner e0a74420f1 wolfcrypt/src/coding.c: restore support for BASE64_NO_TABLE builds. 2025-04-02 17:14:09 -05:00
Daniel Pouzzner c2b486ce53 fix some misindentation in wolfcrypt/src/coding.c.
force lower CMAKE_POLICY_VERSION_MINIMUM to try to work around obsolete cmake config syntax in several OSP workflows.
2025-04-02 17:08:20 -05:00
Daniel Pouzzner 51c6848340 wolfcrypt/src/coding.c, wolfssl/wolfcrypt/coding.h, wolfcrypt/src/asn.c,
wolfcrypt/test/test.c: refactor Base64_Decode() with separate always-CT
  Base64_Decode() and never-CT Base64_Decode_nonCT(), and use the latter only to
  decode known-public PEM objects, otherwise use always-CT Base64_Decode().
2025-04-02 17:08:20 -05:00
Sean Parkinson 4752bd2125 Constant time code: improved implementations
Change constant time code to be faster.
2025-02-26 11:52:09 +10:00
Daniel Pouzzner 0de38040f4 CT tweaks:
in wolfcrypt/src/coding.c, add ALIGN64 to hexDecode[], and add hexEncode[] for use by Base16_Encode();

in wolfcrypt/src/misc.c and wolfssl/wolfcrypt/misc.h:

move ctMask*() up so that min() and max() can use them, and add ctMaskWord32GTE();

add ALIGN64 to kHexChar[];

add CT implementation of CharIsWhiteSpace();

remove min_size_t() and max_size_t() recently added, but only one user (refactored).
2025-01-30 01:24:40 -06:00
JacobBarthelmeh 2c24291ed5 update copyright date 2025-01-21 09:55:03 -07:00
Daniel Pouzzner b07f2cb461 wolfcrypt/src/coding.c: fix incorrect array bounds check in CEscape(), introduced in 8bbe8a7c8a (before which there was no bounds check at all). 2024-12-21 09:47:07 -06:00
Kareem 8bbe8a7c8a Fix a couple of missing bounds checks found via code analyzer. 2024-12-19 17:01:25 -07:00
Daniel Pouzzner 122502e2b1 wolfCrypt -Wconversion expansion: fix numerous warnings, all benign, from -Warith-conversion -Wenum-conversion -Wfloat-conversion -Wsign-conversion. 2024-12-18 11:51:06 -06:00
Daniel Pouzzner c81c9be9ce error code fixes:
* fix TLS layer to consistently use WOLFSSL_FATAL_ERROR for error retvals, rather than literal -1.
* add WC_NO_ERR_TRACE() wrapper around LENGTH_ONLY_E (it does not signify an error condition).
* refactor errcode handling for traceability in wolfSSL_DSA_do_sign(), wolfSSL_DH_size(), wolfSSL_EC_KEY_get_conv_form(), wolfSSL_d2i_DSA_SIG(), wolfSSL_DSA_do_sign(), SetDhInternal(), and wolfSSL_EC_KEY_get_conv_form().
2024-09-06 19:33:48 -05:00
JacobBarthelmeh 31a6a2bf59 update copyright to 2024 2024-07-19 13:15:05 -06:00
Daniel Pouzzner b3e8f0ad24 add --enable-debug-trace-errcodes, WOLFSSL_DEBUG_TRACE_ERROR_CODES, WC_ERR_TRACE(), WC_NO_ERR_TRACE(), support/gen-debug-trace-error-codes.sh. also add numerous deployments of WC_NO_ERR_TRACE() to inhibit frivolous/misleading errcode traces when -DWOLFSSL_DEBUG_TRACE_ERROR_CODES. 2024-06-08 16:39:53 -05:00
Daniel Pouzzner f2c97d5d35 fixes for various wolfcrypt -Wconversions visible only on compilers that promote byte and word16 to signed int, then warn of a sign conflict when an intrinsically safe result is assigned back to the original type. 2023-05-09 23:55:08 -05:00
Daniel Pouzzner ac85cfa3d5 fix "comma at end of enumerator list" warnings in wolfcrypt for C89 compatibility, mostly by just snipping out unneeded comma, but several using WOLF_ENUM_DUMMY_LAST_ELEMENT() to preserve gated enum values as-is. 2023-04-14 13:48:03 -05:00
Sean Parkinson 8851065848 cppcheck fixes
Fix checking of negative with unsigned variables.
Check digestSz for 0 in wc_SSH_KDF() so that no possibility of dividing
by zero.
Change XMEMCPY to XMEMSET in renesas_sce_util.c.
Fix test.c to free prvTmp and pubTmp on read error.
Remove unused variables.
XFREE checks for NULL so don't check before call.
Move variable declarations to reduce scope.
2023-04-03 16:59:58 +10:00
Jacob Barthelmeh 9dcc48c8f7 update copyright to 2023 2022-12-30 17:12:11 -07:00
Kareem c146fcf581 Update Base16_Encode so the ending null terminator is optional. 2022-09-20 14:44:01 -07:00
Jacob Barthelmeh 8eaa85e412 update copyright year to 2022 2022-07-19 10:44:31 -06:00
TakayukiMatsuo 9e02655ac4 Merge remote-tracking branch 'upstream/master' into os_base64 2021-06-16 23:19:52 +09:00
Guido Vranken 220bfe9926 Fix Base64_SkipNewline such that tests pass 2021-06-14 03:42:41 +02:00
Guido Vranken fb366f063e Additional length check improvements in Base64_SkipNewline 2021-06-09 19:16:07 +02:00
Guido Vranken 360d6c8a4f Additional fix for Base64_SkipNewline 2021-05-26 00:25:27 +02:00
Guido Vranken b7663a51b4 Fix length calculations in Base64_SkipNewline
ZD 12328
2021-05-25 03:52:16 +02:00
Eric Blankenhorn cdede0515c Allow parsing spaces in Base64_SkipNewline 2021-04-28 10:30:16 -05:00
TakayukiMatsuo 9fd8fde714 Add fixes along the review commnents. 2021-03-16 11:55:18 +09:00
Jacob Barthelmeh c729318ddd update copyright date 2021-03-11 13:42:46 +07:00
Sean Parkinson cd0670cbd7 RSA: verify only build fixes
configuration: --disable-ecc --disable-dh --disable-aes --disable-aesgcm
--disable-sha512 --disable-sha384 --disable-sha --disable-poly1305
--disable-chacha --disable-md5 --disable-sha3 --enable-cryptonly
--disable-inline --enable-rsavfy --disable-asn --disable-oaep
--disable-rng --disable-filesystem --enable-sp=rsa2048 --enable-sp-math
Fixes to make code build again.
2021-01-06 11:58:15 +10:00
Sean Parkinson 75c062a298 cppcheck: fixes 2020-12-16 17:28:20 +10:00
Sean Parkinson 972d6cfefc Base64: Cache attack resistant decode 2020-12-15 17:22:02 +10:00
Tesfa Mael d5241bbcc6 Coverity fix 2020-06-02 15:35:27 -07:00
David Garske a4caa42793 Improve the Base64 line size for NO_ASN case. Fix report of unread ret. 2020-04-24 11:26:55 -07:00
David Garske 28b686a8ca * Exposed useful sizes MAX_X509_HEADER_SZ and PEM_LINE_SZ
* Refactor the PEM saving code in `test.c`, so its not using large 4K buffer and calculates based on DER.
* Enable ECC key generation test even without `WOLFSSL_KEY_GEN`.
* Added `ECC_KEYGEN_SIZE` macro for ECC key generation testing.
* Refactor ECC DER key generation to use `ECC_BUFSIZE`.
2020-04-23 16:11:54 -07:00
Juliusz Sosinowicz 43ce272cb3 Variable declaration at start of scope 2020-02-18 21:37:06 +01:00