Big struct passed by value in mbedtls_pk_ec() #423

Open
opened 2025-08-18 11:56:34 -05:00 by davidhorstmann-arm · 2 comments
davidhorstmann-arm commented 2025-08-18 11:56:34 -05:00 (Migrated from github.com)

The function mbedtls_pk_ec() seems to unnecessarily pass a large struct (mbedtls_pk_context) by value, resulting in a lot of copying. It's likely this was needed to retain backwards-compatibility but since this function will be made internal-only or perhaps deleted in 4.0, it should be possible to fix this.

Found by Coverity.

The function `mbedtls_pk_ec()` seems to unnecessarily pass a large struct (`mbedtls_pk_context`) by value, resulting in a lot of copying. It's likely this was needed to retain backwards-compatibility but since this function will be made internal-only or perhaps deleted in 4.0, it should be possible to fix this. Found by Coverity.
irwir commented 2025-08-23 11:53:29 -05:00 (Migrated from github.com)

The story began in https://github.com/Mbed-TLS/mbedtls/pull/1766 and maybe ended in https://github.com/Mbed-TLS/mbedtls/issues/7616
It was presumed mbedtls_pk_ec() to be gone in the next major version.

The story began in https://github.com/Mbed-TLS/mbedtls/pull/1766 and maybe ended in https://github.com/Mbed-TLS/mbedtls/issues/7616 It was presumed `mbedtls_pk_ec()` to be gone in the next major version.
gilles-peskine-arm commented 2025-08-25 06:14:47 -05:00 (Migrated from github.com)

Historically, mbedtls_pk_context was a small struct (just two pointers). It only started growing in some driver-only configurations in Mbed TLS 3.x.

Starting from TF-PSA-Crypto 1.0, this function will be private. It's slated for removal, if not in 1.0, then in an early 1.x. So there's no point in trying to optimize it.

In any case, unless compiling with optimizations disabled, I'd expect the compiler to inline it and get rid of the copy.

Historically, `mbedtls_pk_context` was a small struct (just two pointers). It only started growing in some driver-only configurations in Mbed TLS 3.x. Starting from TF-PSA-Crypto 1.0, this function will be private. It's slated for removal, if not in 1.0, then in an early 1.x. So there's no point in trying to optimize it. In any case, unless compiling with optimizations disabled, I'd expect the compiler to inline it and get rid of the copy.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto#423
No description provided.