openssl/crypto/ec
Nicola Tuveri 3712436071 EC point multiplication: add ladder scaffold
for specialized Montgomery ladder implementations

PR #6009 and #6070 replaced the default EC point multiplication path for
prime and binary curves with a unified Montgomery ladder implementation
with various timing attack defenses (for the common paths when a secret
scalar is feed to the point multiplication).
The newly introduced default implementation directly used
EC_POINT_add/dbl in the main loop.

The scaffolding introduced by this commit allows EC_METHODs to define a
specialized `ladder_step` function to improve performances by taking
advantage of efficient formulas for differential addition-and-doubling
and different coordinate systems.

- `ladder_pre` is executed before the main loop of the ladder: by
  default it copies the input point P into S, and doubles it into R.
  Specialized implementations could, e.g., use this hook to transition
  to different coordinate systems before copying and doubling;
- `ladder_step` is the core of the Montgomery ladder loop: by default it
  computes `S := R+S; R := 2R;`, but specific implementations could,
  e.g., implement a more efficient formula for differential
  addition-and-doubling;
- `ladder_post` is executed after the Montgomery ladder loop: by default
  it's a noop, but specialized implementations could, e.g., use this
  hook to transition back from the coordinate system used for optimizing
  the differential addition-and-doubling or recover the y coordinate of
  the result point.

This commit also renames `ec_mul_consttime` to `ec_scalar_mul_ladder`,
as it better corresponds to what this function does: nothing can be
truly said about the constant-timeness of the overall execution of this
function, given that the underlying operations are not necessarily
constant-time themselves.
What this implementation ensures is that the same fixed sequence of
operations is executed for each scalar multiplication (for a given
EC_GROUP), with no dependency on the value of the input scalar.

Co-authored-by: Sohaib ul Hassan <soh.19.hassan@gmail.com>
Co-authored-by: Billy Brumley <bbrumley@gmail.com>

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6690)
2018-07-16 10:17:40 +01:00
..
asm ec/asm/x25519-x86_64.pl: add CFI directives and Windows SE handler. 2018-07-15 19:05:57 +02:00
curve448 Remove some logically dead code 2018-05-31 10:38:51 +01:00
build.info ECC: unify generic ec2 and ecp scalar multiplication, deprecate ec2_mult.c 2018-05-09 13:30:38 +02:00
curve25519.c ec/curve25519.c: reorganize for better accessibility. 2018-07-15 19:06:06 +02:00
ec2_oct.c Modify Sun copyright to follow OpenSSL style 2017-06-20 11:13:45 -04:00
ec2_smpl.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ec_ameth.c Update copyright year 2018-06-20 15:29:23 +01:00
ec_asn1.c ECDSA_SIG: add simple getters for commonly used struct members 2018-05-28 19:11:23 +02:00
ec_check.c Copyright consolidation 06/10 2016-05-17 14:51:04 -04:00
ec_curve.c Improve compatibility of point and curve checks 2018-05-24 17:17:44 +01:00
ec_cvt.c Modify Sun copyright to follow OpenSSL style 2017-06-20 11:13:45 -04:00
ec_err.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ec_key.c Update copyright year 2018-04-17 15:18:40 +02:00
ec_kmeth.c Fix const correctness of EC_KEY_METHOD_get_* 2017-07-23 11:34:11 +02:00
ec_lcl.h EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ec_lib.c [crypto/ec] default to FLT or error 2018-06-21 18:08:56 +01:00
ec_mult.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ec_oct.c Improve compatibility of point and curve checks 2018-05-24 17:17:44 +01:00
ec_pmeth.c ec/ec_pmeth.c: minor cleanups and readability fixes. 2018-06-25 16:42:43 +02:00
ec_print.c Update copyright year 2018-04-17 15:18:40 +02:00
ecdh_kdf.c check return values for EVP_Digest*() APIs 2016-07-15 14:09:05 +01:00
ecdh_ossl.c Update copyright year 2018-04-03 13:57:12 +01:00
ecdsa_ossl.c ecdsa_ossl: address coverity nit 2018-06-22 11:54:30 -05:00
ecdsa_sign.c Useless includes 2016-06-18 16:30:24 -04:00
ecdsa_vrf.c Useless includes 2016-06-18 16:30:24 -04:00
eck_prn.c Remove parentheses of return. 2017-10-18 16:05:06 +01:00
ecp_mont.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ecp_nist.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ecp_nistp224.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ecp_nistp256.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ecp_nistp521.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ecp_nistputil.c Copyright consolidation 06/10 2016-05-17 14:51:04 -04:00
ecp_nistz256_table.c Copyright consolidation 05/10 2016-05-17 15:38:09 -04:00
ecp_nistz256.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ecp_oct.c Many spelling fixes/typo's corrected. 2017-11-11 19:03:10 -05:00
ecp_smpl.c EC point multiplication: add ladder scaffold 2018-07-16 10:17:40 +01:00
ecx_meth.c Add support getting raw private/public keys 2018-06-08 10:04:09 +01:00