summaryrefslogtreecommitdiff
path: root/lib/libcrypto
AgeCommit message (Collapse)Author
2022-08-31Add an empty line for consistency.Theo Buehler
2022-08-31Remove most mentions of contexts on the stack.Theo Buehler
2022-08-31nasty whitespaceTheo Buehler
2022-08-31Rework DSA_size() and ECDSA_size()Theo Buehler
DSA_size() and ECDSA_size() have a very special hack. They fudge up an ASN1_INTEGER with a size which is typically > 100 bytes, backed by a buffer of size 4. This was "fine", however, since they set buf[0] = 0xff, where the craziness that was i2c_ASN1_INTEGER() only looks at the first octet (one may then ask why a buffer of size 4 was necessary...). This changed with the rewrite of i2c_ASN1_INTEGER(), which doesn't respect this particular hack and rightly assumes that it is fed an actual ASN1_INTEGER... Instead, create an appropriate signature and use i2d to determine its size. Fixes an out-of-bounds read flagged by ASAN and oss-fuzz. ok jsing
2022-08-31Switch loop bounds from size_t to int in check_hosts()Theo Buehler
sk_num() can return a negative value, in which case the upper bound is SIZE_MAX, which results in a very long for loop. CID 153997 ok jsing
2022-08-30chacha20_poly1305_cleanup() should return 1Theo Buehler
Otherwise EVP_CIPHER_CTX_cleanup() leaks, as spotted by the ASAN CI. ok jsing
2022-08-30Plug memory leak in X509_REQ_print_ex()Theo Buehler
CID 356353 ok jsing
2022-08-29missing periodTheo Buehler
2022-08-29Provide ERR_R_INIT_FAIL.Joel Sing
Needed for an upcoming change. ok tb@
2022-08-29Provide ASN1_R_TYPE_NOT_PRIMITIVE.Joel Sing
Needed for an upcoming change. ok tb@
2022-08-29static const, not const staticJonathan Gray
c99 6.11.5: "The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature." ok miod@ tb@
2022-08-28Plug memory leak in CMS_add_simple_smimecap() in the unlikely event thatTheo Buehler
ASN1_INTEGER_set() fails. ok jsing
2022-08-28Encode an ASN.1 INTEGER with NULL data to value of zero.Joel Sing
When an ASN1_INTEGER is created it has NULL data until a value is set - previously, an ASN1_INTEGER in this state encoded to an ASN.1 INTEGER with a value of 0, rather than being treated as an error. While code should really set values, the historical behaviour has not required this. Found the hard way by sthen@ with acme-client. ok tb@
2022-08-27Provide additional defines for EVP AEAD.Joel Sing
While these will not be used by LibreSSL, they are used by some QUIC implementations (such as ngtcp2). ok tb@
2022-08-21fix indent and zap trailing whitespaceTheo Buehler
2022-08-20Provide EVP_chacha20_poly1305()Joel Sing
EVP_chacha20_poly1305() is an EVP_CIPHER implementation of the ChaCha20-Poly1305 AEAD. This is potentially used to provide encryption for the QUIC transport layer. Where possible, this should be avoided in favour of the significantly saner EVP_AEAD interface. ok tb@
2022-08-20Remove bogus length checks from EVP_aead_chacha20_poly1305()Joel Sing
The length checks for EVP_aead_chacha20_poly1305() seal/open were incorrect and are no longer necessary (not to mention that the comment failed to match the code). Remove these since the underlying ChaCha implementation will now handle the same sized inputs at these functions can. Issue flagged by and ok tb@
2022-08-20Remove UINT32_MAX limitation on ChaCha() and CRYPTO_chacha_20().Joel Sing
We can avoid this unnecessary limitation by calling chacha_encrypt_bytes() multiple times internally. In the case of ChaCha(), the caller still needs to ensure that the same IV is not used for more than 2^70 bytes. ok tb@
2022-08-20Rewrite i2c_ASN1_INTEGER() using CBB/CBS.Joel Sing
This gives us cleaner and safer code, although it is worth noting that we now generate the encoding even when called with NULL as the output pointer (and then discard it, returning just the length). Resolves oss-fuzz #49963. ok tb@
2022-08-20Make it possible to signal an error from an i2c_* function.Joel Sing
In asn1_i2d_ex_primitive(), asn1_ex_i2c() returning -1 is used to indicate that the object is optional and should be skipped, while -2 is used to indicate that indefinite length encoding should be used. Any other negative value was treated as success, resulting in the out pointer being walked backwards. Avoid this by treating any negative value (aside from -1 and -2) as a failure, propagating it up the stack. Additionally, check the return value of the second asn1_ex_i2c() call to ensure that it matches the value returned by the first call. This makes sure that the length of the encoded object is correct, plus it detects the case where a failure occurs during the second call. Discussed with tb@ (who also flagged the negative value issue).
2022-08-20Add an empty pkcs12_local.h and include it where it will soon be needed.Theo Buehler
2022-08-18Adjust signatures of BIO_ctrl functionsTheo Buehler
In bio.h r1.54, the signature of BIO_callback_ctrl() was changed from bio_info_cb to BIO_info_cb. Adjust manual to reflect this change. At the moment, bio_info_cb and BIO_info_cb are still distinct types with our BIO_info_cb matching OpenSSL's definition. Historically, bio_info_cb had a different type, but that leads to issues with casting function pointers. The ecosystem has moved on to embrace the new type and several ports confuse the two types because OpenSSL decided to "solve" the issues with "typedef BIO_info_cb bio_info_cb; /* backward compatibilty */". We will align with this in the next bump. ok jsing
2022-08-18Allow empty attribute sets in CSRsTheo Buehler
While each attribute must contain at least one extension, it is not required that a CSR have attributes at all. Instead of signalling an error by returning NULL if no extensions are found, return an empty stack of extensions. Via OpenSSL 1f02ca2d ok jsing
2022-08-15Add missing RCS tag and zap a trailing spaceTheo Buehler
2022-08-15Initialize readbytes in BIO_gets()Theo Buehler
If the bgets() callback returns <= 0, we currently rely on the user provided callback to set readbytes, which isn't ideal. This also matches what's done in BIO_read() and BIO_write(). ok jsing
2022-08-11Remove unused variableTheo Buehler
X509_NAME_print() is documented to print things at a given indentation level. Unfortunately, this never worked since someone got some logic wrong. Part of the wrong logic was removed in a dead code removal in OpenSSL commit 92ada7cc, but the variable l was left behind, which leads to compiler warnings on some platforms. End its sad life pointlessly and incorrectly measuring column width and remove it. ok jsing
2022-08-10Avoid signed integer overflow due to unary negationTheo Buehler
The current X509_print_ex() tries too hard pretty printing negative serialNumbers (which shouldn't occur in the first place). In particular, negating LONG_MAX leads to signed overflow. Ditch the code dealing with negative serialNumbers representable as long and fall back to the long form printing. This simplifies the code and fixes oss-fuzz #49944 with/ok jsing
2022-08-10Cast int64_t to uint64_t for negatingTheo Buehler
Avoid signed integer overflow by casting an int64_t to uint64_t before negating. Same fix was applied in a_int.c -r1.44, but was forgotten to be applied to a_enum.c. ok jsing
2022-08-10Only print versions we know aboutTheo Buehler
The version field of an X.509 Certificate is an enum Version ::= INTEGER { v1(0), v2(1), v3(2) } Printing the version as l + 1 only really makes sense with 0 <= l <= 2. Otherwise print a naked l while also indicating that it is an unknown version. ok jsing
2022-08-05Remove overly aggressive trust check in legacy verifier that breaksBob Beck
p5-IO-Socket-SSL regress and regress/sbin/iked/live Still passes the mutt regress that this was intended to fix. ok tb@
2022-08-04Mop up key_len assignments.Joel Sing
Remove unnecessary conditions for XTS mode, since we know which are XTS. Also use bytes rather than bits / 8. ok tb@
2022-08-04Mop up EVP_CIPH_FLAG_FIPS usage.Joel Sing
LibreSSL does not do FIPS and nothing else sets or checks these. ok tb@
2022-08-04Remove various aesni_* defines to aes_* functions.Joel Sing
A number of the AES-NI functions are #defines to an aes_* function - remove these and just use the AES variant directly. ok tb@
2022-08-03Prepare to provide PKCS12 accessorsTheo Buehler
In order to be able to make pkcs12/ opaque, we need an entire family of accessors. These are in a particularly nasty tangle since this was done in about a dozen steps while sprinkling const, renaming functions, etc. The public API also adds backward compat macros for functions that were in the tree for half a day and then renamed. Of course some of them got picked up by some ports. Some of the gruesome hacks in here will go away with the next bump, but that doesn't mean that the pkcs12 directory will be prettier afterward. ok jsing
2022-08-02Expand BLOCK_CIPHER_* macros.Joel Sing
As a first step towards untangling and cleaning up the EVP AES code, expand the BLOCK_CIPHER_* macros. In particular, rather than having two sets of macros - one that is used if AESNI is being compiled in and one if it is not, condition on #ifdef AESNI_CAPABLE in the expanded code. ok tb@
2022-07-31Tidy up some of BN_nist_mod_*Joel Sing
Shuffle variables around for consistency, also ensuring appropriate and consistent initialisation. ok tb@
2022-07-31Allow a NULL header in PEM_write{,_bio}()Theo Buehler
When PEM_write{,_bio}() were documented by Rich Salz and Richard Levitte, it was incorrectly stated that the header argument is allowed to be NULL. This was never true. Instead of fixing the documentation, it was decided that the API needs a fix, so pull in a variant of OpenSSL 3b9082c8. ok jsing
2022-07-30Use named initialisers for BIGNUMs.Joel Sing
Also move the _bignum_nist_p_.*_sqr static BIGNUMs out of individual functions. ok tb@
2022-07-30Untangle two logic chains in x509_asid.c into something more readable.Theo Buehler
ok jsing
2022-07-30Reorder functions and remove unnecessary function prototypes.Joel Sing
2022-07-30Add stack frames to AES-NI x86_64 assembly.Joel Sing
The current AES-NI x86_64 assembly does some strange, although valid things, such as making internal function calls without creating stack frames. In this case, the return address lands in the red zone (which it allows for when making use of the stack) and everything works as expected. However, this trips a false positive in valgrind, which seems to think that any data saved on the stack prior to the internal function call is now "undefined" once the function returns. Avoid this by actually using stack frames - this brings in most of 6a40ebe86b4 from OpenSSL, omitting the unnecessary explicit stack alignment (which was apparently added so this code could be used in the Linux kernel with an incorrectly aligned stack). Valgrind issue reported by Steffen Jaeckel (@sjaeckel), found via libstrophe unit tests. ok tb@
2022-07-30Use ASN1_INTEGER to encode/decode BIGNUM_it.Joel Sing
The current code simply shoves the unvalidated ASN.1 bytes into a BIGNUM on the hope that other things will detect issues (such as negative values being flipped to positive). Instead of doing this, decode and validate the ASN.1 data using ASN1_INTEGER, then convert it to a BIGNUM. Similarly, for encoding convert from BIGNUM to ASN1_INTEGER and use ASN1_INTEGER encoding. ok tb@
2022-07-30Provide and use a primitive clear function for BIGNUM_it.Joel Sing
Also tidy up bn_new() while here. ok tb@
2022-07-30Eliminate the somewhat pointless Ij variableTheo Buehler
Requested by & ok jsing
2022-07-30Transform two || chains into individually checked functionsTheo Buehler
Requested by and ok jsing
2022-07-29Having a perfect square at this point is not an error. Rather it isTheo Buehler
a shortcut bypassing expensive computation, so change goto err to goto done. Bug introduced in last refactoring before commit.
2022-07-29Tweak some comments and whitespace around commentsTheo Buehler
2022-07-26Do not pass input length <= 0 to the cipher handlersTheo Buehler
Input length < 0 is an error and input length == 0 can result in strange effects in some ciphers, except in CCM mode, which is extra special. Based on OpenSSL 420cb707 by Matt Caswell and Richard Levitte found by & ok jsing
2022-07-25fix indentTheo Buehler
2022-07-24Plug leak in X509V3_add1_i2d()Theo Buehler
Do not leak the extension that was deleted from the stack. via OpenSSL c3efe5c9. ok jsing