summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_smpl.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Rename ecp_smpl.c to ecp_methods.ctb2024-11-121-1656/+0
| | | | | | | | While not the greatest of names, ecp_methods.c is better than ecp_smpl.c. It matches the naming ecx_methods.c and in a subsequent commit it will become the new home of the stuff in ecp_mont.c as well. discussed with jsing
* EC_POINT_is_at_infinity() returns a booleantb2024-11-051-10/+10
| | | | | | | | | This may have been different at some point in the past, but it may also have been a confusion with EC_POINT_is_on_curve() which, like any great API with a name implying a boolean return, actually has three possible return values. ok jsing
* affine coordinates: the intention was to move the check, not to copy it...tb2024-11-031-6/+1
| | | | | So... zap the now redundant check. Should have been committed along with ec_lib.c -r1.77
* Fix includes in ec_lib and ecp_smpltb2024-11-021-1/+6
|
* Merge compressed coordinate setting back into ecp_smpl and ec_libtb2024-11-021-1/+99
| | | | The reason these were in separate files was FIPS. Not our problem.
* Retire the oct2point and point2oct EC_METHOD memberstb2024-10-311-3/+1
| | | | | | | | Both our remaining EC_METHODs use the methods that used to be called ec_GFp_simple_{oct2point,point2oct}() so there's no need for the function pointer indirection. Make the public API call them directly. ok jsing
* Make the bn_rand_interval() API a bit more ergonomictb2023-08-031-2/+2
| | | | | | | | | | | | | | | | | | 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
* Tweak EC_GROUP_check_discriminant()tb2023-07-261-28/+28
| | | | | | | | Make the logic and control flow a bit more explicit and use a single extra variable for computing the discriminant. Call it discriminant, not tmp, tmp_1 or tmp_2. ok jsing
* Unindent a big block in EC_GROUP_get_affine_coordinates()tb2023-07-261-32/+34
|
* Introduce and use ec_encode_scalar()tb2023-07-261-43/+48
| | | | | | | | | | | | This introduces two "inverses" of the ec_decode_scalar() function that take a BIGNUM, reduce it modulo p and then encodes it into the curve's field representation. For setting projective coordinates, we need a specialized helper that deals with the Z_is_one optimization that is used to optimize for calculations in standard affine coordinates of the projective plane. This is used for simplifying EC_POINT_set_Jprojective_coordinates() and for cleaning up and streamlining EC_GROUP_set_curve(). ok jsing
* Garbage collect the unused order in check_discriminant()tb2023-07-261-4/+2
| | | | ok jsing
* Streamline check_discriminant()tb2023-07-261-14/+6
| | | | | | Instead of inlining EC_GROUP_get_curve(), we can simply call it... ok jsing
* Introduce ec_decode_scalar()tb2023-07-261-81/+39
| | | | | | | | | This is a helper that decodes a scalar from field-internal representation to a representation as a BIGNUM in the interval [0, p). This simplifies EC_GROUP_get_curve() and EC_POINT_get_Jprojective_coordinates() to a few obvious lines and prepares cleanup in EC_POINT_get_affine_coordinates(). ok jsing
* Use EC_POINT_set_to_infinity() rather than inlining ittb2023-07-261-6/+4
|
* Fix a few more 0/NULL misspellingstb2023-07-251-8/+8
|
* Use [a,b), not [a,b-1] in a commenttb2023-07-251-2/+2
|
* Hide symbols in hkdf, evp, err, ecdsa, and ecbeck2023-07-071-1/+2
| | | | | | (part 2 of commit) ok jsing@
* whitespacetb2023-06-301-2/+2
|
* Handle BN_CTX at the EC API boundary.jsing2023-04-111-133/+53
| | | | | | | | | | | The EC API allows callers to optionally pass in a BN_CTX, which means that any code needing a BN_CTX has to check if one was provided, allocate one if not, then free it again. Rather than doing this dance throughout the EC code, handle the BN_CTX existance at the EC API boundary. This means that lower level implementation code can simply assume that the BN_CTX is available. ok tb@
* Replace the remaining BN_copy() with bn_copy()tb2023-03-271-33/+33
| | | | ok jsing
* Always clear EC groups and points on free.jsing2023-03-081-19/+1
| | | | | | | | | | Rather than sometimes clearing, turn the free functions into ones that always clear (as we've done elsewhere). Turn the EC_GROUP_clear_free() and EC_POINT_clear_free() functions into wrappers that call the *_free() version. Do similar for the EC_METHOD implementations, removing the group_clear_finish() and point_clear_finish() hooks in the process. ok tb@
* Remove EC_FLAGS_DEFAULT_OCT.jsing2023-03-081-2/+5
| | | | | | | | | | | | | | The EC code has an amazing array of function pointer hooks, such that a method can hook into almost any operation... and then there is the EC_FLAGS_DEFAULT_OCT flag, which adds a bunch of complex code and #ifdef so you can avoid setting three of those function pointers! Remove EC_FLAGS_DEFAULT_OCT, the now unused flags field from EC_METHOD, along with the various code that was wrapped in EC_FLAGS_DEFAULT_OCT, setting the three function pointers that need to be set in each of the EC_METHODs. ok beck@ tb@
* Call BN_free() instead of BN_clear_free().jsing2023-03-071-8/+8
| | | | | | | BN_clear_free() is a wrapper that calls BN_free() - call BN_free() directly instead. ok tb@
* Move EC_GFp_simple_method() to the bottom of the file.jsing2023-03-071-75/+51
| | | | | | | | Most of the implemeentation functions for EC_GFp_simple_method() are reused by other code, hence they cannot be made static. However, this keeps the pattern consistent. ok tb@
* Make internal header file names consistenttb2022-11-261-3/+3
| | | | | | | | | | | | | | | | 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
* Change bn_expand()/bn_wexpand() to indicate failure/success via 0/1.jsing2022-11-241-9/+9
| | | | | | | | | Currently bn_expand()/bn_wexpand() return a BIGNUM *, however none of the callers use this (and many already treat it as a true/false value). Change these functions to return 0 on failure and 1 on success, revising callers that test against NULL in the process. ok tb@
* Fix an annoying quirk in the EC codetb2022-11-191-28/+28
| | | | | | Dealing with elliptic curves makes some people think that it would be kind of neat to multiply types with variable names. Sometimes. Only in function definitions.
* whitespacetb2022-11-191-7/+7
|
* Fix check for BN_mod_inverse_ct return valueinoguchi2022-01-201-3/+3
| | | | ok jsing@ millert@ tb@
* Prepare to provide EC_GROUP_order_bits()tb2021-09-081-1/+2
| | | | ok jsing
* Fix indent of EC_METHODs as requested by jsing.tb2021-04-201-33/+33
| | | | While there zap trailing whitespace from a KNF approximation gone wrong.
* Provide EC_POINT_{g,s}et_Jprojective_coordinates for internal usetb2021-04-201-17/+16
| | | | ok jsing
* Prepare to provide EC_POINT_{g,s}et_affine_coordinatestb2021-04-201-3/+3
| | | | | | Similar to part of OpenSSL commit 8e3cced75fb5fee5da59ebef9605d403a999391b ok jsing
* Port OpenSSL commit 99540ec79491f59ed8b46b4edf130e17dc907f52 -- mitigationtb2018-11-151-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
* unrevert the use of bn_rand_interval().tb2018-11-061-5/+3
| | | | ok beck jsing
* Unset Z_is_zero after applying coordinate blinding andtb2018-11-061-3/+4
| | | | | | re-enable coordinate blinding. ok jsing
* disable EC_POINT coordinate blinding due to failures in ECDHE and TLStb2018-11-061-1/+3
|
* revert use of bn_rand_interval due to failures with ECDHE and TLStb2018-11-061-3/+5
|
* Make use of bn_rand_interval() where appropriate.tb2018-11-051-5/+3
| | | | ok beck jsing
* Implement coordinate blinding for EC_POINT.tb2018-11-051-3/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* Recommit Billy Brumley's ECC constant time patch with a fix for sparc64tb2018-07-161-1/+249
| | | | | | | from Nicola Tuveri (who spotted the omission of ecp_nist.c from the PR). discussed with jsing tested by jsg
* recommit label indentation part of the backout; clearly unrelated to thetb2018-07-151-13/+13
| | | | breakage.
* back out ecc constant time changesjsg2018-07-151-261/+13
| | | | | | | | 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@
* Indent labels by a space so they don't obliterate function names in diffs.tb2018-07-101-13/+13
|
* ECC constant time scalar multiplication support. First step in overhaulingtb2018-07-101-1/+249
| | | | | | | | | | | 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
* Send the function codes from the error functions to the bit bucket,beck2017-01-291-8/+8
| | | | | | as was done earlier in libssl. Thanks inoguchi@ for noticing libssl had more reacharounds into this. ok jsing@ inoguchi@
* Add ct and nonct versions of BN_mod_inverse for internal usebeck2017-01-211-3/+4
| | | | ok jsing@
* BN_CTX_get() can fail - consistently check its return value.jsing2015-02-091-43/+58
| | | | | | | | | | | | | | | There are currently cases where the return from each call is checked, the return from only the last call is checked and cases where it is not checked at all (including code in bn, ec and engine). Checking the last return value is valid as once the function fails it will continue to return NULL. However, in order to be consistent check each call with the same idiom. This makes it easy to verify. Note there are still a handful of cases that do not follow the idiom - these will be handled separately. ok beck@ doug@
* Use `> 0' instead of `!= 0' as a successful condition formiod2015-02-081-11/+11
| | | | | | EC_POINT_is_at_infinity() and EC_POINT_is_on_curve(), for they may return -1 should an error arise. ok doug@ jsing@
* if (x) FOO_free(x) -> FOO_free(x).miod2014-07-121-27/+14
| | | | | | | Improves readability, keeps the code smaller so that it is warmer in your cache. review & ok deraadt@