Commit Graph

7262 Commits

Author SHA1 Message Date
Daniel Pouzzner
4b59588cf3 more fixes for implicit casts, mostly asn=original. 2023-04-12 02:17:18 -05:00
Daniel Pouzzner
fe2acb53af wolfcrypt/src/ecc.c:fix overstringent arg check in wc_ecc_gen_k(). 2023-04-12 01:37:09 -05:00
Daniel Pouzzner
7155c5748e fix overlong lines. 2023-04-12 01:37:09 -05:00
Daniel Pouzzner
99ffd7726f wolfcrypt/src/pkcs7.c:wc_PKCS7_DecodeAuthEnvelopedData(): fix clang-analyzer-core.DivideZero (expBlockSz not properly set before use as a denominator in a mod op). 2023-04-12 01:37:09 -05:00
Daniel Pouzzner
ed11669f3c more fixes for implicit casts, including asn=template. 2023-04-12 01:37:09 -05:00
David Garske
72c6429276 Better fixes for pedantic to resolve (error: comparison of unsigned expression >= 0 is always true). Also overlong lines. 2023-04-12 01:37:09 -05:00
David Garske
6418e3cbfe Fixes for implicit casts.
Tested with `./configure --disable-asm --enable-32bit --enable-asn=original --enable-cryptonly CFLAGS="-Wconversion -pedantic" && make`. Some progress with ASN template, but not complete.
2023-04-12 01:37:09 -05:00
billphipps
0013be9027 15451 correct padding for pkcs7 (#6260)
* Update to ensure full blocks for crypto in En/DecodeAuthEnvelopedData.

* Corrected spacing and comments

* Set plain to NULL after free on non-error path.
2023-04-10 14:08:52 -07:00
David Garske
f2ae066797 Merge pull request #6281 from JacobBarthelmeh/ECC
- fix ECC performance regression
2023-04-10 14:08:43 -07:00
JacobBarthelmeh
8bb0b2ef3f fix for ECC sign with nonblocking only 2023-04-10 12:53:40 -07:00
David Garske
6b862a1440 Merge pull request #6272 from gojimmypi/wolfcrypt-mpi-fix
mp_setneg(Z), not mpi
2023-04-10 11:58:04 -07:00
Jacob Barthelmeh
582d8a70f5 fix ECC performance regression 2023-04-09 00:08:01 -06:00
JacobBarthelmeh
12e285434b Merge pull request #6275 from douzzer/20230406-XREWIND-fixes-contd
20230406-XREWIND-fixes-contd
2023-04-06 15:22:48 -06:00
Daniel Pouzzner
7c15131db5 wolfcrypt/src/asn.c: in wc_PemCertToDer_ex() and wc_PemPubKeyToDer_ex(), work around false positive -Wmaybe-uninitialized from scan-build. 2023-04-06 15:15:26 -05:00
JacobBarthelmeh
012f0e0779 Merge pull request #6262 from SparkiDev/mp_int_mem_usage
SP int: improve use of stack
2023-04-06 14:06:08 -06:00
Daniel Pouzzner
3468750bae wolfcrypt/src/asn.c:
* refactor error-checking cascade in wc_PemCertToDer_ex() as in wc_PemPubKeyToDer_ex(),
 * refactor staticBuffer gating/dynamics in wc_PemPubKeyToDer_ex() as in wc_PemCertToDer_ex(),
 * and use IO_FAILED_E, not BUFFER_E, for I/O errors on the file handles, in both routines;

fix smallstack null pointer dereferences in src/pk.c:wolfSSL_RSA_GenAdd() and src/ssl.c:set_curves_list().
2023-04-06 14:31:53 -05:00
Daniel Pouzzner
dcc8b5d7d5 eliminate XREWIND() macro, add XSEEK_SET definitions, and refactor all XREWIND()s to XFSEEK()s, to fix clang-tidy-17 bugprone-unsafe-functions warning on rewind();
add BENCH_DEVID_COLUMN_HEADER in wolfcrypt/benchmark/benchmark.c:bench_stats_sym_finish() to resolve clang-diagnostic-embedded-directive.
2023-04-05 20:28:51 -05:00
Sean Parkinson
8065139050 SP int: improve use of stack
Minimize use of stack.
Make very large stack allocations dynamic memory allocations unless
WOLFSSL_SP_NO_MALLOC.

ProcessBufferTryDecode() split up into a function for each type.
ProcessBufferTryDecodeRsa() decodes the data and gets key size rather
than having or allocating an RsaKey.
Added wc_RsaPrivateKeyValidate() that only validates the encoding is an
RSA key and returns the key size in bytes.

For SP int, only create sp_ints of required size in RSA and ECC
implementation. For WOLFSSL_SMALL_STACK, memory is allocated to have
just enough bytes and size is set to maximum supported. Otherwise,
relies on dynamic stack variables.
For ECC, MAX_ECC_BITS_USE used when dynamic stack variables not
supported. Significantly reduces memory usage when RSA/DH is also built.

Add macros to sp_int.h, tfm.h and integer.h to support declaring,
allocating, initializing and freeing mp_ints.
For integer.h, mp_int is always static as size is no more than 32 bytes.
For tfm.h, WOLFSSL_SMALL_STACK has a full mp_int allocated, otherwise
the full mp_int is put on the stack.
For sp_int.h  with new macros, dynamically allocate sp_int to minimal
size when WOLFSSL_SMALL_STACK, or when dynamic stack variables, declare
them to be of minimal size or otherwise declare with a fixed max.
Added mp_bitsused(), for all implementations, to get the number of bits
available based on used. Included for RSA to get the size of the
modulus.

SP int now always uses dynamic stack variables if possible rather than
for builds with WOLFSSL_SP_SMALL.
Moved code out into separate functions so that stack allocations don't
happen when not going down code path.
2023-04-06 10:04:39 +10:00
JacobBarthelmeh
1bef3ec745 Merge pull request #6233 from embhorn/gh6209
Support HAVE_SESSION_TICKET without realloc
2023-04-05 15:17:58 -06:00
Eric Blankenhorn
d9bf93b49f Support HAVE_SESSION_TICKET without realloc 2023-04-05 11:33:06 -05:00
gojimmypi
bb32b6a927 mp_setneg(Z), not mpi 2023-04-05 17:10:37 +02:00
Sean Parkinson
10c1009bbd Merge pull request #6127 from JacobBarthelmeh/qnx
IMX6Q CAAM Port
2023-04-05 08:44:00 +10:00
David Garske
a4a6a05f06 Merge pull request #6251 from PrinceOfPuppers/master
updated zephyr includes
2023-04-03 16:25:32 -07:00
JacobBarthelmeh
f9f1347e8d third optimization pass with aes-ctr 2023-04-03 16:41:09 -06:00
JacobBarthelmeh
14b0f422c8 optimization pass through 2 2023-04-03 16:41:08 -06:00
JacobBarthelmeh
30adcd58d8 IMX6Q CAAM Port 2023-04-03 16:41:08 -06:00
David Garske
b1e4d4922e Merge pull request #6259 from SparkiDev/cppcheck_fixes_9
cppcheck fixes
2023-04-03 15:35:35 -07:00
Daniel Pouzzner
c08878ac94 configure.ac: include both -I. and -I$srcdir for "circular dependency" test, so that ${build_pwd}/wolfssl/options.h is found in out-of-tree builds; streamline scripting that dynamically sets $TRIM;
linuxkm/module_exports.c.template: include wolfssl/wolfcrypt/wolfmath.h, to bring in wc_GetMathInfo() prototype;

src/ssl.c: move "Global pointer to constant BN on" to src/ssl_bn.c; and in wolfSSL_Cleanup(), call the new wolfSSL_BN_free_one() rather than using ad hoc cleanup logic;

src/ssl_bn.c: add bn_one and wolfSSL_BN_free_one();

src/ssl_asn1.c: fix bugprone-macro-parentheses in bufLenOrNull(); refactor wolfSSL_ASN1_TIME_diff() to avoid floating point math; use intermediate tm_year variable in wolfssl_asn1_time_to_tm() to avoid target-specific type conflicts on tm->tm_year; use "FALL_THROUGH", not "/* fall-through */", in wolfSSL_ASN1_TYPE_set (clang-diagnostic-implicit-fallthrough);

wolfcrypt/src/ecc.c: fix identicalInnerCondition in ecc_mul2add();

wolfcrypt/src/integer.c: refactor OPT_CAST()s in mp_grow() to unconditional casts as elsewhere, to mollify a confused cppcheck-all-intmath;

tests/api.c: reformat some overlong lines.
2023-04-03 15:49:39 -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
David Garske
753ad4c4c1 Merge pull request #6253 from JacobBarthelmeh/CAAM
resolve warning about uninitialized variable
2023-03-31 10:50:28 -07:00
Sean Parkinson
8489095057 Move ASN.1 APIs out to separate file: ssl_asn1.c
Implementations of ASN.1 APIs reworked.

Added tests.

Added wolfssl_bn_set_neg for ASN.1 code.
Added wolfssl_sk_new_type() and wolfssl_sk_pop_type() to generically
handle creating and popping a stack of elements of a type.

No longer freeing pathlen field of ASN1 OBJECT in
wolfSSL_X509_EXTENSION_free(). This is happening in
wolfSSL_ASN1_OBJECT_free().
Stop wolfSSL_i2d_X509_NAME_canon from double freeing ASN.1 STRING's data
field.

Fixed up GetFormattedTime() to be better code.
Added ASN_CLASS_MASK to mask off the class part of an ASN.1 tag.
NO_ASN_TIME means no implementation to get the current time. Disable
features that won'r work without time.
2023-03-31 09:36:01 +10:00
David Garske
22a5a5c45e Add introspection for math build and math cleanups:
* Add introspection for math build.
* Raise build error if more than one multi-precision math library used.
* Fix ESP32 to support using any multi-precision math option.
* Refactor math headers to use `wolfmath.h`
* Refactor of the opaque math variable type `MATH_INT_T` used by crypto hardware (QuickAssist, SE050, ESP32 and STM32).
* Cleanups for building with `WOLFCRYPT_ONLY` and `NO_BIG_INT`.
* Stop forcing use of fast math by default for platforms in settings.h. Note: For users that still want to use fast math (tfm.c) they will need to add USE_FAST_MATH to their build settings.

Applies To:
```
WOLFSSL_ESPWROOM32
WOLFSSL_ESPWROOM32SE
MICROCHIP_PIC32
WOLFSSL_PICOTCP_DEMO
WOLFSSL_UTASKER
WOLFSSL_NRF5x
FREERTOS_TCP
WOLFSSL_TIRTOS
EBSNET
FREESCALE_COMMON
FREESCALE_KSDK_BM
WOLFSSL_DEOS
MICRIUM
WOLFSSL_SGX
```
2023-03-30 14:42:55 -07:00
Jacob Barthelmeh
f7d3ce7843 resolve warning about uninitialized variable 2023-03-30 11:44:08 -06:00
Sean Parkinson
0210dcd98d Merge pull request #6240 from kaleb-himes/wolfEntropy-work
Fix a typo in PP macro and add a ceiling to guard against implementation bugs
2023-03-30 12:33:01 +10:00
PrinceOfPuppers
9b1aed0c82 updated zephyr includes 2023-03-29 22:22:31 -04:00
David Garske
8b34ad7c4d Merge pull request #6245 from lealem47/asyncRelease
Fixes for the async release
2023-03-29 12:33:57 -07:00
David Garske
3841b559ec Merge pull request #6246 from SparkiDev/siphash_asm_fix
siphash: fix assembly so that no register is left behind
2023-03-29 09:23:38 -07:00
Lealem Amedie
047db19956 Disable SHA512/224 & SHA512/256 on QAT 2023-03-29 10:17:06 -06:00
David Garske
689b0f803a Merge pull request #6237 from SparkiDev/benchmark_base10
Benchmark: fix reporting of base10
2023-03-29 08:25:29 -07:00
Sean Parkinson
ca11b4e560 siphash: fix assembly so that no register is left behind
Change all assembly so that no register is used explicitly - all
variables.
2023-03-29 09:38:04 +10:00
kaleb-himes
59107aeaa8 Fix a typo in PP macro and add a ceiling to guard against implementation bugs 2023-03-27 16:02:34 -06:00
Chris Conlon
496a15037b Merge pull request #6166 from TakayukiMatsuo/tsip117 2023-03-27 11:49:18 -06:00
Sean Parkinson
5f2208e71d Benchmark: fix reporting of base10 2023-03-27 16:29:47 +10:00
JacobBarthelmeh
e0e590f126 Merge pull request #6223 from lealem47/misc_fixes
Async build typos and miscellaneous fixes
2023-03-23 23:55:20 +07:00
David Garske
3ef7db8e1b Merge pull request #6229 from JacobBarthelmeh/Testing
fix for check on ecc public key size with FIPS and compressed keys
2023-03-23 08:25:31 -07:00
JacobBarthelmeh
a121a5c270 Merge pull request #6225 from SparkiDev/memzero_check_fixes_1
MemZero check fixes
2023-03-23 21:04:39 +07:00
JacobBarthelmeh
25577ab96c fix for check on ecc public key size with FIPS and compressed keys 2023-03-23 06:58:03 -07:00
Sean Parkinson
d1e4349661 MemZero check fixes
ForceZero the client and server secret regardless of whether TLS 1.3 as
it may change but have been copied in.
ForceZero the input buffer in wolfSSL_Clear() when encryption was on.

Changed wc_PRF_TLS to only check the parts of data used.
Changed where scatch is added for checking in wc_AesCtrEncrypt.
Change wc_MakeRsaKey to memset p, q, tmp1, tmp2 and tmp3 to all zeros so
that MemZero check works. Memset not needed otherwise.
Changes for new compiler - thinks uninitialized.
2023-03-23 12:27:38 +10:00
Lealem Amedie
c83e899b78 Fix for overlong string warning 2023-03-22 17:29:53 -06:00
Lealem Amedie
a5e7a20c93 Fix for logic gating strerror_r() 2023-03-22 17:29:13 -06:00