Mbed-TLS / mbedtls

An open source, portable, easy to use, readable and flexible TLS library, and reference implementation of the PSA Cryptography API. Releases are on a varying cadence, typically around 3 - 6 months between releases.
https://www.trustedfirmware.org/projects/mbed-tls/
Other
5.51k stars 2.6k forks source link

Revise handling and testing of module-internal optimization options #8870

Open gilles-peskine-arm opened 8 months ago

gilles-peskine-arm commented 8 months ago

We have several configuration options that tweak performance/memory/code-size/side-channel-resistance compromises of a specific part of the library, without affecting the functional behavior of the library. In particular, they do not affect the API or ABI. Traditionally these are not distinguished from other configuration options.

I think that in 4.0, we can simplify the handling and testing of options that don't affect the functional behavior, and that only affect a single code module:

https://github.com/Mbed-TLS/mbedtls/pull/8822 introduces some internal options to tweak optimizations in the SHA3 module. They're undocumented because we don't want to guarantee their stability in 3.6.x, but apart from the documentation aspect, I think they show a good way forward.

Documented options in 3.6 that could be in scope:

daverodgman commented 8 months ago

This is something I've talked to @tom-cosgrove-arm about in the past. I suggested a general purpose MBEDTLS_SIZE_PERF_TRADEOFF type option, to give the user a single top-level tuning knob that they set to a number from, say, 1 - 5, to choose prioritisation between size / perf. My thinking was that this could automatically set up all of the fine-grained options, if they are unset, but the user could possibly have the option to over-ride them (e.g. set to 1 or 0). Tom was less keen on this approach.

tom-cosgrove-arm commented 8 months ago

I don't like a general-purpose performance config option, since users might well want to optimise one area for code size and another for performance. I do like the style of options introduced #8822 - they are fine-grained and can be set on the command line either way without getting overridden (a "default on" option needs either edit to the config file to be able to turn it off)

gilles-peskine-arm commented 8 months ago

I also favor a general size/perf/security tradeoff (security: some users are not concerned about timing side channels, so ideally they shouldn't pay for our easily-bypassed countermeasures like blinding). But when an option is contained in a small block of code, its cost is much less.

gilles-peskine-arm commented 3 months ago

What needs to be finalized in terms of requirements for TF-PSA-Crypto 1.0: