1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-07-23 17:48:42 +08:00
Gilles Peskine 1acf7cb76c Avoid reallocating during subtraction
mbedtls_mpi_sub_abs systematically allocated a new mpi when the result
was aliased with the right operand (i.e. X = A - X). This aliasing
very commonly happens during ECP operations. Rewrite the function to
allocate only if the result might not fit otherwise.

This costs a few bytes of code size in bignum.o, and might make
mbedtls_mpi_sub_abs very very slightly slower when no reallocation is
done. However, there is a substantial performance gain in ECP
operations with Montgomery curves (10-20% on my PC).

test_suite_ecp drops from 1422794 to 1271506 calls to calloc().

This commit also fixes a bug whereby mbedtls_mpi_sub_abs would leak
memory when X == B (so TB was in use) and the result was negative.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-07 22:51:25 +01:00
..
2020-12-07 22:51:25 +01:00
2020-12-07 22:51:25 +01:00
2020-11-16 15:02:16 +01:00
2020-08-21 21:08:56 +02:00
2020-08-21 21:08:56 +02:00
2020-08-21 21:08:56 +02:00
2020-09-22 11:57:16 +02:00
2020-11-20 13:57:15 +01:00
2020-08-21 21:08:56 +02:00
2020-09-25 08:43:57 -05:00
2020-08-21 21:08:56 +02:00
2020-11-13 09:20:18 +00:00
2020-09-01 11:04:53 +02:00