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

Error codes in 4.0 #9619

Open
yanesca opened this issue Sep 23, 2024 · 1 comment · May be fixed by Mbed-TLS/TF-PSA-Crypto#167 or #9926
Open

Error codes in 4.0 #9619

yanesca opened this issue Sep 23, 2024 · 1 comment · May be fixed by Mbed-TLS/TF-PSA-Crypto#167 or #9926
Labels
api-break This issue/PR breaks the API and must wait for a new major version enhancement size-s Estimated task size: small (~2d)

Comments

@yanesca
Copy link
Contributor

yanesca commented Sep 23, 2024

We won't have the capacity to unify error codes in 4.0, but we would like to do the low cost high benefit actions here. The goal of this task is to get the low hanging fruits of error code unification (see #8501)

@yanesca yanesca added enhancement api-break This issue/PR breaks the API and must wait for a new major version size-l Estimated task size: large (2w+) labels Sep 23, 2024
@yanesca yanesca moved this to Design needed in Mbed TLS 4.0 planning Sep 23, 2024
@gilles-peskine-arm
Copy link
Contributor

gilles-peskine-arm commented Jan 24, 2025

After some discussion with @mpg (but written in my own words here and with a bit of further analysis), it appears that a useful milestone is to unify the error code space, so this is what I am defining as the goal of this issue. Fully unifying the error codes is out of scope and can be discussed further in #8501.

By unifying the error code space, I mean that any code that expects a PSA error code can now receive and propagate an mbedtls error code, and vice versa. Already, in Mbed TLS 3.x, this was partly the case, in that:

  • Both APIs define error codes as negative values between -32767 and -1, with 0 meaning success.
  • No PSA error code has the same numerical value as an mbedtls error code.

What was missing from the unification is that some code specifically expects a low-level error code, which must be a specific kind of mbedtls error code, not an arbitrary error code. This affects two places in the code:

  • Places where we add a high-level MBEDTLS_ERR_xxx to a low-level MBEDTLS_ERR_xxx (since Error codes: enforce add macro #9566, always using MBEDTLS_ERROR_ADD).
  • The error.h interface, which caters for added error codes.

So the goal here is to get rid of error code additions, and remove the now-obsolete bits of mbedtls/error.h. (Also any other place where we document added error codes, but I can't find any!)

The following are out of scope:

  • Unifying the status types. Legacy functions use int, whereas PSA functions use psa_status_t which is a synonym for int32_t. Even on platforms where these types have the same representation and range, they might be different formal types which can trigger compiler warnings when directly using a value of one type in a context that expects the other type. This can be resolved by adding a cast when needed.
  • Unifying error codes, for example changing all MBEDTLS_ERR_xxx_OUT_OF_MEMORY to PSA_ERROR_OUT_OF_MEMORY. This can happen gradually over time.
  • Actually having psa_xxx functions return MBEDTLS_ERR_xxx values and mbedtls_xxx functions return PSA_ERROR_xxx values, and getting rid of error space conversion functions. With this issue, we're making it possible, but not actually doing it.
  • A unified strerror. Filed as technical debt: Handle PSA error codes in mbedtls_strerror #9925
  • Simplifying error.c. Filed as technical debt: Simplify error.c without error addition #9927
  • Large documentation updates to stop making the distinction between PSA and mbedtls errors. I'm not sure any are needed: we don't use MBEDTLS_ERR_xxx or tls error code or legacy error code in any public documentation except for the 3.0 and PSA transition guides.

@gilles-peskine-arm gilles-peskine-arm added size-s Estimated task size: small (~2d) and removed size-l Estimated task size: large (2w+) labels Jan 24, 2025
@gilles-peskine-arm gilles-peskine-arm moved this from Design needed to Implementation in progress in Mbed TLS 4.0 planning Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-break This issue/PR breaks the API and must wait for a new major version enhancement size-s Estimated task size: small (~2d)
Projects
Status: Implementation in progress
2 participants