summaryrefslogtreecommitdiff
path: root/lib/libcrypto
AgeCommit message (Collapse)Author
2023-12-18cmac: use block_size rather than blTheo Buehler
This is purely mechanical apart from a single line wrap.
2023-12-18Clean up EVP_PBE_CipherInit() a littleTheo Buehler
This is mostly stylistic cleanup, making the control flow a bit more obvious. There's one user-visible change: we no longer go out of our way to provide info about the unknown algorithm. The nid is enough. ok joshua jsing
2023-12-16ASN1_STRING_TABLE_get.3: grammar: have -> hasTheo Buehler
2023-12-16EVP_EncryptUpdate(): make block_size and block_mask constTheo Buehler
suggested by millert
2023-12-16First cleanup pass over EVP_EncryptUpdate()Theo Buehler
Use more sensible variable names in order to make the logic a bit easier to follow. The variables may be renamed in a later pass. Unindent a block that was squeezed too much to the right and make a few minor stylistic tweaks. ok jsing
2023-12-16Move EVP_PBE_find() next to the tablesTheo Buehler
There is no point in having EVP_PBE_CipherInit() between the table and the lookup functions (which it notably uses). No code change.
2023-12-16Remove OBJ_bsearch_() usage from PBETheo Buehler
Split the table of built-in password based encryption algorithms into two and use a linear scan over the table corresponding to the type specified in EVP_PBE_find()'s type argument. Use better variable names, make the API a bit safer and generally reduce the eye bleed in here. ok jsing
2023-12-16Using two different spellings of NULL in the same line is an achievementTheo Buehler
2023-12-16Annotate incorrect value for ub_email_addressTheo Buehler
The ub_email_address upper bound, 128, returned for NID_pkcs9_emailAddress, doesn't match the PKCS#9 specification where it is 255. This was adjusted in RFC 5280: The ASN.1 modules in Appendix A are unchanged from RFC 3280, except that ub-emailaddress-length was changed from 128 to 255 in order to align with PKCS #9 [RFC2985]. Nobody seems to have noticed so far, so leave it at an XXX and a BUGS entry for now. It also clearly has the wrong name. Another mystery is why the RFCs suffix some upper bounds with length, but not others. Also, OpenSSL chose to be inconsistent with that, because inconsistency is one of the few things this library is really good at.
2023-12-16Neuter the ASN1_STRING_TABLE modification APITheo Buehler
This is complete nonsense that nothing's ever used except for a test by schwarze. It will be removed in the next major bump. What remains could be moved to a simple lookup table in security/xca... ok jsing
2023-12-16Remove call to ASN1_STRING_TABLE_cleanup()Theo Buehler
In a few minutes, the string table will no longer have anything to clean up and ASN1_STRING_TABLE_cleanup() will push an error on the stack. So remove this pointless call in the still too complicated OPENSSL_cleanup(). ok jsing
2023-12-16asn1.h: mark a type and a bunch of macros for removalTheo Buehler
ok jsing
2023-12-16Rename ASN1_STRING_TABLE_add manual to _getTheo Buehler
2023-12-16Remove ASN1_STRING_TABLE_{add,cleanup}() documentationTheo Buehler
The unused ASN1_STRING_TABLE extensibility API will be removed in the next major bump and the table itself will become immutable. Lightly adjust the remaining text. In particular, update the RFC reference, stop talking about defaults when nothing can be changed anymore, do not mention useless flags that you will no longer be able to set and move the description of the only remaining flag after the description of ASN1_STRING_TABLE_get(). The file will be renamed in a second step.
2023-12-16Implement and use a do_cipher() wrapperTheo Buehler
Instead of using five different idioms for eight callers of the do_cipher() method in EVP_{Decrypt,Encrypt}{Update,Final_ex}(), wrap the API insanity in an evp_cipher() function that calls do_cipher() as appropriate depending on the EVP_CIPH_FLAG_CUSTOM_CIPHER being set or not. This wrapper has the usual OpenSSL calling conventions. There is one complication in EVP_EncryptUpdate() in the case a previous call wrote only a partial buffer. In that case, the evp_cipher() call is made twice and the lengths have to be added. Add overflow checks and only set outl (the number of bytes written) to out on success. ok jsing
2023-12-15Remove strings.h againTheo Buehler
The portable compat shim doesn't provide it.
2023-12-15Remove EVP_PBE_cleanup() from EVP_cleanup()Theo Buehler
It's a noop and will be removed in the next major bump. ok jsing
2023-12-15Move all the neutered PBE API to the bottom of the fileTheo Buehler
2023-12-15Remove unprotected global state from EVP_PBETheo Buehler
Nobody adds a custom password-based encryption algorithm, be it a PRF or one that can be an outermost AlgorithmIdentifier in CMS or its precursors. This makes the undocumented and unused EVP_PBE_alg_add{,_type}() always fail. They will be removed in the next major bump. Thus, we no longer need to maintain a global stack of PBE algorithms that one thread can happily modify while another one searches it. In subsequent steps we can then remove another rather pointless use of OBJ_bsearch_(). "Let's optimize the lookup in a table with two dozen entries using about as many glorious layers of obfuscating macros." ok jsing
2023-12-15Fix a return value confusion in chacha20_poly1305_cipher()Theo Buehler
On overlong input, chacha20_poly1305_cipher() would return 0, which in EVP_CipherUpdate() and EVP_CipherFinal() signals success with no data written since EVP_CIPH_FLAG_CUSTOM_CIPHER is set. In order to signal an error, we need to return -1. Obviously. ok jsing
2023-12-15Disallow ciphers with EVP_CIPH_FLAG_CUSTOM_CIPHER in CMACTheo Buehler
These are usually AEAD ciphers, for which CMAC makes little sense (if you need a MAC and all you have is an AEAD, you don't need CMAC, you can just use a zero length cipher text). Also, since the CMAC implementation only allows 64 and 128 bit block sizes, the AEADs would error out later anyway. The only family of ciphers this effectively excludes is AES key wrap, for which CMAC makes little sense. One notable side effect of doing this is that the EVP_Cipher() return value checks in the CMAC code magically become correct. EVP. What's not to love about it. ok jsing
2023-12-15Document EVP_Cipher() in codeTheo Buehler
EVP_Cipher() is an implementation detail of EVP_Cipher{Update,Final}(). Behavior depends on EVP_CIPH_FLAG_CUSTOM_CIPHER being set on ctx->cipher. If the flag is set, do_cipher() operates in update mode if in != NULL and in final mode if in == NULL. It returns the number of bytes written to out (which may be 0) or -1 on error. If the flag is not set, do_cipher() assumes properly aligned data and that padding is handled correctly by the caller. Most do_cipher() methods will silently produce garbage and succeed. Returns 1 on success, 0 on error. ok jsing
2023-12-15Move EVP_Cipher() from evp_lib.c to evp_enc.cTheo Buehler
EVP_Cipher() is a dangerous thin wrapper of the do_cipher() method set on the EVP_CIPHER_CTX's cipher. It implements (part of) the update and final step of the EVP_Cipher* API. Its behavior is nuts and will be documented in a comment in a subsequent commit. schwarze has a manpage diff that will fix the incorrect documentation.
2023-12-15Clean up includesTheo Buehler
2023-12-15Neuter EVP_PKEY_asn1_add{0,_alias}()Theo Buehler
Nothing uses these, so they will be removed in the next bump. For now make them always fail and remove the unprotected global state backing them. This makes EVP_PKEY_asn1_get{0,_count}() completely trivial and will allow some further cleanup in later steps. ok jsing
2023-12-15Hoist OBJ_sn2nid() over OBJ_ln2nid()Theo Buehler
In all other places, the short name comes before the long name, so fix the only exception.
2023-12-15Coverity rightly points out that an unsigned int is always >= 0Theo Buehler
2023-12-14OBJ_create: sorry Omar, aobj is a better name than opTheo Buehler
Done.
2023-12-14OBJ_create: use a nid variable to avoid nested function callTheo Buehler
2023-12-14OBJ_create: malloc() -> calloc()Theo Buehler
2023-12-14OBJ_create: test and assign as usualTheo Buehler
2023-12-14OBJ_create: initialize buf and turn function into single exitTheo Buehler
2023-12-14OBJ_create: rename ok to ret and make it last declarationTheo Buehler
2023-12-14OBJ_create(): rename i to lenTheo Buehler
2023-12-14OBJ_create(): remove pointless parenthesesTheo Buehler
2023-12-14OBJ_create(): remove useless castTheo Buehler
2023-12-14OPENSSL_assert() that the passed nid is within rangeTheo Buehler
discussed with deraadt and jsing
2023-12-14Bump OPENSSL_showfatal() from LOG_INFO to LOG_CONSTheo Buehler
This way people can actually notice that an OPENSSL_assert() triggered. discussed with deraadt and jsing
2023-12-14Move the txt to obj/nid conversions a bit down.Theo Buehler
No code change
2023-12-14Dedup OBJ_nid2{obj,sn,ln}()Theo Buehler
First get the obj corresponding to nid, then inspect its sn and ln. Shaves off 40 lines of code and will simplify locking.
2023-12-14Simplify OBJ_nid2obj()Theo Buehler
This is now yet another identical copy of the same code... Next step will be to dedup. ok jsing
2023-12-14Simplify OBJ_nid2sn()Theo Buehler
This is exactly the same as the previous OBJ_nid2ln() change modulo s/ln/sn/g. ok jsing
2023-12-14Simplify OBJ_nid2ln()Theo Buehler
If nid is in the range of built-in NIDs, return the corresponding long name, unless some genius left a hole. Otherwise perform a yolo check if there are any user-added objects with matching nid in the global hash. This changes behavior in that we now push an OBJ_R_UNKNOWN_NID error onto the stack even if there are no user-added objects. ok jsing
2023-12-14Fix sk_deep_copy() implementationTheo Buehler
sk_deep_copy() is bad code. It is less bad than the upstream code, but still bad: it passes strdup() through a void pointer and assigns it to a function pointer of different type before calling the latter. That's not kosher in more than one way. There is no need for such gymnastics. If we need a deep copy for a type, we should implement it as appropriate for that type. Also, we should not expect and even less so allow holes in a STACK_OF(). The only way the vpm->hosts can be populated is by way of this deep_copy function or x509_param_set_hosts_internal(), which pushes only after a non-NULL check. Invariants: they're useful. ok jsing
2023-12-13Simplify OBJ_ln2nid()Theo Buehler
This is s/sn/ln/g of the previous commit and eliminates another OBJ_bsearch_() user, the last one in this file. The bsearch() uses in this file are possibly the only ones that actually make sense since we're searching tables of roughly 1000 entries. ok jsing
2023-12-13Simplify OBJ_sn2nid()Theo Buehler
Another OBJ_bsearch_() elimination. OBJ_sn2nid() is very similar to OBJ_obj2nid(). First it tries to retrieve an object identifier with matching "short name" from the global hash of added objects and then searches the table of built-in objects. ok jsing
2023-12-13Simplify OBJ_obj2nid()Theo Buehler
Continue with OBJ_bsearch_() elimination. OBJ_obj2nid() first checks if the object identifier passed in has a nid and if so, it returns that. Otherwise, it looks into the global hash of added objects (of course without locking) for a match and then returns the nid thereof. As a last attempt, it searches the table of built-in object identifiers. The last two steps can be cleaned up and simplified quite a bit by using C99 initializers, bsearch() and an appropriate comparison function. Then it becomes obvious that bsearch() already returns a pointer to the nid we're looking for, so there is no point in converting that into its corresponding obj and returning the nid thereof. ok jsing
2023-12-05last .Nm should not have a commaJonathan Gray
2023-12-03Remove misuse warnings for EVP_*Final()Theo Buehler
They make no sense. These are thin wrappers of EVP_*Final_ex() and behave exactly the same way. The minor behavior difference of Init and Init_ex is likely a historical artefact of this abomination of an API. Deprecation of the Init functions was recently removed from the manpage. The only reason to prefer the _ex versions over the normal versions is ENGINE. This is no longer an argument. The warnings were added in an attempt at adding automatic cleanup. This broke stuff and was therefore backed out. The warnings remained. discussed with schwarze
2023-12-02Fix some NULL misspellingsTheo Buehler