Skip to content

Benchmark PSA API and TLS throughput #10775

Description

@mschulz-at-hilscher

Suggested enhancement

Currently, benchmark.c provides benchmarks for the legacy mbedtls APIs. As the default crypto API is becoming PSA based, also the PSA APIs shall be benchmarked and the results compared to the legacy mbedtls API's performance.

Additionally, there is currently no benchmark for actual end-to-end TLS throughput. It shall be benchmarked as well, not over the wire but simply using buffers to write to and read from.

In my benchmark experiments, I came to the following conclusions:

  1. AES CBC ciphersuites without ETM are damn slow due to the constant time HMAC used to counter Lucky13. However, they are so slow that especially embedded systems might be stuck in doing almost nothing else than calculating HMACs. Hence, it would be good to enforce ETM on AES CBC ciphersuites as only countermeasure for Lucky13 and not support non-ETM CBC ciphersuites anymore.
  2. NULL ciphersuites also use constant time HMACs, which makes them almost as slow as the AES CBC ciphersuites without ETM. However, I do not see why NULL ciphersuites would need constant time HMACs. Which attack is supposed to be countered by this countermeasure? If there is no valid reason to use constant time HMACs, use regular HMACs instead.
  3. Compared to the legacy mbedtls APIs, PSA APIs are highly inefficient. On every crypto operation, key management operations are performed, for example, to lock the key slot and get the key, verify that a certain operation is allowed to be done with a key, ... Especially for short TLS records, the overhead is significant and reduces the TLS throughput. If a key in a certain keyslot is chosen to be used as TLS session key, it should be sufficient to perform all those key management checks once, when the session is setup, but during frame processing, the implementation shall stupidly just perform the crypto operations with no further overhead.
  4. Using PSA APIs to perform AES GCM operations during SSL encryption and decryption, the psa_aead_encrypt function is called in mbedtls_ssl_encrypt_buf, for example. Compared to the legacy API, psa_aead_encrypt internally calls psa_aead_setup on every single frame. Which calls mbedtls_gcm_setkey that calculates H for GCM operations from the AES key. With the legacy mbedtls API, mbedtls_gcm_setkey was only called once per session and not once per frame. Hence, the use of PSA APIs significantly reduces the TLS throughput of AES GCM. Here, it would be better to cache H with the AES keys that are used for GCM operations, so that it does not need to be recalculated everytime.

Justification

Mbed TLS needs this because otherwise we cannot measure the significant performance decrease that some architectural design decisions introduce. Next step would be to create additional tickets to solve the inefficiencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions