Commit graph

454 commits

Author SHA1 Message Date
Tom Cosgrove
09d23786f6
Merge pull request #7429 from xkqian/bignumber_update_comments
Update links to references in bignum
2023-04-26 16:21:56 +01:00
Xiaokang Qian
50fe36317a Update links in ecp.c
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
2023-04-12 06:08:45 +00:00
Valerio Setti
fd122f4e95 ecp: introduce new ECP_LIGHT symbol
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-04-11 11:33:50 +02:00
Xiaokang Qian
669c7c35f0 Update SEC1 link in ecp.c
Old link doesn't work any more, update it to one
new link to refer version 2

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
2023-04-10 07:36:35 +00:00
Minos Galanakis
d61dbd4df7 ecp_curves: Update mbedtls_ecp_group_free().
This patch updates the method to not free the `grp->P`
and `grp->N` structure members.

The contents of `P` and `N` are stored in static memory at
`curve448_p/n` and `curve25519p/n` and no longer dynamically
allocated.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-01-19 16:11:55 +00:00
Gilles Peskine
449bd8303e Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:50:10 +01:00
Manuel Pégourié-Gonnard
2510dd41bf
Merge pull request #6282 from gstrauss/sw_derive_y
mbedtls_ecp_point_read_binary from compressed fmt
2022-12-22 10:20:31 +01:00
Glenn Strauss
efde9d58de remove duplicated consecutive preproc directives
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-12-20 04:20:12 -05:00
Manuel Pégourié-Gonnard
8b6d14be8b Extract common code for computing X^3 + AX + B
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-12-20 04:17:03 -05:00
Glenn Strauss
452416121d move mbedtls_ecp_sw_derive_y after MPI_ECP_ macros
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-12-19 21:25:27 -05:00
Glenn Strauss
fcabc28cfc use MPI_ECP_* macros in mbedtls_ecp_sw_derive_y()
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-12-19 21:24:50 -05:00
Glenn Strauss
cbfd5e9db7 comment
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-12-16 11:03:41 -05:00
Glenn Strauss
369bfb94c5 comments and whitespace
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-12-16 10:49:04 -05:00
Gilles Peskine
5a34b36bbd Remove more now-redundant definitions of inline
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-25 13:26:44 +01:00
Dave Rodgman
1a22bef116
Merge pull request #6190 from daverodgman/invalid-ecdsa-pubkey
Improve ECDSA verify validation
2022-10-31 09:37:26 +00:00
Gilles Peskine
75c4eaf1f8
Merge pull request #5841 from aurel32/ecp_mul_mxz-timing-leak
Fix a timing leak in ecp_mul_mxz()
2022-10-27 19:46:48 +02:00
Gilles Peskine
744fd37d23
Merge pull request #6467 from davidhorstmann-arm/fix-unusual-macros-0
Fix unusual macros
2022-10-25 19:55:29 +02:00
David Horstmann
6e11687ba5 Minor improvements to ecp.c changes
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-10-25 10:32:08 +01:00
David Horstmann
fc735dffd6 Refactor macro-spanning ifs in ecp.c
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-10-07 14:08:42 +01:00
Glenn Strauss
2ff77119df mbedtls_ecp_point_read_binary from compressed fmt
mbedtls_ecp_point_read_binary from MBEDTLS_ECP_PF_COMPRESSED format

Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-10-03 05:43:27 -04:00
Gilles Peskine
945b23c46f Include platform.h unconditionally: automatic part
We used to include platform.h only when MBEDTLS_PLATFORM_C was enabled, and
to define ad hoc replacements for mbedtls_xxx functions on a case-by-case
basis when MBEDTLS_PLATFORM_C was disabled. The only reason for this
complication was to allow building individual source modules without copying
platform.h. This is not something we support or recommend anymore, so get
rid of the complication: include platform.h unconditionally.

There should be no change in behavior since just including the header should
not change the behavior of a program.

This commit replaces most occurrences of conditional inclusion of
platform.h, using the following code:

```
perl -i -0777 -pe 's!#if.*\n#include "mbedtls/platform.h"\n(#else.*\n(#define (mbedtls|MBEDTLS)_.*\n|#include <(stdarg|stddef|stdio|stdlib|string|time)\.h>\n)*)?#endif.*!#include "mbedtls/platform.h"!mg' $(git grep -l '#include "mbedtls/platform.h"')
```

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-09-15 20:33:07 +02:00
Dave Rodgman
c947751a5f Fix ECDSA signature verification edge-case
For R and S equal to 1, ensure the public key is checked
for validity.

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-08-19 11:16:37 +01:00
Tuvshinzaya Erdenekhuu
86669de348 Broke 2 long lines
Signed-off-by: Tuvshinzaya Erdenekhuu <tuvshinzaya.erdenekhuu@arm.com>
2022-07-28 10:31:16 +01:00
Tuvshinzaya Erdenekhuu
22f3654324 Remove NULL pointer validation in ecp.c
Signed-off-by: Tuvshinzaya Erdenekhuu <tuvshinzaya.erdenekhuu@arm.com>
2022-07-27 15:21:48 +01:00
Aurelien Jarno
c79ce88152 Fix a timing leak in ecp_mul_mxz()
The bit length of m is leaked through through timing in ecp_mul_mxz().
Initially found by Manuel Pégourié-Gonnard on ecp_mul_edxyz(), which has
been inspired from ecp_mul_mxz(), during initial review of the EdDSA PR.
See: https://github.com/Mbed-TLS/mbedtls/pull/3245#discussion_r490827996

