Schema and script improvements

Signed-off-by: Archana <archana.madhavan@silabs.com>
Signed-off-by: Asfandyar Orakzai <asfandyar.orakzai@silabs.com>
This commit is contained in:
Archana 2022-04-11 10:12:08 +05:30 committed by Asfandyar Orakzai
parent 01aa39e3ff
commit 22c7827876
6 changed files with 30 additions and 55 deletions

View File

@ -25,8 +25,7 @@
"items": { "items": {
"type": "string" "type": "string"
}, },
"minItems": 1, "default": []
"uniqueItems": true
}, },
"capabilities": { "capabilities": {
"type": "array", "type": "array",
@ -43,23 +42,17 @@
"entry_points": { "entry_points": {
"type": "array", "type": "array",
"items": { "items": {
"type": "string", "type": "string"
"enum": ["import_key", "export_key", "export_public_key", }
"copy_key", "get_builtin_key"]
},
"minItems": 1,
"uniqueItems": true
}, },
"name": { "names": {
"type": "object", "type": "object",
"patternProperties": { "patternProperties": {
"^[A-Z_a-z][0-9A-Z_a-z]*$": { "^[A-Z_a-z][0-9A-Z_a-z]*$": {
"type": "string", "type": "string",
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$" "pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
} }
}, }
"minItems": 1,
"uniqueItems": true
} }
}, },
"required": [ "required": [

View File

@ -21,8 +21,7 @@
"items": { "items": {
"type": "string" "type": "string"
}, },
"minItems": 1, "default": []
"uniqueItems": true
}, },
"capabilities": { "capabilities": {
"type": "array", "type": "array",
@ -39,23 +38,17 @@
"entry_points": { "entry_points": {
"type": "array", "type": "array",
"items": { "items": {
"type": "string", "type": "string"
"enum": ["import_key", "export_key", "export_public_key", }
"copy_key", "get_builtin_key"]
},
"minItems": 1,
"uniqueItems": true
}, },
"name": { "names": {
"type": "object", "type": "object",
"patternProperties": { "patternProperties": {
"^[A-Z_a-z][0-9A-Z_a-z]*$": { "^[A-Z_a-z][0-9A-Z_a-z]*$": {
"type": "string", "type": "string",
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$" "pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
} }
}, }
"minItems": 1,
"uniqueItems": true
}, },
"fallback": { "fallback": {
"type": "boolean", "type": "boolean",
@ -66,8 +59,7 @@
"entry_points" "entry_points"
] ]
} }
], ]
"default": []
} }
}, },
"required": [ "required": [

View File

@ -14,7 +14,7 @@
"_comment": "The Mbed TLS opaque driver supports copy key/ get builtin key", "_comment": "The Mbed TLS opaque driver supports copy key/ get builtin key",
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", "mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
"entry_points": ["copy_key", "get_builtin_key"], "entry_points": ["copy_key", "get_builtin_key"],
"name": {"copy_key":"mbedtls_test_opaque_copy_key", "get_builtin_key":"mbedtls_test_opaque_get_builtin_key"} "names": {"copy_key":"mbedtls_test_opaque_copy_key", "get_builtin_key":"mbedtls_test_opaque_get_builtin_key"}
} }
] ]
} }

View File

@ -15,7 +15,7 @@
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)", "mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
"entry_points": ["export_public_key"], "entry_points": ["export_public_key"],
"fallback": true, "fallback": true,
"name": {"export_public_key":"mbedtls_test_transparent_export_public_key"} "names": {"export_public_key":"mbedtls_test_transparent_export_public_key"}
} }
] ]

View File

@ -64,8 +64,8 @@
/* BEGIN-Common Macro definitions */ /* BEGIN-Common Macro definitions */
{% macro entry_point_name(capability, entry_point, driver) -%} {% macro entry_point_name(capability, entry_point, driver) -%}
{% if capability.name is defined and entry_point in capability.name.keys() -%} {% if capability.name is defined and entry_point in capability.names.keys() -%}
{{ capability.name[entry_point]}} {{ capability.names[entry_point]}}
{% else -%} {% else -%}
{{driver.prefix}}_{{driver.type}}_{{entry_point}} {{driver.prefix}}_{{driver.type}}_{{entry_point}}
{% endif -%} {% endif -%}
@ -606,7 +606,7 @@ psa_status_t psa_driver_wrapper_import_key(
size_t *key_buffer_length, size_t *key_buffer_length,
size_t *bits ) size_t *bits )
{ {
{% set entry_point = "import_key" -%} {% with entry_point = "import_key" -%}
{% macro entry_point_param(driver) -%} {% macro entry_point_param(driver) -%}
attributes, attributes,
data, data,
@ -655,11 +655,9 @@ bits
/* Key is stored in the slot in export representation, so /* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=12 %} {% with nest_indent=12 %}
{% include "OS-template-transparent.jinja" -%} {% include "OS-template-transparent.jinja" -%}
{% endwith -%} {% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
/* Fell through, meaning no accelerator supports this operation */ /* Fell through, meaning no accelerator supports this operation */
@ -669,17 +667,15 @@ bits
key_buffer_length, bits ) ); key_buffer_length, bits ) );
/* Add cases for opaque driver here */ /* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %} {% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%} {% include "OS-template-opaque.jinja" -%}
{% endwith -%} {% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default: default:
(void)status; (void)status;
return( PSA_ERROR_INVALID_ARGUMENT ); return( PSA_ERROR_INVALID_ARGUMENT );
} }
{% endwith %}
} }
psa_status_t psa_driver_wrapper_export_key( psa_status_t psa_driver_wrapper_export_key(
@ -688,7 +684,7 @@ psa_status_t psa_driver_wrapper_export_key(
uint8_t *data, size_t data_size, size_t *data_length ) uint8_t *data, size_t data_size, size_t *data_length )
{ {
{% set entry_point = "export_key" -%} {% with entry_point = "export_key" -%}
{% macro entry_point_param(driver) -%} {% macro entry_point_param(driver) -%}
attributes, attributes,
key_buffer, key_buffer,
@ -733,16 +729,15 @@ data_length
/* Add cases for opaque driver here */ /* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %} {% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%} {% include "OS-template-opaque.jinja" -%}
{% endwith -%} {% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default: default:
/* Key is declared with a lifetime not known to us */ /* Key is declared with a lifetime not known to us */
return( status ); return( status );
} }
{% endwith %}
} }
psa_status_t psa_driver_wrapper_export_public_key( psa_status_t psa_driver_wrapper_export_public_key(
@ -751,7 +746,7 @@ psa_status_t psa_driver_wrapper_export_public_key(
uint8_t *data, size_t data_size, size_t *data_length ) uint8_t *data, size_t data_size, size_t *data_length )
{ {
{% set entry_point = "export_public_key" -%} {% with entry_point = "export_public_key" -%}
{% macro entry_point_param(driver) -%} {% macro entry_point_param(driver) -%}
attributes, attributes,
key_buffer, key_buffer,
@ -790,11 +785,9 @@ data_length
/* Key is stored in the slot in export representation, so /* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */ * cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=12 %} {% with nest_indent=12 %}
{% include "OS-template-transparent.jinja" -%} {% include "OS-template-transparent.jinja" -%}
{% endwith -%} {% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
/* Fell through, meaning no accelerator supports this operation */ /* Fell through, meaning no accelerator supports this operation */
return( psa_export_public_key_internal( attributes, return( psa_export_public_key_internal( attributes,
@ -806,16 +799,15 @@ data_length
/* Add cases for opaque driver here */ /* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %} {% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%} {% include "OS-template-opaque.jinja" -%}
{% endwith -%} {% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default: default:
/* Key is declared with a lifetime not known to us */ /* Key is declared with a lifetime not known to us */
return( status ); return( status );
} }
{% endwith %}
} }
psa_status_t psa_driver_wrapper_get_builtin_key( psa_status_t psa_driver_wrapper_get_builtin_key(
@ -823,7 +815,7 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
psa_key_attributes_t *attributes, psa_key_attributes_t *attributes,
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
{ {
{% set entry_point = "get_builtin_key" -%} {% with entry_point = "get_builtin_key" -%}
{% macro entry_point_param(driver) -%} {% macro entry_point_param(driver) -%}
slot_number, slot_number,
attributes, attributes,
@ -835,11 +827,9 @@ key_buffer_length
switch( location ) switch( location )
{ {
#if defined(PSA_CRYPTO_DRIVER_TEST) #if defined(PSA_CRYPTO_DRIVER_TEST)
/* BEGIN-Templating */
{% with nest_indent=8 %} {% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%} {% include "OS-template-opaque.jinja" -%}
{% endwith -%} {% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_DRIVER_TEST */ #endif /* PSA_CRYPTO_DRIVER_TEST */
default: default:
(void) slot_number; (void) slot_number;
@ -848,6 +838,7 @@ key_buffer_length
(void) key_buffer_length; (void) key_buffer_length;
return( PSA_ERROR_DOES_NOT_EXIST ); return( PSA_ERROR_DOES_NOT_EXIST );
} }
{% endwith %}
} }
psa_status_t psa_driver_wrapper_copy_key( psa_status_t psa_driver_wrapper_copy_key(
@ -856,7 +847,7 @@ psa_status_t psa_driver_wrapper_copy_key(
uint8_t *target_key_buffer, size_t target_key_buffer_size, uint8_t *target_key_buffer, size_t target_key_buffer_size,
size_t *target_key_buffer_length ) size_t *target_key_buffer_length )
{ {
{% set entry_point = "copy_key" -%} {% with entry_point = "copy_key" -%}
{% macro entry_point_param(driver) -%} {% macro entry_point_param(driver) -%}
attributes, attributes,
source_key, source_key,
@ -883,11 +874,9 @@ target_key_buffer_length
switch( location ) switch( location )
{ {
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %} {% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%} {% include "OS-template-opaque.jinja" -%}
{% endwith -%} {% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default: default:
(void)source_key; (void)source_key;
@ -898,6 +887,7 @@ target_key_buffer_length
status = PSA_ERROR_INVALID_ARGUMENT; status = PSA_ERROR_INVALID_ARGUMENT;
} }
return( status ); return( status );
{% endwith %}
} }
/* /*

View File

@ -135,12 +135,12 @@ def main() -> int:
def_arg_mbedtls_root = build_tree.guess_mbedtls_root() def_arg_mbedtls_root = build_tree.guess_mbedtls_root()
parser = argparse.ArgumentParser() 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', nargs='?',
help='root directory of mbedtls source code')
parser.add_argument('--json-dir', nargs='?',
help='root directory of mbedtls source code') 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='?', parser.add_argument('output_directory', nargs='?',
help='output file\'s location') help='output file\'s location')
args = parser.parse_args() args = parser.parse_args()