summaryrefslogtreecommitdiff
path: root/lib/libcrypto/rsa
AgeCommit message (Collapse)Author
2024-08-29Remove the pkey_{,public_,param_}check() handlersTheo Buehler
This disables the EVP_PKEY_*check() API and makes it fail (more precisely indicate lack of support) on all key types. This is an intermediate step to full removal. Removal is ok beck jsing
2024-08-28Implement X509_get_signature_info()Theo Buehler
This is a slightly strange combination of OBJ_find_sigid_algs() and the security level API necessary because OBJ_find_sigid_algs() on its own isn't smart enough for the special needs of RSA-PSS and EdDSA. The API extracts the hash's NID and the pubkey's NID from the certificate's signatureAlgorithm and invokes special handlers for RSA-PSS and EdDSA for retrieving the corresponding information. This isn't entirely free for RSA-PSS, but for now we don't cache this information. The security bits calculation is a bit hand-wavy, but that's something that comes along with this sort of numerology. ok jsing
2024-08-26replace atoi(3) usage with strtonum(3); ok/tweaks tb@Omar Polo
2024-07-08Hide global _it symbols in rsa.hBob Beck
ok tb@
2024-06-24libcrypto: constify most error string tablesTheo Buehler
These constitute the bulk of the remaining global mutable state in libcrypto. This commit moves most of them into data.rel.ro, leaving out ERR_str_{functs,libraries,reasons} (which require a slightly different approach) and SYS_str_reasons which is populated on startup. The main observation is that if ERR_load_strings() is called with a 0 lib argument, the ERR_STRING_DATA argument is not actually modified. We could use this fact to cast away const on the caller side and be done with it. We can make this cleaner by adding a helper ERR_load_const_strings() which explicitly avoids the assignment to str->error overriding the error code already set in the table. In order for this to work, we need to sprinkle some const in err/err.c. CMS called ERR_load_strings() with non-0 lib argument, but this didn't actually modify the error data since it ored in the value already stored in the table. Annoyingly, we need to cast const away once, namely in the call to lh_insert() in int_err_set_item(). Fixing this would require changing the public API and is going to be tricky since it requires that the LHASH_DOALL_FN_* types adjust. ok jsing
2024-05-19remove prototypes with no matching functionJonathan Gray
feedback and ok tb@
2024-03-30Rewrite RSA_padding_add_PKCS1_type_{1,2}() with CBS/CBB.Joel Sing
ok tb@
2024-03-27Unify *_up_ref() implementationsTheo Buehler
No need for an inconsistently named local variable and a ternary operator. ok jsing
2024-03-26Clean up use of EVP_MD_CTX_{legacy_clear,cleanup} in PKCS1_MGF1joshua
ok tb@
2024-03-26Clean up use of EVP_MD_CTX_{legacy_clear,cleanup} injoshua
RSA_verify_PKCS1_PSS_mgf1 ok jsing@ tb@
2024-03-17Annotate RSA-PSS SHA parameter encoding as wrongTheo Buehler
A historic blunderfest in the ASN.1 module for RSA-PSS led to very confusing text in various RFCs. davidben and my current reading of this is that parameters for SHA-* should be encoded as an ASN.1 NULL rather than omitted. The use of X509_ALGOR_set_evp_md() leads to them being omitted, and is therefore counter to the specification (but allowed. We should fix this. For now, leave a reminder. See https://boringssl-review.googlesource.com/c/boringssl/+/67088 for a lot more details. ok davidben
2024-02-18Use EVP_MD_CTX_legacy_clear() internallyTheo Buehler
ok jsing
2024-01-10Inline rsa_is_pss() and rsa_pkey_is_pss()Theo Buehler
It's more explicit and not that much longer. ok jsing
2024-01-04Replace .pkey_base_id with a .base_method pointerTheo Buehler
Every EVP_PKEY_ASN1_METHOD is either an ASN.1 method or an alias. As such it resolves to an underlying ASN.1 method (in one step). This information can be stored in a base_method pointer in allusion to the pkey_base_id, which is the name for the nid (aka pkey_id aka type) of the underlying method. For an ASN.1 method, the base method is itself, so the base method is set as a pointer to itself. For an alias it is of course a pointer to the underlying method. Then obviously ameth->pkey_base_id is the same as ameth->base_method->pkey_id, so rework all ASN.1 methods to follow that. ok jsing
2024-01-04Split ameth arrays into individual methodsTheo Buehler
For some reason DSA, GOST, and RSA had their ASN.1 methods stored in an array. This is clumsy and the only benefit is that one saves a few externs in p_lib.c. They were also arranged by ascending NID because of bsearch() madness. Split them up and arrange the methods by name, which is much saner and simpler. ok jsing
2024-01-01pkey_is_pss() and pkey_ctx_is_pss() to rsa_ameth.cTheo Buehler
These aren't particularly helpful and should probably both be expanded. For now move them to the only place where they are actually used.
2023-12-28Rework pkey_rsa_keygen()Theo Buehler
As usual, make the function single exit. Initialize the pkey callback pointer and the BN_GENCB on the stack at the top rather than relying on the weird trans_cb() in evp_pkey_set_cb_translate() to do so. Greatly simplify the control flow and add missing error checks. ok jsing
2023-12-28Rework rsa_priv_decode()Theo Buehler
Turn the function into single exit and error check EVP_PKEY_assign() for style. ok jsing
2023-12-28Clean up old_rsa_priv_decode()Theo Buehler
Again change this function into the single exit idiom, and error check EVP_PKEY_assign(). ok jsing
2023-11-29Ignore ENGINE at the API boundaryTheo Buehler
This removes the remaining ENGINE members from various internal structs and functions. Any ENGINE passed into a public API is now completely ignored functions returning an ENGINE always return NULL. ok jsing
2023-11-19Unifdef OPENSSL_NO_ENGINE in libcryptoTheo Buehler
This is mechanical apart from a few manual edits to avoid doubled empty lines. ok jsing
2023-11-09Fix X509_ALGOR_set0() usage in rsa_alg_set_oaep_padding()Theo Buehler
Replace X509_ALGOR_set0() with X509_ALGOR_set0_by_nid(). This way there is no missing error checking for OBJ_nid2obj() and no nested functions. Slightly more importantly, this plugs two long standing potential leaks in this function (or previously rsa_cms_encrypt()) due to missing error checking: in the unlikely event that X509_ALGOR_set0() failed, astr/ostr would leak. ok jsing
2023-11-09Use X509_ALGOR_set0_by_nid() in rsa_mgf1md_to_maskGenAlgorithm()Theo Buehler
ok jsing
2023-11-08More minor cleanup in rsa_alg_set_oaep_padding()Theo Buehler
Test and assign one more instance replace a useless comment by an empty line.
2023-11-08Prepare further fixes of X509_ALGOR_set0() misuseTheo Buehler
In rsa_alg_set_oaep_padding() rename los to ostr for consistency with astr, make it have function scope, free ostr in the error path and assume X509_ALGOR_set0() success. ok jca
2023-11-08zap a stray spaceTheo Buehler
2023-11-08Rename os into astr in rsa_alg_set_oaep_padding()Theo Buehler
2023-11-08Rename pkctx to pkey_ctx in rsa_alg_set_oaep_padding() and rsa_cms_encrypt()Theo Buehler
2023-11-08Some simple cosmetics in rsa_alg_set_oaep_padding()Theo Buehler
Rename rv into ret and split it on its own line, move labellen a bit down add some empty lines. To match style elsewhere. Most of this was requested by jsing
2023-11-08Split OAEP padding handling into a helper functionTheo Buehler
This matches what is done for PKCS#1 1.5 and PSS. This function needs a lot of work still, but it's easier to do that without having to tiptoe around a lot of other garbage. ok jsing
2023-11-07Move CMS_RecipientInfo_ktri_get0_algs() down a few lines and fix itsTheo Buehler
error check
2023-11-07Move CMS_RecipientInfo_get0_pkey_ctx() to first use of pkctxTheo Buehler
2023-11-07Inline rsa_ctx_to_pss_string()Theo Buehler
After previous refactoring, rsa_all_set_pss_padding() is the last remaining caller of the weirdly named and ugly rsa_all_set_pss_padding(). This can be handled in a few simple lines now that this mess has slightly cleaner code.
2023-11-07Rename pkctx to pkey_ctx in rsa_{cms,item}_sign()Theo Buehler
2023-11-07Trivial cleanup in rsa_cms_sign()Theo Buehler
Check and assign the EVP_PKEY_CTX and move the extraction of the algorithm identifier from the signer info a few lines down.
2023-11-07Rework RSA_PKCS1_PSS_PADDING handling in rsa_item_sign()Theo Buehler
The current convoluted mess can be handled with two calls to the new rsa_alg_set_pss_padding() helper. Not that this would be obvious at all. This fixes two more leaks in case of X509_ALGOR_set0() failure. ok jsing
2023-11-07Add a helper to set RSASSA-PSS padding parametersTheo Buehler
This sets the AlgorithmIdentifier's algorithm to id-RSASSA-PSS with appropriate RSASSA-PSS parameters. This pulls a chunk of code out of rsa_cms_sign() and rewrites it with proper error checking, thereby fixing a long-standing leak. This helper can also be used in rsa_item_sign(), but that part is a bit special, and will therefore be commmitted separately. ok jsing
2023-11-07Add a helper to set RSA PKCS #1 v1.5 padding OIDTheo Buehler
This removes a few duplicated and unchecked X509_ALGOR_set0() calls and factors them into a helper function that sets the AlgorithmIdentifier on the recipient info or signer info to rsaEncryption with null parameters. ok jsing
2023-10-26Rework the MD setting in the RSA ASN.1 methodTheo Buehler
This streamlines the code to use safer idioms, do proper error checking and be slightly less convoluted. Sprinkle a few references to RFC 8017 and explain better what we are doing and why. Clarify ownership and use more consistent style. This removes the last internal use of X509_ALGOR_set_md(). ok jsing
2023-08-12RSA's _free and _size also lose their int_ prefixTheo Buehler
2023-08-10Fix a leak in rsa_pub_encode()Theo Buehler
rsa_param_encode() allocates the PSS parameters in an ASN1_STRING which is leaked if any error occurs later in rsa_pub_encode(). Convert the rest of the code to follow our ordinary idioms more closely. ok jsing
2023-08-10rsa_priv_encode: plug leak on PKCS8_pkey_set0() failureTheo Buehler
Change the code to use safer idioms and avoid nested function calls. ok jsing
2023-08-09Rework BN_BLINDING to use pthread_t directlyTheo Buehler
Instead of CRYPTO_THREADID, which passes pthread_via through unsigned long, we can use pthread_self() and pthread_equal() directly. This commit keeps using the awkward 'local' nomenclature as that is used throughout the rsa code. This will be changed after the blinding code will have been fully merged into rsa_blinding.c. ok jsing
2023-08-09Merge remainder of rsa_crpt.c into rsa_eay.cTheo Buehler
Most of these are one line wrappers around methods implemented in rsa_eay.c by default.
2023-08-09Move RSA blinding API from rsa_crpt.c to rsa_blinding.cTheo Buehler
2023-08-09Move RSA_blinding_{on,off}() to the bottom of the fileTheo Buehler
2023-08-09Move bn_blind.c to rsa_blinding.cTheo Buehler
discussed with jsing
2023-08-09Merge BN_BLINDING_create_param() into BN_BLINDING_new()Theo Buehler
2023-08-08Drop the unused BN_BLINDING argument of BN_BLINDING_create_param()Theo Buehler
2023-08-08Simplify RSA_setup_blinding()Theo Buehler
Make this look a bit more like other code we cleaned up avoiding nesting and unnecessary else branches. ok jsing