summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/recallocarray.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2023-03-15Return the signature length after successful signing operationtb1-1/+3
This is required behavior of the EVP_DigestSign() API, but seemingly almost nothing uses this. Well, turns out ldns does. Reported by Stephane. Helpful comments by sthen. ok jsing
2023-03-15Add comments that explain why things are done in this strange order.tb1-3/+13
There's some method to this madness. ok jsing
2023-03-15Push calloc() of ndef_aux down as far as possible andtb1-7/+8
pull the setting of the ex_arg up, so we can do error checking. ok jsing
2023-03-15Error check BIO_asn1_set_{prefix,suffix}() callstb1-3/+5
ok jsing
2023-03-15Streaming BIOs assume they can write to NULL BIOstb1-5/+4
At least SMIME_text() relies on this. Pushing an error on the stack trips PKCS7 regress in py-cryptography, so indicate nothing was written instead of throwing an error. Reported by Alex Gaynor a while back ok jsing
2023-03-15Ensure negative input to BN_mod_exp_mont_consttime() is correctly reduced.jsing1-7/+4
A negative input to BN_mod_exp_mont_consttime() is not correctly reduced, remaining negative (when it should be in the range [0, m)). Fix this by unconditionally calling BN_nnmod() on the input. Fixes ossfuzz #55997. ok tb@
2023-03-15Include tests with negative values in BN_mod_exp* regress.jsing1-2/+15
This currently fails.
2023-03-15bn_mod_exp_zero: rename result into gottb1-14/+14
2023-03-13Stop confusing out and asn_bio in BIO_new_NDEF()tb1-4/+4
BIO_new_NDEF() sets up an ASN.1 BIO to the output chain and then adds even more BIOs. Since BIO_push(bio, new_tail) returns bio on success, after the if ((out = BIO_push(asn_bio, out)) != NULL) the 'out' BIO and the 'asn_bio' are the same. The code then goes on and uses one or the other. This is very confusing. Simply stop using out once it's appended to asn_bio. ok jsing
2023-03-12pk7_cb() and cms_cb()tb2-5/+8
Add and fix FALLTHROUGH statement. I was confused for way too long since I hadn't noticed that this case fell through to the next. Also add and move some empty lines in the cms_cb() to make this resemble KNF more.
2023-03-12Avoid an 1 byte out-of-bounds read in ASN1_PRINTABLE_type()tb1-2/+2
In case the input is not NUL terminated, the reversed check for length and terminating NUL results in a one-byte overread. The documentation says that the input should be a string, but in ASN.1 land you never know... Reported by Guido Vranken a while back ok beck
2023-03-11Remove a few extra spacestb1-2/+2
2023-03-11Switch an early return into goto errtb1-2/+2
2023-03-11Tiny cleanup for readabilitytb1-4/+5
Turn a malloc() into calloc() and check two function calls directly forever instead of a combined check afterward.
2023-03-11Use "if (ptr == NULL)" instead of "if (!ptr)"tb1-3/+3
Requested by jsing
2023-03-11Fix double free after BIO_new_NDEF()tb1-6/+7
Once the asn_bio is prepended to the out chain, and before the asn1_cb() has done its thing, asn_bio needs to be popped off again on error. Failing to do this can cause write after frees or double frees when the out BIO is used after the function returned. Based on a very complicated diff by Matt Caswell and Viktor Dukhovni. This was part of the fixes in OpenSSL 1.1.1t. ok jsing
2023-03-11Fix an off-by-one in dsa_check_key()tb1-2/+2
The private key is a random number in [1, q-1], so 1 must be allowed. Since q is at least an 160-bit prime and 2^159 + 1 is not prime (159 is not a power of 2), the probability that this is hit is < 2^-159, but a tiny little bit wrong is still wrong. Found while investigating a report by bluhm ok jsing
2023-03-11Call CRYPTO_cleanup_all_ex_data() from OPENSSL_cleanup().jsing1-0/+1
Issue reported by Graham Percival (@gperciva) ok tb@
2023-03-11Add OPENSSL_cleanup() calls to some regress.jsing2-2/+6
This gets us some minimal test coverage.
2023-03-11Avoid -0 in BN_div_word().jsing1-1/+5
Currently, the use of BN_div_word() can result in -0 - avoid this by setting negative again, at the end of the computation. Should fix oss-fuzz 56667. ok tb@
2023-03-11Correct sign handling in BN_add_word().jsing1-3/+3
A sign handling bug was introduced to BN_add_word() in bn_word.c r1.18. When handling addition to a negative bignum, the BN_sub_word() call can result in the sign being flipped, which we need to account for. Use the same code in BN_sub_word() - while not technically needed here it keeps the code consistent. Issue discovered by tb@ ok tb@
2023-03-11Remove a pesky space.jsing1-2/+2
2023-03-11Add regress coverage for BN_{add,sub,mul,div,mod}_word().jsing2-1/+619
This also provides some indirect coverage for BN_hex2bn(), BN_bn2hex() and BN_get_word(). Two of these tests are currently failing and will be fixed shortly.
2023-03-11Mark test table as static const.jsing1-2/+2
2023-03-10Crankl libcrypto/libssl/libtls minors after symbol additiontb3-3/+3
2023-03-10Update Symbols.listtb1-0/+18
2023-03-10Expose various X509_STORE_*check_issued()tb1-3/+1
2023-03-10Expose X509_CRL_get0_sigalg() and X509_get0_uidstb1-5/+1
2023-03-10Expose UI_null()tb1-3/+1
2023-03-10Expose the EVP_CIPHER_meth_* API (setter only) in evp.htb1-3/+1
2023-03-10ASN.1 BIO: properly wire up prefix_free and suffix_freetb1-1/+7
If something goes wrong before the ASN.1 BIO state machine has passed both flushing states, asn1_bio_free() forgets to free the ndef_aux and the ex_arg since the prefix_free() and suffix_free callbacks are not called. This can lead to leaks, notably in streaming bios. Part of https://github.com/openssl/openssl/pull/15999 I have a regress covering this but it is not yet ready to land. ok beck jsing
2023-03-10Return the correct type for ASN.1 BOOLEANstb1-5/+9
ASN.1 BOOLEANs and ASN.1 NULL are handled specially in the ASN.1 sausage factory and they are special in that they don't have a->value.ptr set. Both need to be special cased here since they fail the a->type.ptr != NULL check. Apart from fixing an obvious bug in ASN1_TYPE_get(), this fixes another crash in openssl(1) asn1parse. There is more to do in the vicinity, but that is more complex and will have to wait for OpenBSD 7.3-current. with/ok jsing
2023-03-10openssl(1) asn1parse: avoid crash with ASN.1 BOOLEANStb1-3/+4
When pointing openssl asn1parse -strparse at DER octets 01 01, it crashes: $ printf '<\x01\x01>' | openssl asn1parse -inform der -strparse 1 Refuse to parse BOOLEAN types instead, which avoids a crash in hensonian /* hmm... this is a little evil, but it works */ code. Found while poking at CMS timestamps to understand one of job's diffs. with/ok jsing
2023-03-09Add missing error checking in PKCS7tb1-3/+11
Check the return value of BIO_set_md(). Prompted by OpenSSL's fix for CVE-2023-0401 (the crash in that bug is an OpenSSL 3-only problem due to provider design). ok beck jsing
2023-03-08Use BN_free() instead of BN_clear_free()tb1-2/+2
2023-03-08Fix a EC_GROUP_clear_free() that snuck through.jsing1-2/+2
Thanks to Mark Patruck for reporting.
2023-03-08Fix previous.jsing1-5/+5
2023-03-08reduce number of tests in bn_rand_interval.tb1-2/+2
This is only testing basic functionality anyway, so 10000 tests are more than enough.
2023-03-08bn_isqrt: reduce number of tests to 100.tb1-2/+2
The runtime is roughly quadratic in N_TESTS. While it only takes 1-2s on modern machines, this test takes a long time on slow machines. A reduction of runtime by a factor of ~16 is significant.
2023-03-08Process up to four test vector files concurrently.jsing1-4/+30
This avoids having a slow down when processing test vector files that only have a single group. Note that the processing of test vector files is in turn going to be rate limited by the number of concurrent test groups, which means we do not need variable limits for vectors. Reduces a Wycheproof regress run down to ~8 seconds on an Apple M1.
2023-03-08Always clear EC groups and points on free.jsing10-114/+35
Rather than sometimes clearing, turn the free functions into ones that always clear (as we've done elsewhere). Turn the EC_GROUP_clear_free() and EC_POINT_clear_free() functions into wrappers that call the *_free() version. Do similar for the EC_METHOD implementations, removing the group_clear_finish() and point_clear_finish() hooks in the process. ok tb@
2023-03-08Run test groups concurrently.jsing1-144/+151
Add a basic test coordinator, that allows for Wycheproof test groups to be run concurrently. This can be further improved (especially for vectors that have limited test groups), however it already reduces the regress duration by about half on an Apple M1.
2023-03-08zap more audit remnantstb1-6/+1
2023-03-08Stop trying to use EC_GFp_nist_method().jsing1-76/+20
Currently, if compiled without OPENSSL_BN_ASM_MONT, EC_GROUP_new_curve_GFp() tries to use EC_GFp_nist_method(), falling back to EC_GFp_mont_method() if it is not a NIST curve (if OPENSSL_BN_ASM_MONT is defined we use EC_GFp_mont_method() unconditionally). Now that we have a reasonable non-assembly Montgomery implementation, the performance of EC_GFp_nist_method() is either similar or slower than EC_GFp_mont_method() (the exception being P-521, however if you're using that you're not doing it for performance reasons anyway). The EC_GFp_nist_method() uses rather scary BN NIST code (which would probably already be removed, if not for the BN and EC public APIs), it uses code paths that are currently less constant time, and there is additional overhead in checking to see if the curve is actually supported. Stop trying to use EC_GFp_nist_method() and unconditionally use EC_GFp_mont_method() in all cases. While here, factor out the common setup code and call it from both EC_GROUP_new_curve_GFp() and EC_GROUP_new_curve_GF2m(). ok beck@ tb@
2023-03-08Remove acceptable audit.jsing1-94/+1
This code would need changes to be safe to use concurrently - remove it since it is somewhat incomplete and needs reworking. Requested by tb@
2023-03-08Remove EC_FLAGS_DEFAULT_OCT.jsing6-79/+27
The EC code has an amazing array of function pointer hooks, such that a method can hook into almost any operation... and then there is the EC_FLAGS_DEFAULT_OCT flag, which adds a bunch of complex code and #ifdef so you can avoid setting three of those function pointers! Remove EC_FLAGS_DEFAULT_OCT, the now unused flags field from EC_METHOD, along with the various code that was wrapped in EC_FLAGS_DEFAULT_OCT, setting the three function pointers that need to be set in each of the EC_METHODs. ok beck@ tb@
2023-03-07Improve bn_montgomery_multiply_words().jsing1-10/+13
Rather than calling bn_mul_add_words() twice - once to multiply and once to reduce - perform the multiplication and reduction in a single pass using bn_mulw_addw_addw() directly. Also simplify the addition of the resulting carries, which in turn allows us to avoid zeroing the top half of the temporary words. This provides a ~20-25% performance improvement for RSA operations on aarch64. ok tb@
2023-03-07Slightly rework bn_mulw_addtw().jsing1-5/+3
Call bn_mulw_addw() rather than doing bn_mulw() follow by bn_addw(). This simplifies the code slightly, plus on some platforms bn_mulw_addw() can be optimised (and bn_mulw_addtw() will then benefit from such an optimisation). ok tb@
2023-03-07Call BN_free() instead of BN_clear_free().jsing15-79/+79
BN_clear_free() is a wrapper that calls BN_free() - call BN_free() directly instead. ok tb@
2023-03-07Fix another return value check for CMS_SharedInfo_encode()tb1-2/+2
This should have been included in a previous diff/commit...