summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/ec
AgeCommit message (Collapse)AuthorFilesLines
2020-12-04Move point-on-curve check to set_affine_coordinatestb4-18/+50
Bad API design makes it possible to set an EC_KEY public key to a point not on the curve. As a consequence, it was possible to have bogus ECDSA signatures validated. In practice, all software uses either EC_POINT_oct2point*() to unmarshal public keys or issues a call to EC_KEY_check_key() after setting it. This way, a point on curve check is performed and the problem is mitigated. In OpenSSL commit 1e2012b7ff4a5f12273446b281775faa5c8a1858, Emilia Kasper moved the point-on-curve check from EC_POINT_oct2point to EC_POINT_set_affine_coordinates_*, which results in more checking. In addition to this commit, we also check in the currently unused codepath of a user set callback for setting compressed coordinates, just in case this will be used at some point in the future. The documentation of EC_KEY_check_key() is very vague on what it checks and when checks are needed. It could certainly be improved a lot. It's also strange that EC_KEY_set_key() performs no checks, while EC_KEY_set_public_key_affine_coordinates() implicitly calls EC_KEY_check_key(). It's a mess. Issue found and reported by Guido Vranken who also tested an earlier version of this fix. ok jsing
2020-06-05Add support for additional GOST curves.jsing1-5/+163
These GOST curves are defined in RFC 7836 and draft-deremin-rfc4491-bis. Add aliases for 256-bit GOST curves (see draft-smyshlyaev-tls12-gost-suites) and rename the 512-bit curve ids to follow names defined in tc26 OID registry. Diff from Dmitry Baryshkov <dbaryshkov@gmail.com> Sponsored by ROSA Linux. ok inoguchi@
2019-09-29If a NULL or zero cofactor is passed to EC_GROUP_set_generator(),tb3-11/+113
try to compute it using Hasse's bound. This works as long as the cofactor is small enough. Port of Brumley's fix for CVE-2019-1547 in OpenSSL 1.1.1 (old license) tests & ok inoguchi input & ok jsing commit 30c22fa8b1d840036b8e203585738df62a03cec8 Author: Billy Brumley <bbrumley@gmail.com> Date: Thu Sep 5 21:25:37 2019 +0300 [crypto/ec] for ECC parameters with NULL or zero cofactor, compute it The cofactor argument to EC_GROUP_set_generator is optional, and SCA mitigations for ECC currently use it. So the library currently falls back to very old SCA-vulnerable code if the cofactor is not present. This PR allows EC_GROUP_set_generator to compute the cofactor for all curves of cryptographic interest. Steering scalar multiplication to more SCA-robust code. This issue affects persisted private keys in explicit parameter form, where the (optional) cofactor field is zero or absent. It also affects curves not built-in to the library, but constructed programatically with explicit parameters, then calling EC_GROUP_set_generator with a nonsensical value (NULL, zero). The very old scalar multiplication code is known to be vulnerable to local uarch attacks, outside of the OpenSSL threat model. New results suggest the code path is also vulnerable to traditional wall clock timing attacks. CVE-2019-1547 Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> (Merged from https://github.com/openssl/openssl/pull/9781)
2019-09-09Plug memory leak in error paths. Found while comparing this filetb1-5/+5
with OpenSSL 1.1.1's version which contains a similar fix. ok jsing
2019-09-09Provide EVP_PKEY_CTX_get_signature_md() macro and implement thejsing1-1/+5
EVP_PKEY_CTRL_GET_MD control for DSA, EC and RSA. This is used by the upcoming RSA CMS code. ok inoguchi@ tb@
2019-09-09Move #include <openssl/cms.h> to more appropriate location (since it isjsing1-3/+2
now being installed).
2019-09-08Add CMS ECC support.jsing1-2/+370
This brings in EC code from OpenSSL 1.1.1b, with style(9) and whitespace cleanups. All of this code is currently under OPENSSL_NO_CMS hence is a no-op. ok inoguchi@
2019-09-06Add various macros and controls for EC_PKEY_CTX.jsing3-26/+313
These are needed for the upcoming EC CMS support (nothing else appears to use them). This largely syncs our ec_pmeth.c with OpenSSL 1.1.1b. With input from inoguchi@ and tb@. ok inoguchi@ tb@
2019-05-10Initialize EC_KEY_METHOD before use.bcook1-2/+2
Fixes COV-186146 ok tb, beck
2019-01-19$OpenBSD$tb1-0/+1
2019-01-19Partial port of EC_KEY_METHOD from OpenSSL 1.1.tb2-9/+9
Pass const method to EC_KEY_METHOD_get_*() to get rid of an XXX. from markus
2019-01-19Partial port of EC_KEY_METHOD from OpenSSL 1.1.tb4-29/+125
This commit adds missing API for ECDH/ECDSA_verify. from markus
2019-01-19Partial port of EC_KEY_METHOD from OpenSSL 1.1.tb4-23/+401
This commit adds init/free, support for signing, setting and getting the method, engine support as well as extra data. from markus
2018-11-15Port OpenSSL commit 99540ec79491f59ed8b46b4edf130e17dc907f52 -- mitigationtb1-4/+4
for a timing vullnerability in ECDSA signature generation (CVE-2018-0735). Note that the blinding that we introduced back in June for ECDSA and DSA should mitigate this and related issues. This simply adds an additional layer of protection. discussed with jsing
2018-11-09Avoid dereferencing eckey before checking it for NULL.tb1-5/+6
CID 184282 ok beck jsing mestre
2018-11-06unrevert the use of bn_rand_interval().tb3-12/+9
ok beck jsing
2018-11-06Unset Z_is_zero after applying coordinate blinding andtb1-3/+4
re-enable coordinate blinding. ok jsing
2018-11-06disable EC_POINT coordinate blinding due to failures in ECDHE and TLStb1-1/+3
2018-11-06revert use of bn_rand_interval due to failures with ECDHE and TLStb2-7/+10
2018-11-05Make use of bn_rand_interval() where appropriate.tb2-10/+7
ok beck jsing
2018-11-05Eliminate a few "} else" branches, a few unneeded NULL checks beforetb1-16/+12
freeing and indent nearby labels. ok beck jsing
2018-11-05Implement coordinate blinding for EC_POINT.tb10-18/+110
Based on OpenSSL commit 875ba8b21ecc65ad9a6bdc66971e50 by Billy Brumley, Sohaib ul Hassan and Nicola Tuveri. ok beck jsing commit 875ba8b21ecc65ad9a6bdc66971e50461660fcbb Author: Sohaib ul Hassan <soh.19.hassan@gmail.com> Date: Sat Jun 16 17:07:40 2018 +0300 Implement coordinate blinding for EC_POINT This commit implements coordinate blinding, i.e., it randomizes the representative of an elliptic curve point in its equivalence class, for prime curves implemented through EC_GFp_simple_method, EC_GFp_mont_method, and EC_GFp_nist_method. This commit is derived from the patch https://marc.info/?l=openssl-dev&m=131194808413635 by Billy Brumley. Coordinate blinding is a generally useful side-channel countermeasure and is (mostly) free. The function itself takes a few field multiplicationss, but is usually only necessary at the beginning of a scalar multiplication (as implemented in the patch). When used this way, it makes the values that variables take (i.e., field elements in an algorithm state) unpredictable. For instance, this mitigates chosen EC point side-channel attacks for settings such as ECDH and EC private key decryption, for the aforementioned curves. For EC_METHODs using different coordinate representations this commit does nothing, but the corresponding coordinate blinding function can be easily added in the future to extend these changes to such curves. Co-authored-by: Nicola Tuveri <nic.tuv@gmail.com> Co-authored-by: Billy Brumley <bbrumley@gmail.com> Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/6526)
2018-09-01Tweak comment.tb1-5/+2
2018-08-24Add consts to EVP_PKEY_asn1_set_private()tb1-2/+2
Requires adding a const to the priv_decode() member of EVP_PKEY_ASN1_METHOD and adjusting all *_priv_decode() functions. All this is already documented this way. tested in a bulk build by sthen ok jsing
2018-08-24After removing support for broken PKCS#8 formats (it was high time),tb1-2/+2
we can add const to PKCS8_pkey_get0(). In order for this to work, we need to sprinkle a few consts here and there. tested in a bulk by sthen ok jsing
2018-07-23Use BN_swap_ct() instead of BN_consttime_swap() intb1-5/+10
ec_GF2m_montgomery_point_multiply(). The new BN_swap_ct() API is an improved version of the public BN_consttime_swap() function: it allows error checking, doesn't assert(), and has fewer assumptions on the input. This diff eliminates the last use of BN_consttime_swap() in our tree. ok inoguchi, jsing
2018-07-16Recommit Billy Brumley's ECC constant time patch with a fix for sparc64tb6-47/+341
from Nicola Tuveri (who spotted the omission of ecp_nist.c from the PR). discussed with jsing tested by jsg
2018-07-15recommit label indentation part of the backout; clearly unrelated to thetb19-91/+93
breakage.
2018-07-15back out ecc constant time changesjsg20-426/+133
after the constant time commits various regress tests started failing on sparc64 ssh t9, libcrypto ec ecdh ecdsa and trying to ssh out resulted in 'invalid elliptic curve value' ok tb@
2018-07-10Indent labels by a space so they don't obliterate function names in diffs.tb19-91/+93
2018-07-10ECC constant time scalar multiplication support. First step in overhaulingtb5-46/+337
the EC module. From Billy Brumley and his team, via https://github.com/libressl-portable/openbsd/pull/94 With tweaks from jsing and me. ok jsing
2018-05-19Add a const qualifier to the 'key' argument of i2o_ECPublicKey() andtb2-4/+4
one to the last argument of each one of i2s_ASN1_OCTET_STRING(), s2i_ASN1_OCTET_STRING(), i2s_ASN1_INTEGER(), i2s_ASN1_ENUMERATED(), and i2s_ASN1_ENUMERATED_TABLE(). tested in a bulk build by sthen ok jsing
2018-05-01Convert a handful of X509_*() functions to take const as in OpenSSL.tb1-6/+6
tested in a bulk by sthen ok jsing
2018-04-23Make whitespace between functions and structs a bit more consistent.tb1-3/+7
2018-03-16Consistently spell "IPsec" in comments and debug outputs.mpi1-2/+2
From Raf Czlonka, ok sthen@
2018-03-12Fix for processing of EC public keyinoguchi2-15/+27
Prevents segmentation fault while reading EC private key without public key. Generates missing EC public key when reading EC private key. Refer to these OpenSSL commits: 1f2b943254ce590867717375e4f364860a9b7154 2083f7c465d07867dd9867b8742bb71c03d1f203 Reported on GitHub https://github.com/libressl-portable/portable/issues/395 by Anton Bukov (@k06a) . ok beck@
2017-05-26Avoid a potential NULL pointer dereference in d2i_ECPrivateKey().jsing1-1/+7
Reported by Robert Swiecki, who found the issue using honggfuzz. ok bcook@
2017-05-02use freezero() instead of memset/explicit_bzero + free. Substantiallyderaadt7-30/+17
reduces conditional logic (-218, +82). MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH cache alignment calculation bn/bn_exp.c wasn'tt quite right. Two other tricky bits with ASN1_STRING_FLAG_NDEF and BN_FLG_STATIC_DATA where the condition cannot be collapsed completely. Passes regress. ok beck
2017-01-29Send the function codes from the error functions to the bit bucket,beck22-562/+391
as was done earlier in libssl. Thanks inoguchi@ for noticing libssl had more reacharounds into this. ok jsing@ inoguchi@
2017-01-21Add ct and nonct versions of BN_mod_inverse for internal usebeck1-3/+4
ok jsing@
2016-12-21Explicitly export a list of symbols from libcrypto.jsing2-3/+14
Move the "internal" BN functions from bn.h to bn_lcl.h and stop exporting the bn_* symbols. These are documented as only being intended for internal use, so why they were placed in a public header is beyond me... This hides 363 previously exported symbols, most of which exist in headers that are not installed and were never intended to be public. This also removes a few crusty old things that should have died long ago (like _ossl_old_des_read_pw). But don't worry... there are still 3451 symbols exported from the library. With input and testing from inoguchi@. ok beck@ inoguchi@
2016-11-04Add assembler code for the nist 256-bit GFp curve, written initially bymiod9-6/+19107
Intel. Obtained from BoringSSL, with some integration work borrowed from OpenSSL 1.0.2; assembler code for arm and sparc64 borrowed from OpenSSL 1.1.0. None of this code is enabled in libcrypto yet. ok beck@ jsing@
2016-10-19unifdef OPENSSL_NO_CMSjsing1-22/+1
2016-09-03remove unused variablebeck1-2/+1
2016-09-03Fix some very unnecessary convoultion.beck1-16/+6
ok krw@
2016-03-20" the the " -> " the ", or in a couple of cases replace the superfluouskrw1-2/+2
"the" with the obviously intended word. Started with a "the the" spotted by Mihal Mazurek.
2016-03-12Add error handling to the remaining calls to bn_wexpand().bcook1-12/+16
Noticed by pascal-cuoq from Github: https://github.com/libressl-portable/openbsd/issues/56 ok beck@
2016-03-10http -> https for a few more IETF URLs in comments or man pagesmmcc1-2/+2
2015-10-16Remove pointless externs - the structs are declared in the same files ajsing1-3/+1
few lines above.
2015-10-16Expand DECLARE_ASN1_ALLOC_FUNCTIONS and DECLARE_ASN1_FUNCTIONS_constjsing1-6/+17
macros. The only change in the generated assembly is due to line numbering.