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.57k stars 2.61k forks source link

Simplify platform interfaces #8108

Open gilles-peskine-arm opened 1 year ago

gilles-peskine-arm commented 1 year ago

The portability layer in Mbed TLS is complex. The goal of this issue is to simplify it. This will require a major redesign that can only be done in a major release (I don't think it's possible to get anywhere without API changes).

As of Mbed TLS 3.x, the portability layer consists of:

I think cryptographic engines and platform configuration are different beasts, and we already have a plan for cryptographic engines, which is PSA drivers. So this issue is about the platform interfaces that aren't related to cryptography.

Ideally, it should be possible to integrate Mbed TLS into an embedded OS by providing a custom my_platform.h and my_platform.o, which implement all the features Mbed TLS needs that are related to the OS: malloc, printf, sockets, filesystem, etc. We would provide versions of these files for Unix-like systems and for Windows, and embedded OS/BSP maintainers can write versions for their platform.

gilles-peskine-arm commented 1 year ago

Example of why we need this: https://github.com/Mbed-TLS/mbedtls/issues/8490 — User confusion and errors in the documentation because MBEDTLS_PLATFORM_ZEROIZE_ALT doesn't behave like the others — most MBEDTLS_PLATFORM_xxx_ALT macros are the name of a function to use instead of the default, but MBEDTLS_PLATFORM_ZEROIZE_ALT is instead a boolean that says not to link the default function, so that users have to provide their own with the standard name.

mschulz-at-hilscher commented 4 months ago

Would it be possible to call the C11 Annex K bounds checking interface of standard libary functions as required by https://wiki.sei.cmu.edu/confluence/display/c/STR07-C.+Use+the+bounds-checking+interfaces+for+string+manipulation?

gilles-peskine-arm commented 4 months ago

@mschulz-at-hilscher Most platforms don't have Annex K functions, so they aren't an option for us.

In any case, we prefer to rely on static analysis over runtime detection: it's safer (if we do static analysis right, which could definitely be improved), and less code size.