From a2cac3224da64632cf24a168df38c2d449f8caa9 Mon Sep 17 00:00:00 2001 From: Archana Date: Thu, 14 Apr 2022 09:31:28 +0530 Subject: [PATCH] Update and document mbedtls extensions Signed-off-by: Archana Signed-off-by: Asfandyar Orakzai --- docs/proposed/psa-driver-developer-guide.md | 6 ++++++ scripts/data_files/driver_jsons/driver_opaque_schema.json | 4 ++-- .../data_files/driver_jsons/driver_transparent_schema.json | 4 ++-- .../data_files/driver_jsons/mbedtls_test_opaque_driver.json | 6 +++--- .../driver_jsons/mbedtls_test_transparent_driver.json | 6 +++--- .../data_files/driver_templates/OS-template-opaque.jinja | 2 +- .../driver_templates/OS-template-transparent.jinja | 2 +- .../driver_templates/psa_crypto_driver_wrappers.c.jinja | 6 +++--- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/docs/proposed/psa-driver-developer-guide.md b/docs/proposed/psa-driver-developer-guide.md index 70cb9d397..b39f5599e 100644 --- a/docs/proposed/psa-driver-developer-guide.md +++ b/docs/proposed/psa-driver-developer-guide.md @@ -36,6 +36,12 @@ A driver therefore consists of: Mbed TLS calls driver entry points [as specified in the PSA Cryptography Driver Interface specification](psa-driver-interface.html#driver-entry-points) except as otherwise indicated in this section. +## Mbed TLS extensions + +The driver description can include Mbed TLS extensions (marked by the namespace "mbedtls"). Mbed TLS extensions are meant to extend/help integrating the driver into the library's infrastructure. +* `"mbedtls/h_condition"` (optional, string) can include complex preprocessor definitions to conditionally include header files for a given driver. +* `"mbedtls/c_condition"` (optional, string) can include complex preprocessor definitions to conditionally enable dispatch capabilities for a driver. + ## Building and testing your driver diff --git a/scripts/data_files/driver_jsons/driver_opaque_schema.json b/scripts/data_files/driver_jsons/driver_opaque_schema.json index 946977eb7..933eb0748 100644 --- a/scripts/data_files/driver_jsons/driver_opaque_schema.json +++ b/scripts/data_files/driver_jsons/driver_opaque_schema.json @@ -17,7 +17,7 @@ "type": ["integer","string"], "pattern": "^(0x|0X)?[a-fA-F0-9]+$" }, - "mbedtls/h_depend_on": { + "mbedtls/h_condition": { "type": "string" }, "headers": { @@ -36,7 +36,7 @@ "_comment": { "type": "string" }, - "mbedtls/c_depend_on": { + "mbedtls/c_condition": { "type": "string" }, "entry_points": { diff --git a/scripts/data_files/driver_jsons/driver_transparent_schema.json b/scripts/data_files/driver_jsons/driver_transparent_schema.json index 06fea5559..f5d91eb32 100644 --- a/scripts/data_files/driver_jsons/driver_transparent_schema.json +++ b/scripts/data_files/driver_jsons/driver_transparent_schema.json @@ -13,7 +13,7 @@ "type": "string", "const": ["transparent"] }, - "mbedtls/h_depend_on": { + "mbedtls/h_condition": { "type": "string" }, "headers": { @@ -32,7 +32,7 @@ "_comment": { "type": "string" }, - "mbedtls/c_depend_on": { + "mbedtls/c_condition": { "type": "string" }, "entry_points": { diff --git a/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json b/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json index c31f96490..41c74f2db 100644 --- a/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json +++ b/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json @@ -2,17 +2,17 @@ "prefix": "mbedtls_test", "type": "opaque", "location": "0x7fffff", - "mbedtls/h_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", + "mbedtls/h_condition": "defined(PSA_CRYPTO_DRIVER_TEST)", "headers": ["test/drivers/test_driver.h"], "capabilities": [ { "_comment": "The Mbed TLS opaque driver supports import key/export key/export_public key", - "mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", + "mbedtls/c_condition": "defined(PSA_CRYPTO_DRIVER_TEST)", "entry_points": ["import_key", "export_key", "export_public_key"] }, { "_comment": "The Mbed TLS opaque driver supports copy key/ get builtin key", - "mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", + "mbedtls/c_condition": "defined(PSA_CRYPTO_DRIVER_TEST)", "entry_points": ["copy_key", "get_builtin_key"], "names": {"copy_key":"mbedtls_test_opaque_copy_key", "get_builtin_key":"mbedtls_test_opaque_get_builtin_key"} } diff --git a/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json b/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json index db31ff408..9eb259f65 100644 --- a/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json +++ b/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json @@ -1,18 +1,18 @@ { "prefix": "mbedtls_test", "type": "transparent", - "mbedtls/h_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", + "mbedtls/h_condition": "defined(PSA_CRYPTO_DRIVER_TEST)", "headers": ["test/drivers/test_driver.h"], "capabilities": [ { "_comment": "The Mbed TLS transparent driver supports import key/export key", - "mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", + "mbedtls/c_condition": "defined(PSA_CRYPTO_DRIVER_TEST)", "entry_points": ["import_key", "export_key"], "fallback": true }, { "_comment": "The Mbed TLS transparent driver supports export_public key", - "mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", + "mbedtls/c_condition": "defined(PSA_CRYPTO_DRIVER_TEST)", "entry_points": ["export_public_key"], "fallback": true, "names": {"export_public_key":"mbedtls_test_transparent_export_public_key"} diff --git a/scripts/data_files/driver_templates/OS-template-opaque.jinja b/scripts/data_files/driver_templates/OS-template-opaque.jinja index 115e22c86..a25d1c371 100644 --- a/scripts/data_files/driver_templates/OS-template-opaque.jinja +++ b/scripts/data_files/driver_templates/OS-template-opaque.jinja @@ -7,7 +7,7 @@ Expected inputs: -#} {% for driver in drivers if driver.type == "opaque" -%} {% for capability in driver.capabilities if entry_point in capability.entry_points -%} -#if ({% if capability['mbedtls/c_depend_on'] is defined -%}{{ capability['mbedtls/c_depend_on'] }} {% else -%} {{ 1 }} {% endif %}) +#if ({% if capability['mbedtls/c_condition'] is defined -%}{{ capability['mbedtls/c_condition'] }} {% else -%} {{ 1 }} {% endif %}) {%- filter indent(width = nest_indent) %} case {{ driver.location }}: return( {{ entry_point_name(capability, entry_point, driver) }}({{entry_point_param(driver) | indent(20)}})); diff --git a/scripts/data_files/driver_templates/OS-template-transparent.jinja b/scripts/data_files/driver_templates/OS-template-transparent.jinja index 9ba115568..a6b7d6905 100644 --- a/scripts/data_files/driver_templates/OS-template-transparent.jinja +++ b/scripts/data_files/driver_templates/OS-template-transparent.jinja @@ -7,7 +7,7 @@ Expected inputs: -#} {% for driver in drivers if driver.type == "transparent" -%} {% for capability in driver.capabilities if entry_point in capability.entry_points -%} -#if ({% if capability['mbedtls/c_depend_on'] is defined -%}{{ capability['mbedtls/c_depend_on'] }} {% else -%} {{ 1 }} {% endif %}) +#if ({% if capability['mbedtls/c_condition'] is defined -%}{{ capability['mbedtls/c_condition'] }} {% else -%} {{ 1 }} {% endif %}) {%- filter indent(width = nest_indent) %} status = {{ entry_point_name(capability, entry_point, driver) }}({{entry_point_param(driver) | indent(20)}}); diff --git a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja index f38479df0..d5ae91103 100644 --- a/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja +++ b/scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja @@ -39,13 +39,13 @@ #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) {% for driver in drivers -%} /* Headers for {{driver.prefix}} {{driver.type}} driver */ -{% if driver['mbedtls/h_depend_on'] is defined -%} -#if {{ driver['mbedtls/h_depend_on'] }} +{% if driver['mbedtls/h_condition'] is defined -%} +#if {{ driver['mbedtls/h_condition'] }} {% endif -%} {% for header in driver.headers -%} #include "{{ header }}" {% endfor %} -{% if driver['mbedtls/h_depend_on'] is defined -%} +{% if driver['mbedtls/h_condition'] is defined -%} #endif {% endif -%} {% endfor %}