Fix that by using grp->nbits + 1 instead, which anyway is very close to
the length of m, which means there is no significant performance impact.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-05-16 23:15:07 +02:00
Dave Rodgman
2a045325f9
Merge pull request #5766 from leorosen/fix-var-init
Add missing local variable initialization
2022-05-16 14:47:00 +01:00
Leonid Rozenboim
a3008e7e2e Add missing local variable initialization
These issues were flagged by Coverity as instances where a local
variable may be used prior to being initialized. Please note that
none of these changes fixes any particular bug, this is just an attempt
to add more robustness.

Signed-off-by: Leonid Rozenboim <leonid.rozenboim@oracle.com>
2022-05-13 18:08:11 +01:00
Shaun Case
8b0ecbccf4 Redo of PR#5345. Fixed spelling and typographical errors found by CodeSpell.
Signed-off-by: Shaun Case <warmsocks@gmail.com>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-05-11 21:25:51 +01:00
Przemek Stekiel
ab5274bb19 Remove parameters validation using ECP_VALIDATE_RET
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
2022-03-28 07:23:08 +02:00
Przemek Stekiel
711d0f5e29 Add implemetation of ECP keypair export function
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
2022-03-18 13:52:26 +01:00
Hanno Becker
bae3023576 Make more use of helper function for init/free of MPI array
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-11 05:06:54 +00:00
Hanno Becker
466df6e713 Introduce helper function for init/free of MPI array
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-10 11:24:42 +00:00
Hanno Becker
ac4d4bc97c Improve documentation of ECP module
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-09 06:34:04 +00:00
Hanno Becker
ee95f6c4c9 Don't allow Z coordinate being unset in ecp_add_mixed()
Previously, ecp_add_mixed(), commputing say P+Q, would allow for the
Q parameter to have an unset Z coordinate as a shortcut for Z == 1.
This was leveraged during computation and usage of the T-table
(storing low multiples of the to-be-multiplied point on the curve).
It is a potentially error-prone corner case, though, since an MPIs
with unset data pointer coordinate and limb size 0 is also a valid
representation of the number 0.

As a first step towards removing ECP points with unset Z coordinate,
the constant time T-array getter ecp_select_comb() has previously
been modified to return 'full' mbedtls_ecp_point structures,
including a 1-initialized Z-coordinate.

Similarly, this commit ...

- Modifies ecp_normalize_jac_many() to set the Z coordinates
  of the points it operates on to 1 instead of freeing them.

- Frees the Z-coordinates of the T[]-array explicitly
  once the computation and normalization of the T-table has finished.

  As a minimal functional difference between old and new code,
  the new code also frees the Z-coordinate of T[0]=P, which the
  old code did not.

- Modifies ecp_add_mixed() to no longer allow unset Z coordinates.

Except for the post-precomputation storage form of the T[] array,
the code does therefore no longer use EC points with unset Z coordinate.

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-09 05:52:40 +00:00
Hanno Becker
c27a0e0093 Add more wrappers for ECP MPI operations
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-06 09:21:50 +00:00
Hanno Becker
595616e5cd Add more wrappers for internal ECP coordinate operations
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-06 05:12:02 +00:00
Hanno Becker
6a28870b1e Make ecp_select_comb() create valid EC point with Z coordinate set
ecp_select_comb() did previously not set the Z coordinate of the target point.
Instead, callers would either set it explicitly or leave it uninitialized,
relying on the (only partly upheld) convention that sometimes an uninitialized
Z value represents 1.

This commit modifies ecp_select_comb() to always set the Z coordinate to 1.
This comes at the cost of memory for a single coordinate, which seems worth
it for the increased robustness.

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-06 04:46:45 +00:00
Hanno Becker
30838868ac Keep temporaries across iterations of ecp_double_add_mxz()
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-05 06:09:42 +00:00
Hanno Becker
3b29f2194b Keep temporaries across iterations of ecp_add_mixed()
This saves heap operations

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 07:34:14 +00:00
Hanno Becker
a7f8edd709 Keep temporaries across iterated invocations of ecp_double_jac()
This reduces the number of heap operations.

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 07:29:46 +00:00
Hanno Becker
28ccb1cc90 Reduce number of local MPIs from 9 to 4 in ecp_double_add_mxz()
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 07:15:14 +00:00
Hanno Becker
376dc89519 Reorder ops in ecp_double_add_mxz() to indicate redundant local MPIs
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 07:14:07 +00:00
Hanno Becker
0d629791e9 Remove local MPI from ecp_randomize_jac()
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 06:45:49 +00:00
Hanno Becker
885ed403c9 Introduce wrapper for modular squaring
This paves the way for dedicated squaring implementations.

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 06:43:50 +00:00
Hanno Becker
b8442cd9c6 Remove another local MPI from ecp_normalize_jac_many()
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 06:32:42 +00:00
Hanno Becker
02a999b91a Remove local MPI from ecp_normalize_jac_many()
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 06:32:42 +00:00
Hanno Becker
838b715fcc Add comment on input/output aliasing in ecp_add_mixed()
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 06:32:42 +00:00
Hanno Becker
ce29ae84dd Introduce macro wrappers for ECC modular arithmetic
This improves readibility and prepares for further changes
like the introduction of a single double-width temporary for
ECP arithmetic.

Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-04 06:32:39 +00:00
Hanno Becker
76f897d699 Reduce number of temporary MPIs in ECP normalization
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-02 12:47:34 +00:00
Hanno Becker
02b35bd00a Introduce wrapper for modular multiplication with single-width const
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-01-01 06:54:25 +00:00