Merge branch 'Mbed-TLS:development' into codegen_1.1
diff --git a/docs/proposed/psa-driver-developer-guide.md b/docs/proposed/psa-driver-developer-guide.md
index 70cb9d3..b39f559 100644
--- a/docs/proposed/psa-driver-developer-guide.md
+++ b/docs/proposed/psa-driver-developer-guide.md
@@ -36,6 +36,12 @@
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
<!-- TODO -->
diff --git a/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md b/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md
index 6172159..6144aad 100644
--- a/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md
+++ b/docs/proposed/psa-driver-wrappers-codegen-migration-guide.md
@@ -13,20 +13,28 @@
## Prerequisites
-Python3 and Jinja2 rev 2.10.1
+Python3, Jinja2 rev 2.10.1 and jsonschema rev 3.2.0
## Feature Version
-1.0
+1.1
### What's critical for a migrating user
The Driver Wrapper auto generation project is designed to use a python templating library ( Jinja2 ) to render templates based on drivers that are defined using a Driver description JSON file(s).
-While that is the larger goal, for version 1.0 here's what's changed
+While that is the larger goal, for version 1.1 here's what's changed
#### What's changed
(1) psa_crypto_driver_wrappers.c will from this point on be auto generated.
-(2) The auto generation is based on the template file at scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja.
-(3) So while all driver wrapper templating support is yet to come in, the library user will need to patch into the template file as needed, this could be read as replacing the template file with the current psa_crypto_driver_wrappers.c file maintained by the library user.
+(2) The auto generation is based on the template file at **scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja**.
+(3) The driver JSONS to be used for generating the psa_crypto_driver_wrappers.c file can be found at **scripts/data_files/driver_jsons/** as their default location, this path includes the schemas against which the driver schemas will be validated (driver_opaque_schema.json, driver_transparent_schema.json) and a driverlist.json which specifies the drivers to be considered and the order in which they want to be called into. The default location for driverlist.json and driver JSONS can be overloaded by passing an argument --json-dir while running the script generate_driver_wrappers.py.
+(4) While the complete driver wrapper templating support is yet to come in, if the library user sees a need to patch psa_crypto_driver_wrappers.c file, the user will need to patch into the template file as needed (psa_crypto_driver_wrappers.c.jinja).
+
+#### How to set your driver up
+
+Please refer to psa-driver-interface.md for information on how a driver schema can be written.
+One can also refer to the example test drivers/ JSON schemas under **scripts/data_files/driver_jsons/**.
+
+The JSON file 'driverlist.json' is meant to be edited by the user to reflect the drivers one wants to use on a device. The order in which the drivers are passed is also essential if/when there are multiple transparent drivers on a given system to retain the same order in the templating.
diff --git a/scripts/data_files/driver_jsons/driver_opaque_schema.json b/scripts/data_files/driver_jsons/driver_opaque_schema.json
new file mode 100644
index 0000000..933eb07
--- /dev/null
+++ b/scripts/data_files/driver_jsons/driver_opaque_schema.json
@@ -0,0 +1,71 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "properties": {
+ "_comment": {
+ "type": "string"
+ },
+ "prefix": {
+ "type": "string",
+ "pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
+ },
+ "type": {
+ "type": "string",
+ "const": ["opaque"]
+ },
+ "location": {
+ "type": ["integer","string"],
+ "pattern": "^(0x|0X)?[a-fA-F0-9]+$"
+ },
+ "mbedtls/h_condition": {
+ "type": "string"
+ },
+ "headers": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": []
+ },
+ "capabilities": {
+ "type": "array",
+ "items": [
+ {
+ "type": "object",
+ "properties": {
+ "_comment": {
+ "type": "string"
+ },
+ "mbedtls/c_condition": {
+ "type": "string"
+ },
+ "entry_points": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "names": {
+ "type": "object",
+ "patternProperties": {
+ "^[A-Z_a-z][0-9A-Z_a-z]*$": {
+ "type": "string",
+ "pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
+ }
+ }
+ }
+ },
+ "required": [
+ "entry_points"
+ ]
+ }
+ ]
+ }
+ },
+ "required": [
+ "prefix",
+ "type",
+ "location",
+ "capabilities"
+ ]
+}
diff --git a/scripts/data_files/driver_jsons/driver_transparent_schema.json b/scripts/data_files/driver_jsons/driver_transparent_schema.json
new file mode 100644
index 0000000..f5d91eb
--- /dev/null
+++ b/scripts/data_files/driver_jsons/driver_transparent_schema.json
@@ -0,0 +1,70 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "properties": {
+ "_comment": {
+ "type": "string"
+ },
+ "prefix": {
+ "type": "string",
+ "pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
+ },
+ "type": {
+ "type": "string",
+ "const": ["transparent"]
+ },
+ "mbedtls/h_condition": {
+ "type": "string"
+ },
+ "headers": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": []
+ },
+ "capabilities": {
+ "type": "array",
+ "items": [
+ {
+ "type": "object",
+ "properties": {
+ "_comment": {
+ "type": "string"
+ },
+ "mbedtls/c_condition": {
+ "type": "string"
+ },
+ "entry_points": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "names": {
+ "type": "object",
+ "patternProperties": {
+ "^[A-Z_a-z][0-9A-Z_a-z]*$": {
+ "type": "string",
+ "pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
+ }
+ }
+ },
+ "fallback": {
+ "type": "boolean",
+ "default": "false"
+ }
+ },
+ "required": [
+ "entry_points"
+ ]
+ }
+ ]
+ }
+ },
+ "required": [
+ "prefix",
+ "type",
+ "capabilities"
+ ]
+}
diff --git a/scripts/data_files/driver_jsons/driverlist.json b/scripts/data_files/driver_jsons/driverlist.json
new file mode 100644
index 0000000..50ad816
--- /dev/null
+++ b/scripts/data_files/driver_jsons/driverlist.json
@@ -0,0 +1 @@
+["mbedtls_test_opaque_driver.json","mbedtls_test_transparent_driver.json"]
diff --git a/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json b/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json
new file mode 100644
index 0000000..41c74f2
--- /dev/null
+++ b/scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json
@@ -0,0 +1,20 @@
+{
+ "prefix": "mbedtls_test",
+ "type": "opaque",
+ "location": "0x7fffff",
+ "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_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_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
new file mode 100644
index 0000000..9eb259f
--- /dev/null
+++ b/scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json
@@ -0,0 +1,22 @@
+{
+ "prefix": "mbedtls_test",
+ "type": "transparent",
+ "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_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_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
new file mode 100644
index 0000000..a25d1c3
--- /dev/null
+++ b/scripts/data_files/driver_templates/OS-template-opaque.jinja
@@ -0,0 +1,17 @@
+{# One Shot function's dispatch code for opaque drivers.
+Expected inputs:
+* drivers: the list of driver descriptions.
+* entry_point: the name of the entry point that this function dispatches to.
+* entry_point_param(driver): the parameters to pass to the entry point.
+* nest_indent: number of extra spaces to indent the code to.
+-#}
+{% 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_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)}}));
+{% endfilter -%}
+#endif
+{% endfor %}
+{% endfor %}
diff --git a/scripts/data_files/driver_templates/OS-template-transparent.jinja b/scripts/data_files/driver_templates/OS-template-transparent.jinja
new file mode 100644
index 0000000..a6b7d69
--- /dev/null
+++ b/scripts/data_files/driver_templates/OS-template-transparent.jinja
@@ -0,0 +1,19 @@
+{# One Shot function's dispatch code for transparent drivers.
+Expected inputs:
+* drivers: the list of driver descriptions.
+* entry_point: the name of the entry point that this function dispatches to.
+* entry_point_param(driver): the parameters to pass to the entry point.
+* nest_indent: number of extra spaces to indent the code to.
+-#}
+{% 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_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)}});
+
+if( status != PSA_ERROR_NOT_SUPPORTED )
+ return( status );
+{% endfilter -%}
+#endif
+{% endfor %}
+{% endfor %}
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 a5ae6a2..d5ae911 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
@@ -1,7 +1,7 @@
/*
* Functions to delegate cryptographic operations to an available
* and appropriate accelerator.
- * Warning: This file will be auto-generated in the future.
+ * Warning: This file is now auto-generated.
*/
/* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
@@ -19,6 +19,8 @@
* limitations under the License.
*/
+
+/* BEGIN-common headers */
#include "common.h"
#include "psa_crypto_aead.h"
#include "psa_crypto_cipher.h"
@@ -29,34 +31,46 @@
#include "psa_crypto_rsa.h"
#include "mbedtls/platform.h"
+/* END-common headers */
#if defined(MBEDTLS_PSA_CRYPTO_C)
+/* BEGIN-driver headers */
#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS)
-
-/* Include test driver definition when running tests */
-#if defined(PSA_CRYPTO_DRIVER_TEST)
-#ifndef PSA_CRYPTO_DRIVER_PRESENT
-#define PSA_CRYPTO_DRIVER_PRESENT
+{% for driver in drivers -%}
+/* Headers for {{driver.prefix}} {{driver.type}} driver */
+{% 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_condition'] is defined -%}
#endif
-#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
-#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
-#endif
-#include "test/drivers/test_driver.h"
-#endif /* PSA_CRYPTO_DRIVER_TEST */
-
-/* Repeat above block for each JSON-declared driver during autogeneration */
+{% endif -%}
+{% endfor %}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */
+/* END-driver headers */
/* Auto-generated values depending on which drivers are registered.
* ID 0 is reserved for unallocated operations.
* ID 1 is reserved for the Mbed TLS software driver. */
+/* BEGIN-driver id definition */
#define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1)
+{% for driver in drivers -%}
+#define {{(driver.prefix + "_" + driver.type + "_driver_id").upper()}} ({{ loop.index + 1 }})
+{% endfor %}
+/* END-driver id */
-#if defined(PSA_CRYPTO_DRIVER_TEST)
-#define PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID (2)
-#define PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID (3)
-#endif /* PSA_CRYPTO_DRIVER_TEST */
+/* BEGIN-Common Macro definitions */
+{% macro entry_point_name(capability, entry_point, driver) -%}
+ {% if capability.name is defined and entry_point in capability.names.keys() -%}
+ {{ capability.names[entry_point]}}
+ {% else -%}
+ {{driver.prefix}}_{{driver.type}}_{{entry_point}}
+ {% endif -%}
+{% endmacro %}
+/* END-Common Macro definitions */
/* Support the 'old' SE interface when asked to */
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
@@ -592,6 +606,16 @@
size_t *key_buffer_length,
size_t *bits )
{
+{% with entry_point = "import_key" -%}
+{% macro entry_point_param(driver) -%}
+attributes,
+data,
+data_length,
+key_buffer,
+key_buffer_size,
+key_buffer_length,
+bits
+{% endmacro %}
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
psa_get_key_lifetime( attributes ) );
@@ -631,17 +655,11 @@
/* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-#if defined(PSA_CRYPTO_DRIVER_TEST)
- status = mbedtls_test_transparent_import_key(
- attributes,
- data, data_length,
- key_buffer, key_buffer_size,
- key_buffer_length, bits );
- /* Declared with fallback == true */
- if( status != PSA_ERROR_NOT_SUPPORTED )
- return( status );
-#endif /* PSA_CRYPTO_DRIVER_TEST */
+{% with nest_indent=12 %}
+{% include "OS-template-transparent.jinja" -%}
+{% endwith -%}
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
+
/* Fell through, meaning no accelerator supports this operation */
return( psa_import_key_into_slot( attributes,
data, data_length,
@@ -649,20 +667,15 @@
key_buffer_length, bits ) );
/* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TEST_DRIVER_LOCATION:
- return( mbedtls_test_opaque_import_key(
- attributes,
- data, data_length,
- key_buffer, key_buffer_size,
- key_buffer_length, bits ) );
-#endif /* PSA_CRYPTO_DRIVER_TEST */
+{% with nest_indent=8 %}
+{% include "OS-template-opaque.jinja" -%}
+{% endwith -%}
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default:
(void)status;
return( PSA_ERROR_INVALID_ARGUMENT );
}
-
+{% endwith %}
}
psa_status_t psa_driver_wrapper_export_key(
@@ -671,6 +684,15 @@
uint8_t *data, size_t data_size, size_t *data_length )
{
+{% with entry_point = "export_key" -%}
+{% macro entry_point_param(driver) -%}
+attributes,
+key_buffer,
+key_buffer_size,
+data,
+data_size,
+data_length
+{% endmacro %}
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
psa_get_key_lifetime( attributes ) );
@@ -707,20 +729,15 @@
/* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TEST_DRIVER_LOCATION:
- return( mbedtls_test_opaque_export_key( attributes,
- key_buffer,
- key_buffer_size,
- data,
- data_size,
- data_length ) );
-#endif /* PSA_CRYPTO_DRIVER_TEST */
+{% with nest_indent=8 %}
+{% include "OS-template-opaque.jinja" -%}
+{% endwith -%}
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default:
/* Key is declared with a lifetime not known to us */
return( status );
}
+{% endwith %}
}
psa_status_t psa_driver_wrapper_export_public_key(
@@ -729,6 +746,15 @@
uint8_t *data, size_t data_size, size_t *data_length )
{
+{% with entry_point = "export_public_key" -%}
+{% macro entry_point_param(driver) -%}
+attributes,
+key_buffer,
+key_buffer_size,
+data,
+data_size,
+data_length
+{% endmacro %}
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
psa_get_key_lifetime( attributes ) );
@@ -759,18 +785,9 @@
/* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-#if defined(PSA_CRYPTO_DRIVER_TEST)
- status = mbedtls_test_transparent_export_public_key(
- attributes,
- key_buffer,
- key_buffer_size,
- data,
- data_size,
- data_length );
- /* Declared with fallback == true */
- if( status != PSA_ERROR_NOT_SUPPORTED )
- return( status );
-#endif /* PSA_CRYPTO_DRIVER_TEST */
+{% with nest_indent=12 %}
+{% include "OS-template-transparent.jinja" -%}
+{% endwith -%}
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
/* Fell through, meaning no accelerator supports this operation */
return( psa_export_public_key_internal( attributes,
@@ -782,20 +799,15 @@
/* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TEST_DRIVER_LOCATION:
- return( mbedtls_test_opaque_export_public_key( attributes,
- key_buffer,
- key_buffer_size,
- data,
- data_size,
- data_length ) );
-#endif /* PSA_CRYPTO_DRIVER_TEST */
+{% with nest_indent=8 %}
+{% include "OS-template-opaque.jinja" -%}
+{% endwith -%}
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default:
/* Key is declared with a lifetime not known to us */
return( status );
}
+{% endwith %}
}
psa_status_t psa_driver_wrapper_get_builtin_key(
@@ -803,15 +815,21 @@
psa_key_attributes_t *attributes,
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
{
+{% with entry_point = "get_builtin_key" -%}
+{% macro entry_point_param(driver) -%}
+slot_number,
+attributes,
+key_buffer,
+key_buffer_size,
+key_buffer_length
+{% endmacro %}
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
switch( location )
{
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TEST_DRIVER_LOCATION:
- return( mbedtls_test_opaque_get_builtin_key(
- slot_number,
- attributes,
- key_buffer, key_buffer_size, key_buffer_length ) );
+{% with nest_indent=8 %}
+{% include "OS-template-opaque.jinja" -%}
+{% endwith -%}
#endif /* PSA_CRYPTO_DRIVER_TEST */
default:
(void) slot_number;
@@ -820,6 +838,7 @@
(void) key_buffer_length;
return( PSA_ERROR_DOES_NOT_EXIST );
}
+{% endwith %}
}
psa_status_t psa_driver_wrapper_copy_key(
@@ -828,6 +847,15 @@
uint8_t *target_key_buffer, size_t target_key_buffer_size,
size_t *target_key_buffer_length )
{
+{% with entry_point = "copy_key" -%}
+{% macro entry_point_param(driver) -%}
+attributes,
+source_key,
+source_key_length,
+target_key_buffer,
+target_key_buffer_size,
+target_key_buffer_length
+{% endmacro %}
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_key_location_t location =
PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
@@ -846,14 +874,9 @@
switch( location )
{
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
-#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TEST_DRIVER_LOCATION:
- return( mbedtls_test_opaque_copy_key( attributes, source_key,
- source_key_length,
- target_key_buffer,
- target_key_buffer_size,
- target_key_buffer_length) );
-#endif /* PSA_CRYPTO_DRIVER_TEST */
+{% with nest_indent=8 %}
+{% include "OS-template-opaque.jinja" -%}
+{% endwith -%}
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default:
(void)source_key;
@@ -864,6 +887,7 @@
status = PSA_ERROR_INVALID_ARGUMENT;
}
return( status );
+{% endwith %}
}
/*
@@ -1068,7 +1092,7 @@
alg );
/* Declared with fallback == true */
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
if( status != PSA_ERROR_NOT_SUPPORTED )
return( status );
@@ -1100,7 +1124,7 @@
alg );
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
return( status );
#endif /* PSA_CRYPTO_DRIVER_TEST */
@@ -1141,7 +1165,7 @@
alg );
/* Declared with fallback == true */
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
if( status != PSA_ERROR_NOT_SUPPORTED )
return( status );
@@ -1172,7 +1196,7 @@
alg );
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
return( status );
#endif /* PSA_CRYPTO_DRIVER_TEST */
@@ -1204,12 +1228,12 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_cipher_set_iv(
&operation->ctx.transparent_test_driver_ctx,
iv, iv_length ) );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
return( mbedtls_test_opaque_cipher_set_iv(
&operation->ctx.opaque_test_driver_ctx,
iv, iv_length ) );
@@ -1245,13 +1269,13 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_cipher_update(
&operation->ctx.transparent_test_driver_ctx,
input, input_length,
output, output_size, output_length ) );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
return( mbedtls_test_opaque_cipher_update(
&operation->ctx.opaque_test_driver_ctx,
input, input_length,
@@ -1287,12 +1311,12 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_cipher_finish(
&operation->ctx.transparent_test_driver_ctx,
output, output_size, output_length ) );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
return( mbedtls_test_opaque_cipher_finish(
&operation->ctx.opaque_test_driver_ctx,
output, output_size, output_length ) );
@@ -1321,7 +1345,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
status = mbedtls_test_transparent_cipher_abort(
&operation->ctx.transparent_test_driver_ctx );
mbedtls_platform_zeroize(
@@ -1329,7 +1353,7 @@
sizeof( operation->ctx.transparent_test_driver_ctx ) );
return( status );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
status = mbedtls_test_opaque_cipher_abort(
&operation->ctx.opaque_test_driver_ctx );
mbedtls_platform_zeroize(
@@ -1394,7 +1418,7 @@
status = mbedtls_test_transparent_hash_setup(
&operation->ctx.test_driver_ctx, alg );
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
if( status != PSA_ERROR_NOT_SUPPORTED )
return( status );
@@ -1429,8 +1453,8 @@
&target_operation->ctx.mbedtls_ctx ) );
#endif
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
- target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
+ target_operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
return( mbedtls_test_transparent_hash_clone(
&source_operation->ctx.test_driver_ctx,
&target_operation->ctx.test_driver_ctx ) );
@@ -1454,7 +1478,7 @@
input, input_length ) );
#endif
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_hash_update(
&operation->ctx.test_driver_ctx,
input, input_length ) );
@@ -1480,7 +1504,7 @@
hash, hash_size, hash_length ) );
#endif
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_hash_finish(
&operation->ctx.test_driver_ctx,
hash, hash_size, hash_length ) );
@@ -1503,7 +1527,7 @@
return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) );
#endif
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_hash_abort(
&operation->ctx.test_driver_ctx ) );
#endif
@@ -1650,7 +1674,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
status = mbedtls_test_transparent_aead_encrypt_setup(
&operation->ctx.transparent_test_driver_ctx,
attributes, key_buffer, key_buffer_size,
@@ -1698,7 +1722,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
status = mbedtls_test_transparent_aead_decrypt_setup(
&operation->ctx.transparent_test_driver_ctx,
attributes,
@@ -1747,7 +1771,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_aead_set_nonce(
&operation->ctx.transparent_test_driver_ctx,
nonce, nonce_length ) );
@@ -1781,7 +1805,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_aead_set_lengths(
&operation->ctx.transparent_test_driver_ctx,
ad_length, plaintext_length ) );
@@ -1815,7 +1839,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_aead_update_ad(
&operation->ctx.transparent_test_driver_ctx,
input, input_length ) );
@@ -1853,7 +1877,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_aead_update(
&operation->ctx.transparent_test_driver_ctx,
input, input_length, output, output_size,
@@ -1897,7 +1921,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_aead_finish(
&operation->ctx.transparent_test_driver_ctx,
ciphertext, ciphertext_size,
@@ -1961,7 +1985,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_aead_verify(
&operation->ctx.transparent_test_driver_ctx,
plaintext, plaintext_size,
@@ -1995,7 +2019,7 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_aead_abort(
&operation->ctx.transparent_test_driver_ctx ) );
@@ -2104,7 +2128,7 @@
alg );
/* Declared with fallback == true */
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
if( status != PSA_ERROR_NOT_SUPPORTED )
return( status );
@@ -2135,7 +2159,7 @@
alg );
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
return( status );
#endif /* PSA_CRYPTO_DRIVER_TEST */
@@ -2176,7 +2200,7 @@
alg );
/* Declared with fallback == true */
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
if( status != PSA_ERROR_NOT_SUPPORTED )
return( status );
@@ -2207,7 +2231,7 @@
alg );
if( status == PSA_SUCCESS )
- operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
+ operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
return( status );
#endif /* PSA_CRYPTO_DRIVER_TEST */
@@ -2238,12 +2262,12 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_mac_update(
&operation->ctx.transparent_test_driver_ctx,
input, input_length ) );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
return( mbedtls_test_opaque_mac_update(
&operation->ctx.opaque_test_driver_ctx,
input, input_length ) );
@@ -2272,12 +2296,12 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_mac_sign_finish(
&operation->ctx.transparent_test_driver_ctx,
mac, mac_size, mac_length ) );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
return( mbedtls_test_opaque_mac_sign_finish(
&operation->ctx.opaque_test_driver_ctx,
mac, mac_size, mac_length ) );
@@ -2306,12 +2330,12 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_mac_verify_finish(
&operation->ctx.transparent_test_driver_ctx,
mac, mac_length ) );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
return( mbedtls_test_opaque_mac_verify_finish(
&operation->ctx.opaque_test_driver_ctx,
mac, mac_length ) );
@@ -2336,10 +2360,10 @@
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
- case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
return( mbedtls_test_transparent_mac_abort(
&operation->ctx.transparent_test_driver_ctx ) );
- case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
+ case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
return( mbedtls_test_opaque_mac_abort(
&operation->ctx.opaque_test_driver_ctx ) );
#endif /* PSA_CRYPTO_DRIVER_TEST */
diff --git a/scripts/driver.requirements.txt b/scripts/driver.requirements.txt
index 5364d8e..9e26b3c 100644
--- a/scripts/driver.requirements.txt
+++ b/scripts/driver.requirements.txt
@@ -15,4 +15,5 @@
Jinja2 >= 2.10.3; python_version >= '3.10'
# Jinja2 >=2.10, <3.0 needs a separate package for type annotations
types-Jinja2
-
+jsonschema >= 3.2.0
+types-jsonschema
diff --git a/scripts/generate_driver_wrappers.py b/scripts/generate_driver_wrappers.py
index 71b881e..f43d4e5 100755
--- a/scripts/generate_driver_wrappers.py
+++ b/scripts/generate_driver_wrappers.py
@@ -22,54 +22,172 @@
import sys
import os
+import json
+from typing import Tuple, NewType, Dict, Any
import argparse
+import jsonschema
import jinja2
from mbedtls_dev import build_tree
-def render(template_path: str) -> str:
+JSONSchema = NewType('JSONSchema', object)
+# The Driver is an Object, but practically it's indexable and can called a dictionary to
+# keep MyPy happy till MyPy comes with a more composite type for JsonObjects.
+Driver = NewType('Driver', dict)
+
+
+class JsonValidationException(Exception):
+ def __init__(self, message="Json Validation Failed"):
+ self.message = message
+ super().__init__(self.message)
+
+
+def render(template_path: str, driver_jsoncontext: list) -> str:
"""
- Render template from the input file.
+ Render template from the input file and driver JSON.
"""
environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(template_path)),
keep_trailing_newline=True)
template = environment.get_template(os.path.basename(template_path))
- return template.render()
+ return template.render(drivers=driver_jsoncontext)
-def generate_driver_wrapper_file(mbedtls_root: str, output_dir: str) -> None:
+
+def generate_driver_wrapper_file(template_dir: str, \
+ output_dir: str, driver_jsoncontext: list) -> None:
"""
Generate the file psa_crypto_driver_wrapper.c.
"""
driver_wrapper_template_filename = \
- os.path.join(mbedtls_root, \
- "scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja")
+ os.path.join(template_dir, "psa_crypto_driver_wrappers.c.jinja")
- result = render(driver_wrapper_template_filename)
+ result = render(driver_wrapper_template_filename, driver_jsoncontext)
with open(os.path.join(output_dir, "psa_crypto_driver_wrappers.c"), 'w') as out_file:
out_file.write(result)
+
+def validate_json(driverjson_data: Driver, driverschema_list: dict) -> bool:
+ """
+ Validate the Driver JSON against an appropriate schema
+ the schema passed could be that matching an opaque/ transparent driver.
+ """
+ driver_type = driverjson_data["type"]
+ driver_prefix = driverjson_data["prefix"]
+ try:
+ _schema = driverschema_list[driver_type]
+ jsonschema.validate(instance=driverjson_data, schema=_schema)
+
+ except KeyError as err:
+ # This could happen if the driverjson_data.type does not exist in the passed in schema list
+ # schemas = {'transparent': transparent_driver_schema, 'opaque': opaque_driver_schema}
+ # Print onto stdout and stderr.
+ print("Unknown Driver type " + driver_type +
+ " for driver " + driver_prefix, str(err))
+ print("Unknown Driver type " + driver_type +
+ " for driver " + driver_prefix, str(err), file=sys.stderr)
+ return False
+
+ except jsonschema.exceptions.ValidationError as err:
+ # Print onto stdout and stderr.
+ print("Error: Failed to validate data file: {} using schema: {}."
+ "\n Exception Message: \"{}\""
+ " ".format(driverjson_data, _schema, str(err)))
+ print("Error: Failed to validate data file: {} using schema: {}."
+ "\n Exception Message: \"{}\""
+ " ".format(driverjson_data, _schema, str(err)), file=sys.stderr)
+ return False
+
+ return True
+
+
+def load_driver(schemas: Dict[str, Any], driver_file: str) -> Any:
+ with open(driver_file, 'r') as f:
+ json_data = json.load(f)
+ if not validate_json(json_data, schemas):
+ raise JsonValidationException()
+ return json_data
+
+
+def read_driver_descriptions(mbedtls_root: str, json_directory: str, \
+ jsondriver_list: str) -> Tuple[bool, list]:
+ """
+ Merge driver JSON files into a single ordered JSON after validation.
+ """
+ result = []
+ with open(os.path.join(mbedtls_root,
+ 'scripts',
+ 'data_files',
+ 'driver_jsons',
+ 'driver_transparent_schema.json'), 'r') as file:
+ transparent_driver_schema = json.load(file)
+ with open(os.path.join(mbedtls_root,
+ 'scripts',
+ 'data_files',
+ 'driver_jsons',
+ 'driver_opaque_schema.json'), 'r') as file:
+ opaque_driver_schema = json.load(file)
+
+ driver_schema = {'transparent': transparent_driver_schema,
+ 'opaque': opaque_driver_schema}
+ with open(os.path.join(json_directory, jsondriver_list), 'r') as driverlistfile:
+ driver_list = json.load(driverlistfile)
+
+ try:
+ result = [load_driver(schemas=driver_schema,
+ driver_file=os.path.join(json_directory, driver_file_name))
+ for driver_file_name in driver_list]
+ except JsonValidationException as _:
+ return False, []
+
+ return True, result
+
+
def main() -> int:
"""
Main with command line arguments.
+ returns 1 when read_driver_descriptions returns False
"""
def_arg_mbedtls_root = build_tree.guess_mbedtls_root()
- def_arg_output_dir = os.path.join(def_arg_mbedtls_root, 'library')
parser = argparse.ArgumentParser()
- parser.add_argument('--mbedtls-root', nargs='?', default=def_arg_mbedtls_root,
+ parser.add_argument('--mbedtls-root', default=def_arg_mbedtls_root,
help='root directory of mbedtls source code')
+ parser.add_argument('--template-dir',
+ help='directory holding the driver templates')
+ parser.add_argument('--json-dir',
+ help='directory holding the driver JSONs')
parser.add_argument('output_directory', nargs='?',
- default=def_arg_output_dir, help='output file\'s location')
+ help='output file\'s location')
args = parser.parse_args()
mbedtls_root = os.path.abspath(args.mbedtls_root)
- output_directory = args.output_directory
+ if args.template_dir is None:
+ args.template_dir = os.path.join(mbedtls_root,
+ 'scripts',
+ 'data_files',
+ 'driver_templates')
+ if args.json_dir is None:
+ args.json_dir = os.path.join(mbedtls_root,
+ 'scripts',
+ 'data_files',
+ 'driver_jsons')
+ if args.output_directory is None:
+ args.output_directory = os.path.join(mbedtls_root, 'library')
- generate_driver_wrapper_file(mbedtls_root, output_directory)
+ output_directory = args.output_directory
+ template_directory = args.template_dir
+ json_directory = args.json_dir
+
+ # Read and validate list of driver jsons from driverlist.json
+ ret, merged_driver_json = read_driver_descriptions(mbedtls_root, json_directory,
+ 'driverlist.json')
+ if ret is False:
+ return 1
+ generate_driver_wrapper_file(template_directory, output_directory, merged_driver_json)
return 0
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/tests/docker/bionic/Dockerfile b/tests/docker/bionic/Dockerfile
index 28d33b7..4b5739c 100644
--- a/tests/docker/bionic/Dockerfile
+++ b/tests/docker/bionic/Dockerfile
@@ -60,9 +60,15 @@
pkg-config \
&& rm -rf /var/lib/apt/lists/*
-# Jinja2 is required for driver dispatch code generation.
+# The following packages are required for validating Python files.
+# The version of Pylint is set to 2.4.4 to match CI.
RUN python3 -m pip install \
- jinja2==2.10.1 types-jinja2
+ packaging mypy pylint==2.4.4
+
+# Jinja2 and jsonschema is required for driver dispatch code generation.
+RUN python3 -m pip install \
+ jinja2==2.10.1 types-jinja2 \
+ jsonschema==3.2.0 types-jsonschema
# Build a static, legacy openssl from sources with sslv3 enabled
# Based on https://gist.github.com/bmaupin/8caca3a1e8c3c5686141 (build-openssl.sh)
diff --git a/tests/include/test/drivers/test_driver.h b/tests/include/test/drivers/test_driver.h
index 098b21a..b3c29e4 100644
--- a/tests/include/test/drivers/test_driver.h
+++ b/tests/include/test/drivers/test_driver.h
@@ -20,6 +20,14 @@
#ifndef PSA_CRYPTO_TEST_DRIVER_H
#define PSA_CRYPTO_TEST_DRIVER_H
+#if defined(PSA_CRYPTO_DRIVER_TEST)
+#ifndef PSA_CRYPTO_DRIVER_PRESENT
+#define PSA_CRYPTO_DRIVER_PRESENT
+#endif
+#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
+#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
+#endif
+
#define PSA_CRYPTO_TEST_DRIVER_LOCATION 0x7fffff
#include "test/drivers/aead.h"
@@ -30,4 +38,5 @@
#include "test/drivers/signature.h"
#include "test/drivers/asymmetric_encryption.h"
+#endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_TEST_DRIVER_H */
diff --git a/tests/scripts/check_names.py b/tests/scripts/check_names.py
index e204487..e94608f 100755
--- a/tests/scripts/check_names.py
+++ b/tests/scripts/check_names.py
@@ -283,7 +283,7 @@
"library/*.c",
"3rdparty/everest/library/everest.c",
"3rdparty/everest/library/x25519.c"
- ])
+ ], ["library/psa_crypto_driver_wrappers.c"])
symbols = self.parse_symbols()
# Remove identifier macros like mbedtls_printf or mbedtls_calloc