mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

Extract Montgomery multiplication from the prototype

Open yanesca opened this issue 2 years ago • 0 comments

The task is to extract Montgomery multiplication from the prototype: https://github.com/hanno-arm/mbedtls/blob/ecp_prototype/library/bignum_core.c#L366-L394

Doing this will involve extracting other core functions (like for example MPI_CORE(sub)) as well.

This task is about extracting the MPI_CORE(montmul) function. MPI_CORE(montmul_d) is out of scope.

There should be separate commits containing the code from the prototype, with the absolute minimum of modifications that make the library compile. (It is Ok if these functions are not called at all at this point.) These commits should have Hanno as the author (git commit --author="Hanno Becker <[email protected]>")

Function declarations should go to library/bignum_core.h and implementations to library/bignum_new.c. (This will involve renaming library/bignum_internal.h.)

The task includes making the legacy Bignum functions call the extracted functions where the functionality is duplicated. For example, instead of mpi_sub_hlp() in bignum.c the new mpi_core_sub() should be called as well. This is necessary to minimise cost in code size.

The prototype is too macro heavy. Most new macros should be expanded/removed or replaced with static functions if possible. (Pre-existing macros should not be touched.) The macro MPI_CORE should expand to mbedtls_mpi_core_ ## func ## instead of mbedtls_mpi_core_ ## func ## _minimal.

This task is done when:

  • [x] The MPI_CORE(montmul) and its dependencies are taken from the prototype and credit is given to Hanno
  • [x] New macros are expanded/removed
  • [x] The legacy functions in bignum.c are calling the new functions wherever possible
  • [x] Extensive unit tests are added for all new functions

yanesca avatar Jul 04 '22 12:07 yanesca