summaryrefslogtreecommitdiff
path: root/lib/libcrypto/dsa
AgeCommit message (Collapse)Author
2023-08-12Drop silly int_ prefix from _free() and _size()Theo Buehler
2023-08-12Free {priv,pub}_key before assigning to itTheo Buehler
While it isn't the case for the default implementations, custom DH and DSA methods could conceivably populate private and public keys, which in turn would result in leaks in the pub/priv decode methods. ok jsing
2023-08-12Readability tweak for key parameters in DSATheo Buehler
ok jsing
2023-08-12Simplify and unify missing_parameters() for DH and DSATheo Buehler
ok jsing
2023-08-12Convert {DH,DSA}_new_method() to using calloc()Theo Buehler
Due to OPENSSL_NO_ENGINE the engine member of dh and dsa is currently uninitialized. As a consequence, {DH,DSA}_get0_engine() will return a garbage pointer, which is particularly bad because the only reason we kept them in the first place is that they are used by some software... A side effect of freeing with {DH,DSA}_free() instead of a hand-rolled version is that we may call ->meth->finish() before ->meth->init() was called. We need a NULL check for ->meth to be on the safe side in case we should need to bring ENGINE back. with nits from djm ok deraadt djm
2023-08-11Improve variable names in {dh,dsa}_{pub,priv}_{de,en}code()Theo Buehler
Use aint for the ASN1_INTEGER holding the key and astr for the ASN1_STRING holding the parameters. This frees up key and params for their DER encoded versions, matching the naming we use elsewhere much more closely. ok jsing
2023-08-11Use params{,_len} in {dh,dsa}_params_{en,de}code()Theo Buehler
2023-08-11Use key/key_len in old_dsa_priv_{en,de}code()Theo Buehler
ok jsing
2023-08-11Add back an empty line that I didn't really want to removeTheo Buehler
2023-08-11Align dh and dsa decoding functions with encodingTheo Buehler
This adds some missing error checks and fixes and unifies error codes which were (as usual) all over the place or just plain nonsense. Use an auxiliary variable for d2i invocations even though it is not really needed here. ok jsing
2023-08-10Convert {dh,dsa}_{pub,priv}_encode() to single exitTheo Buehler
Use the same variable names throughout these functions and unify them some more. ok jsing
2023-08-10Clean up {dh,dsa}_pub_encode()Theo Buehler
This brings these two messy functions into more usual shape. There is a lot more that can be done in here. It is a step in the right direction. ok jsing
2023-08-10Various fixes in {dh,dsa}_priv_encode()Theo Buehler
Avoid creating an ASN1_STRING with negative length, set type, data and length via ASN1_STRING_type_new() and ASN1_STRING_set0() instead of doing this manually. Check return value for i2d_ASN1_INTEGER() and use an intermediate ASN1_OBJECT instead of nested function calls. Finally, clear sensitive data with freezero(). ok jsing
2023-08-03Make the bn_rand_interval() API a bit more ergonomicTheo Buehler
Provide bn_rand_in_range() which is a slightly tweaked version of what was previously called bn_rand_range(). The way bn_rand_range() is called in libcrypto, the lower bound is always expressible as a word. In fact, most of the time it is 1, the DH code uses a 2, the MR tests in BPSW use 3 and an exceptinally high number appears in the Tonelli-Shanks implementation where we use 32. Converting these lower bounds to BIGNUMs on the call site is annoying so let bn_rand_interval() do that internally and route that through bn_rand_in_range(). This way we can avoid using BN_sub_word(). Adjust the bn_isqrt() test to use bn_rand_in_range() since that's the only caller that uses actual BIGNUMs as lower bounds. ok jsing
2023-07-08hide symbols in dsaBob Beck
ok tb@
2023-07-07Mop up remaining uses of ASN1_bn_print()Theo Buehler
This removes lots of silly buffers and will allow us to make this API go away. ok jsing
2023-04-25Wire up truncated SHA-2, SHA-3 and related thingsTheo Buehler
from jsing
2023-04-18Bring includes into canonical orderTheo Buehler
Requested by jsing
2023-04-18Move some includes out of OPENSSL_NO_DEPRECATEDTheo Buehler
Some headers were included conditionally on OPENSSL_NO_DEPRECATED in hopes that eventually the mess of everything includes everything will magically resolve itself. Of course everyone would end up building openssl with OPENSSL_NO_DEPRECATED over time... Right. Surprisingly, the ecosystem has come to rely on these implicit inclusions, so about two dozen ports would fail to build because of this. Patching this would be easy but really not worth the effort. ok jsing
2023-04-13Remove files that definitely contain no code anymoreTheo Buehler
(experts disagree whether they ever did)
2023-04-13Move DSA_generate_parameters() from dsa_depr.c to dsa_gen.cTheo Buehler
Discussed with jsing
2023-04-09Move a few functions out of OPENSSL_NO_DEPRECATEDTheo Buehler
Geoff Thorpe added OPENSSL_NO_DEPRECATED nearly two decades ago. The hope was that at some point some functions can be dropped. Most of the functions marked deprecated are actually unused nowadays but unfortunately some of them are still used in the ecosystem. Move them out of OPENSSL_NO_DEPRECATED so we can define it without breaking the consumers in the next bump. ERR_remove_state() is still used by a dozen or so ports. This isn't a big deal since it is just a stupid wrapper for the not quite as deprecated ERR_remove_thread_state(). It's not worth patching these ports. Annoyingly, {DH,DSA}_generate_parameters() and RSA_generate_key() are still used. They "make use" of the old-style BN_GENCB callback, which is therefore more difficult to remove - in case you don't know know: that's the thing responsible for printing pretty '.', '+' and '*' when you generate keys. Most annoyingly, DH_generate_parameters() was added to rust-openssl in 2020 for "advanced DH support". This is very unfortunate since cargo bundles a rust-openssl and updates it only every few years or so. As a consequence we're going to be stuck with this nonsense for a good while. ok beck jsing
2023-03-27Replace the remaining BN_copy() with bn_copy()Theo Buehler
ok jsing
2023-03-25BN_free() is defined in <openssl/bn.h>Theo Buehler
This is currently pulled in via dsa.h and ecdsa.h, but only when OPENSSL_NO_DEPRECATED is not defined. We should fix this in the public header, too - let's wait a bit with that.
2023-03-11Fix an off-by-one in dsa_check_key()Theo Buehler
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-07Call BN_free() instead of BN_clear_free().Joel Sing
BN_clear_free() is a wrapper that calls BN_free() - call BN_free() directly instead. ok tb@
2023-03-04Simplify the consistency checks in old_dsa_priv_decode()Theo Buehler
We have long had expensive checks for DSA domain parameters in old_dsa_priv_decode(). These were implemented in a more complicated way than necesary. ok beck jsing
2023-03-04Cap the number of iterations in DSA signingTheo Buehler
The DSA standard specifies an infinite loop: if either r or s is zero in the signature calculation, a new random number k shall be generated and the whole thing is to be redone. The rationale is that, as the standard puts it, "[i]t is extremely unlikely that r = 0 or s = 0 if signatures are generated properly." The problem is... There is no cheap way to know that the DSA domain parameters we are handed are actually DSA domain parameters, so even if all our calculations are carefully done to do all the checks needed, we cannot know if we generate the signatures properly. For this we would need to do two primality checks as well as various congruences and divisibility properties. Doing this easily leads to DoS, so nobody does it. Unfortunately, it is relatively easy to generate parameters that pass all sorts of sanity checks and will always compute s = 0 since g is nilpotent. Thus, as unlikely as it is, if we are in the mathematical model, in practice it is very possible to ensure that s = 0. Read David Benjamin's glorious commit message for more information https://boringssl-review.googlesource.com/c/boringssl/+/57228 Thanks to Guido Vranken for reporting this issue, also thanks to Hanno Boeck who apparently found and reported similar problems earlier. ok beck jsing
2023-03-04Small readability tweak in old_dsa_priv_decode()Theo Buehler
Explicitly check against NULL and turn early return into goto err. ok beck jsing
2023-03-04Call dsa_check_keys() before signing or verifyingTheo Buehler
We already had some checks on both sides, but they were less precise and differed between the functions. The code here is messy enough, so any simplification is helpful... ok beck jsing
2023-03-04Add dsa_check_key() calls on DSA decodingTheo Buehler
When decoding a public or a private key, use dsa_check_key() to ensure consistency of the DSA parameters. We do not always have sufficient information to do that, so this is not always possible. This adds new checks and replaces incomplete existing ones. On decoding the private key we will now only calculate the corresponding public key, if the sizes are sensible. This avoids potentially expensive operations. ok beck jsing
2023-03-04Provide dsa_check_key()Theo Buehler
This is a cheap check that ensures basid parameter consistency per FIPS 186-4: 1 < g < q, that q has the allowed bit sizes 160, 224, 256 and that p is neither too small nor too large. Unfortunately, enforcing the three allowed sizes for p is not possible since the default dsa key generation has not respected this limitation. Instead of checking that p and q are prime, we only check that they are odd. Check that public and private keys, if set, are in the proper range. In particular, disallow zero values. Various versions of these checks have been added to the dsa code over time. This consolidates and extends them and in a subsequent commit wewill replace the incomplete checks. BoringSSL has a similar function of the same name, thanks to David Benjamin for pointing it out. ok beck jsing
2023-03-04Provide DSA_R_INVALID_PARAMETERS error codeTheo Buehler
This has been missing for a while already and will be used in a few upcoming commits. ok beck jsing
2023-02-13Merge dsa_sign.c and dsa_vrf.c into dsa_ossl.cTheo Buehler
discussed with jsing
2023-02-13dsa/dsa_sign.c: unindent by inverting logic for DSA_SIG_free(NULL)Theo Buehler
2023-02-13dsa/dsa_sign.c: shuffle functions into a more sensible orderTheo Buehler
2023-01-11Clean up and simplify BIGNUM handling in DSA code.Joel Sing
This adds missing BN_CTX_start()/BN_CTX_end() calls, removes NULL checks before BN_CTX_end()/BN_CTX_free() (since they're NULL safe) and calls BN_free() instead of BN_clear_free() (which does the same thing). Also replace stack allocated BIGNUMs with calls to BN_CTX_get(), using the BN_CTX that is already available. ok tb@
2023-01-11Simplify BIGNUM handling in dsa_builtin_keygen().Joel Sing
Rather than having complicated "attempt to reuse" dances, always allocate priv_key/pub_key, then free and assign on success. ok tb@
2022-11-26Make internal header file names consistentTheo Buehler
Libcrypto currently has a mess of *_lcl.h, *_locl.h, and *_local.h names used for internal headers. Move all these headers we inherited from OpenSSL to *_local.h, reserving the name *_internal.h for our own code. Similarly, move dtls_locl.h and ssl_locl.h to dtls_local and ssl_local.h. constant_time_locl.h is moved to constant_time.h since it's special. Adjust all .c files in libcrypto, libssl and regress. The diff is mechanical with the exception of tls13_quic.c, where #include <ssl_locl.h> was fixed manually. discussed with jsing, no objection bcook
2022-11-19Rework pkey_dsa_sign() and pkey_dsa_verify()Theo Buehler
Since DSA_sign() and DSA_verify() ignore their type argument, don't bother to determine it here. Check all size_t for overflow before passing them as int arguments. Follow OpenSSL and add a check to see if the tbs blob's length matches the one of the md, in case it is set on the EVP_PKEY_CTX. Fix return value check of DSA_sign(). ok jsing
2022-11-19Rework DSA_sign() and DSA_verify()Theo Buehler
Change DSA_sign() to single exit and check the signed i2d_DSA_SIG() return value before assigning it to an unsigned int. In DSA_verify() let d2i_DSA_SIG() handle the allocation, split error check of i2d_DSA_SIG() from signature check and change an unnecessary freezero() to free. ok jsing
2022-11-19Fix whitespaceTheo Buehler
2022-11-10Fix a few more leaks in *_print() functions.Tobias Heider
ok jsing@
2022-11-08Fix leak of pk if EVP_PKEY_set1_DSA() fails.Tobias Heider
Found with CodeChecker ok jsing@
2022-09-03Stop using CBIGNUM_it internal to libcrypto.Joel Sing
CBIGNUM_it is supposed to be the "clear bignum" or "secure" bignum - that is one which zeros its memory after use and ensures that the constant time flags are set... in LibreSSL we always do both of these things for BIGNUMs, so just use BIGNUM_it instead. ok tb@
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-07-12Remove mkerr.pl remnants from LibreSSLKlemens Nanni
This script is not used at all and files are edited by hand instead. Thus remove misleading comments incl. the obsolete script/config. Feedback OK jsing tb
2022-07-11fix NULL return adding missing semicolonBrent Cook
ok tb@
2022-07-07Expose new API in headers.Theo Buehler
These are mostly security-level related, but there are also ASN1_TIME and ASN_INTEGER functions here, as well as some missing accessors. ok jsing