Issue: Bugs in PSA Driver Wrapper Jinja Templates (v1.1.0) #763

Open
opened 2026-04-16 03:07:01 -05:00 by fceeme · 0 comments
fceeme commented 2026-04-16 03:07:01 -05:00 (Migrated from github.com)

Description

There are two distinct bugs in the Jinja templates used by generate_driver_wrappers.py in the TF-PSA-Crypto 1.1.0 release. These issues cause generation failures or routing omissions when defining custom opaque drivers via JSON.

Bug 1: Typo in JSON Capability Names Evaluation (capability.name vs capability.names)

In both psa_crypto_driver_wrappers.h.jinja and psa_crypto_driver_wrappers_no_static.c.jinja, there is a typo in the entry_point_name macro. The template checks for capability.name is defined instead of capability.names is defined.

Since the official JSON schema specifies "names", this condition always evaluates to False. As a result, the wrapper script ignores custom entry point names defined in the JSON file and forces the fallback naming convention (prefix_type_entry_point, e.g., my_se_opaque_get_builtin_key instead of my_se_get_builtin_key), generating undefined reference compilation errors.

Affected Files:

  • core/scripts/mbedtls_framework/templates/psa_crypto_driver_wrappers.h.jinja
  • core/scripts/mbedtls_framework/templates/psa_crypto_driver_wrappers_no_static.c.jinja

Fix:

 /* BEGIN-Common Macro definitions */
 {% macro entry_point_name(capability, entry_point, driver) -%}
-    {% if capability.name is defined and entry_point in capability.names.keys() -%}
+    {% if capability.names is defined and entry_point in capability.names.keys() -%}
     {{ capability.names[entry_point]}}
     {% else -%}
     {{driver.prefix}}_{{driver.type}}_{{entry_point}}

Bug 2: Missing Opaque Driver Dispatch Route for sign_hash

In psa_crypto_driver_wrappers.h.jinja, the psa_driver_wrapper_sign_hash wrapper completely lacks the generation logic to route calls to opaque drivers. The block /* Add cases for opaque driver here */ is empty, except for test driver injections. Consequently, legitimate opaque driver sign_hash callbacks are never triggered.

Affected File:

  • core/scripts/mbedtls_framework/templates/psa_crypto_driver_wrappers.h.jinja

Fix:
Add the Jinja mapping logic under the opaque driver comment block inside psa_driver_wrapper_sign_hash():

         /* Add cases for opaque driver here */
+{% for driver in opaque_drivers %}
+{% if driver.sign_hash %}
+        case {{driver.id}}:
+            return( {{driver.prefix}}_sign_hash( attributes,
+                                                 key_buffer,
+                                                 key_buffer_size,
+                                                 alg,
+                                                 hash,
+                                                 hash_length,
+                                                 signature,
+                                                 signature_size,
+                                                 signature_length ) );
+{% endif %}
+{% endfor %}
 #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
 #if defined(PSA_CRYPTO_DRIVER_TEST)
         case PSA_CRYPTO_TEST_DRIVER_LOCATION:

Environment

  • TF-PSA-Crypto Version: 1.1.0
  • Component: psa_crypto_driver_wrappers generator script

Impact

  • Bug 1: Custom driver API endpoints with the "names" mapping fail to link during compilation because the wrapper ignores the JSON provided names.
  • Bug 2: Secure Elements and opaque drivers cannot execute psa_sign_hash(), breaking hash signature operations that rely on hardware-backed keys.
## Description There are two distinct bugs in the Jinja templates used by `generate_driver_wrappers.py` in the TF-PSA-Crypto 1.1.0 release. These issues cause generation failures or routing omissions when defining custom opaque drivers via JSON. ### Bug 1: Typo in JSON Capability Names Evaluation (`capability.name` vs `capability.names`) In both `psa_crypto_driver_wrappers.h.jinja` and `psa_crypto_driver_wrappers_no_static.c.jinja`, there is a typo in the `entry_point_name` macro. The template checks for `capability.name is defined` instead of `capability.names is defined`. Since the official JSON schema specifies `"names"`, this condition always evaluates to `False`. As a result, the wrapper script ignores custom entry point names defined in the JSON file and forces the fallback naming convention (`prefix_type_entry_point`, e.g., `my_se_opaque_get_builtin_key` instead of `my_se_get_builtin_key`), generating undefined reference compilation errors. **Affected Files:** - `core/scripts/mbedtls_framework/templates/psa_crypto_driver_wrappers.h.jinja` - `core/scripts/mbedtls_framework/templates/psa_crypto_driver_wrappers_no_static.c.jinja` **Fix:** ```diff /* BEGIN-Common Macro definitions */ {% macro entry_point_name(capability, entry_point, driver) -%} - {% if capability.name is defined and entry_point in capability.names.keys() -%} + {% if capability.names is defined and entry_point in capability.names.keys() -%} {{ capability.names[entry_point]}} {% else -%} {{driver.prefix}}_{{driver.type}}_{{entry_point}} ``` --- ### Bug 2: Missing Opaque Driver Dispatch Route for `sign_hash` In `psa_crypto_driver_wrappers.h.jinja`, the `psa_driver_wrapper_sign_hash` wrapper completely lacks the generation logic to route calls to opaque drivers. The block `/* Add cases for opaque driver here */` is empty, except for test driver injections. Consequently, legitimate opaque driver `sign_hash` callbacks are never triggered. **Affected File:** - `core/scripts/mbedtls_framework/templates/psa_crypto_driver_wrappers.h.jinja` **Fix:** Add the Jinja mapping logic under the opaque driver comment block inside `psa_driver_wrapper_sign_hash()`: ```diff /* Add cases for opaque driver here */ +{% for driver in opaque_drivers %} +{% if driver.sign_hash %} + case {{driver.id}}: + return( {{driver.prefix}}_sign_hash( attributes, + key_buffer, + key_buffer_size, + alg, + hash, + hash_length, + signature, + signature_size, + signature_length ) ); +{% endif %} +{% endfor %} #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_DRIVER_TEST) case PSA_CRYPTO_TEST_DRIVER_LOCATION: ``` ## Environment - **TF-PSA-Crypto Version:** 1.1.0 - **Component:** `psa_crypto_driver_wrappers` generator script ## Impact - **Bug 1:** Custom driver API endpoints with the `"names"` mapping fail to link during compilation because the wrapper ignores the JSON provided names. - **Bug 2:** Secure Elements and opaque drivers cannot execute `psa_sign_hash()`, breaking hash signature operations that rely on hardware-backed keys.
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#763
No description provided.