Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bignum inline assembly replacement more flexible #5366

Open
hanno-becker opened this issue Dec 28, 2021 · 0 comments
Open

Make bignum inline assembly replacement more flexible #5366

hanno-becker opened this issue Dec 28, 2021 · 0 comments

Comments

@hanno-becker
Copy link

hanno-becker commented Dec 28, 2021

Suggested enhancement

Currently, we only allow inline assembly for single long-multiply-accumulate steps within scalar*bignum long multiplications (MULADDC_CORE). There are at least two ways this should be made more flexible to allow for higher performance bignum implementations:

  • (Simple) Allow the optimization of multiple consecutive occurrences of MULADDC_CORE, as discussed in Improve inline assembly for Cortex-M + DSP #5360. Ultimately, allow replacing the entire mpi_mul_hlp() routine.
  • (More complex) Allow a larger step/window size during Montgomery multiplication: Instead of iterating through inputs in steps of mbedtls_mpi_uint, allow iteration in steps of mbedtls_mpi_uint[N]. This will allow to significantly reduce the number of memory operations used multiplications, esp. on the A-profile where we have 31 GPRs of which the current MULADDC_CORE uses only very few.

At first I wondered whether the second point should be implemented by changing the typedef's for mbedtls_mpi_uint, but that's an API break since mbedtls_mpi_uint is part of mbedtls_mpi_mul_int(). It seems better to directly modify the granularity of the two loops around mpi_mul_hlp() we have in the code: Firstly, mbedtls_mpi_mul_mpi() (https://github.com/ARMmbed/mbedtls/blob/development/library/bignum.c#L1487-1488), and secondly, mpi_montmul() (https://github.com/ARMmbed/mbedtls/blob/development/library/bignum.c#L1911-L1935).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants