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": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
"default": []
},
"capabilities": {
"type": "array",
@ -43,23 +42,17 @@
"entry_points": {
"type": "array",
"items": {
"type": "string",
"enum": ["import_key", "export_key", "export_public_key",
"copy_key", "get_builtin_key"]
"type": "string"
}
},
"minItems": 1,
"uniqueItems": true
},
"name": {
"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]*$"
}
},
"minItems": 1,
"uniqueItems": true
}
}
},
"required": [

View file

@ -21,8 +21,7 @@
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
"default": []
},
"capabilities": {
"type": "array",
@ -39,23 +38,17 @@
"entry_points": {
"type": "array",
"items": {
"type": "string",
"enum": ["import_key", "export_key", "export_public_key",
"copy_key", "get_builtin_key"]
"type": "string"
}
},
"minItems": 1,
"uniqueItems": true
},
"name": {
"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]*$"
}
},
"minItems": 1,
"uniqueItems": true
}
},
"fallback": {
"type": "boolean",
@ -66,8 +59,7 @@
"entry_points"
]
}
],
"default": []
]
}
},
"required": [

View file

@ -14,7 +14,7 @@
"_comment": "The Mbed TLS opaque driver supports copy key/ get builtin key",
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
"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)",
"entry_points": ["export_public_key"],
"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 */
{% macro entry_point_name(capability, entry_point, driver) -%}
{% if capability.name is defined and entry_point in capability.name.keys() -%}
{{ capability.name[entry_point]}}
{% if capability.name is defined and entry_point in capability.names.keys() -%}
{{ capability.names[entry_point]}}
{% else -%}
{{driver.prefix}}_{{driver.type}}_{{entry_point}}
{% endif -%}
@ -606,7 +606,7 @@ psa_status_t psa_driver_wrapper_import_key(
size_t *key_buffer_length,
size_t *bits )
{
{% set entry_point = "import_key" -%}
{% with entry_point = "import_key" -%}
{% macro entry_point_param(driver) -%}
attributes,
data,
@ -655,11 +655,9 @@ bits
/* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=12 %}
{% include "OS-template-transparent.jinja" -%}
{% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
/* Fell through, meaning no accelerator supports this operation */
@ -669,17 +667,15 @@ bits
key_buffer_length, bits ) );
/* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%}
{% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default:
(void)status;
return( PSA_ERROR_INVALID_ARGUMENT );
}
{% endwith %}
}
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 )
{
{% set entry_point = "export_key" -%}
{% with entry_point = "export_key" -%}
{% macro entry_point_param(driver) -%}
attributes,
key_buffer,
@ -733,16 +729,15 @@ data_length
/* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%}
{% endwith -%}
/* END-Templating */
#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(
@ -751,7 +746,7 @@ psa_status_t psa_driver_wrapper_export_public_key(
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) -%}
attributes,
key_buffer,
@ -790,11 +785,9 @@ data_length
/* Key is stored in the slot in export representation, so
* cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=12 %}
{% include "OS-template-transparent.jinja" -%}
{% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
/* Fell through, meaning no accelerator supports this operation */
return( psa_export_public_key_internal( attributes,
@ -806,16 +799,15 @@ data_length
/* Add cases for opaque driver here */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%}
{% endwith -%}
/* END-Templating */
#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(
@ -823,7 +815,7 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
psa_key_attributes_t *attributes,
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) -%}
slot_number,
attributes,
@ -835,11 +827,9 @@ key_buffer_length
switch( location )
{
#if defined(PSA_CRYPTO_DRIVER_TEST)
/* BEGIN-Templating */
{% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%}
{% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_DRIVER_TEST */
default:
(void) slot_number;
@ -848,6 +838,7 @@ key_buffer_length
(void) key_buffer_length;
return( PSA_ERROR_DOES_NOT_EXIST );
}
{% endwith %}
}
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,
size_t *target_key_buffer_length )
{
{% set entry_point = "copy_key" -%}
{% with entry_point = "copy_key" -%}
{% macro entry_point_param(driver) -%}
attributes,
source_key,
@ -883,11 +874,9 @@ target_key_buffer_length
switch( location )
{
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
/* BEGIN-Templating */
{% with nest_indent=8 %}
{% include "OS-template-opaque.jinja" -%}
{% endwith -%}
/* END-Templating */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
default:
(void)source_key;
@ -898,6 +887,7 @@ target_key_buffer_length
status = PSA_ERROR_INVALID_ARGUMENT;
}
return( status );
{% endwith %}
}
/*

View file

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