mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
JSONschema and python improvements
* JSON Schema manually updated to be more semantically valid. * Python script improved to be more verbose with exceptions * Templating file improved by adding an additional macro. Signed-off-by: Archana <archana.madhavan@silabs.com> Signed-off-by: Asfandyar Orakzai <asfandyar.orakzai@silabs.com>
This commit is contained in:
committed by
Asfandyar Orakzai
parent
e17071a5ee
commit
fdbbcba3eb
@ -2,25 +2,31 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"prefix": {
|
||||
"_comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"prefix": {
|
||||
"type": "string",
|
||||
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"const": ["opaque"]
|
||||
},
|
||||
"location": {
|
||||
"type": "string"
|
||||
"type": ["integer","string"],
|
||||
"pattern": "^(0x|0X)?[a-fA-F0-9]+$"
|
||||
},
|
||||
"dependency": {
|
||||
"mbedtls/h_depend_on": {
|
||||
"type": "string"
|
||||
},
|
||||
"headers": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"capabilities": {
|
||||
"type": "array",
|
||||
@ -31,71 +37,33 @@
|
||||
"_comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"depend_on": {
|
||||
"mbedtls/c_depend_on": {
|
||||
"type": "string"
|
||||
},
|
||||
"entry_points": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "string"
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": ["import_key", "export_key", "export_public_key",
|
||||
"copy_key", "get_builtin_key"]
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"_comment",
|
||||
"depend_on",
|
||||
"entry_points"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"depend_on": {
|
||||
"type": "string"
|
||||
},
|
||||
"entry_points": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"name": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"copy_key": {
|
||||
"type": "string"
|
||||
},
|
||||
"get_builtin_key": {
|
||||
"type": "string"
|
||||
"patternProperties": {
|
||||
"^[A-Z_a-z][0-9A-Z_a-z]*$": {
|
||||
"type": "string",
|
||||
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"copy_key",
|
||||
"get_builtin_key"
|
||||
]
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"_comment",
|
||||
"depend_on",
|
||||
"entry_points",
|
||||
"name"
|
||||
"entry_points"
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -105,8 +73,6 @@
|
||||
"prefix",
|
||||
"type",
|
||||
"location",
|
||||
"dependency",
|
||||
"headers",
|
||||
"capabilities"
|
||||
]
|
||||
}
|
||||
|
@ -2,22 +2,27 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"prefix": {
|
||||
"_comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"prefix": {
|
||||
"type": "string",
|
||||
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"const": ["transparent"]
|
||||
},
|
||||
"dependency": {
|
||||
"mbedtls/h_depend_on": {
|
||||
"type": "string"
|
||||
},
|
||||
"headers": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"capabilities": {
|
||||
"type": "array",
|
||||
@ -28,79 +33,46 @@
|
||||
"_comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"depend_on": {
|
||||
"mbedtls/c_depend_on": {
|
||||
"type": "string"
|
||||
},
|
||||
"entry_points": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "string"
|
||||
"items": {
|
||||
"type": "string",
|
||||
"enum": ["import_key", "export_key", "export_public_key",
|
||||
"copy_key", "get_builtin_key"]
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"fallback": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"_comment",
|
||||
"depend_on",
|
||||
"entry_points",
|
||||
"fallback"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_comment": {
|
||||
"type": "string"
|
||||
},
|
||||
"depend_on": {
|
||||
"type": "string"
|
||||
},
|
||||
"entry_points": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"fallback": {
|
||||
"type": "boolean"
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"name": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"export_public_key": {
|
||||
"type": "string"
|
||||
"patternProperties": {
|
||||
"^[A-Z_a-z][0-9A-Z_a-z]*$": {
|
||||
"type": "string",
|
||||
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"export_public_key"
|
||||
]
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"fallback": {
|
||||
"type": "boolean",
|
||||
"default": "false"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"_comment",
|
||||
"depend_on",
|
||||
"entry_points",
|
||||
"fallback",
|
||||
"name"
|
||||
"entry_points"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"default": []
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"prefix",
|
||||
"type",
|
||||
"dependency",
|
||||
"headers",
|
||||
"capabilities"
|
||||
]
|
||||
}
|
||||
|
@ -2,18 +2,18 @@
|
||||
"prefix": "mbedtls_test",
|
||||
"type": "opaque",
|
||||
"location": "0x7fffff",
|
||||
"dependency": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"mbedtls/h_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"headers": ["test/drivers/test_driver.h"],
|
||||
"capabilities": [
|
||||
{
|
||||
"_comment": "The mbedTLS opaque driver supports import key/export key/export_public key",
|
||||
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"_comment": "The Mbed TLS opaque driver supports import key/export key/export_public key",
|
||||
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"entry_points": ["import_key", "export_key", "export_public_key"]
|
||||
},
|
||||
{
|
||||
"_comment": "The mbedTLS opaque driver supports copy key/ get builtin key",
|
||||
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"entry_points": ["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)",
|
||||
"entry_points": ["copy_key", "get_builtin_key"],
|
||||
"name": {"copy_key":"mbedtls_test_opaque_copy_key", "get_builtin_key":"mbedtls_test_opaque_get_builtin_key"}
|
||||
}
|
||||
]
|
||||
|
@ -1,18 +1,18 @@
|
||||
{
|
||||
"prefix": "mbedtls_test",
|
||||
"type": "transparent",
|
||||
"dependency": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"mbedtls/h_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"headers": ["test/drivers/test_driver.h"],
|
||||
"capabilities": [
|
||||
{
|
||||
"_comment": "The mbedTLS transparent driver supports import key/export key",
|
||||
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"_comment": "The Mbed TLS transparent driver supports import key/export key",
|
||||
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"entry_points": ["import_key", "export_key"],
|
||||
"fallback": true
|
||||
},
|
||||
{
|
||||
"_comment": "The mbedTLS transparent driver supports export_public key",
|
||||
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||
"_comment": "The Mbed TLS transparent driver supports export_public key",
|
||||
"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"}
|
||||
|
@ -1,13 +1,16 @@
|
||||
{# 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.depend_on is defined -%}{{ capability.depend_on }} {% else -%} {{ 1 }} {% endif %})
|
||||
#if ({% if capability['mbedtls/c_depend_on'] is defined -%}{{ capability['mbedtls/c_depend_on'] }} {% else -%} {{ 1 }} {% endif %})
|
||||
{%- filter indent(width = nest_indent) %}
|
||||
case {{ driver.location }}:
|
||||
{% if capability.name is defined and entry_point in capability.name.keys() -%}
|
||||
return({{ capability.name[entry_point]}}({{entry_point_attributes(driver) | indent(20)}}));
|
||||
{% else -%}
|
||||
return({{driver.prefix}}_{{driver.type}}_{{entry_point}}({{entry_point_attributes(driver) | indent(20)}}));
|
||||
{% endif -%}
|
||||
return( {{ entry_point_name(capability, entry_point, driver) }}({{entry_point_param(driver) | indent(20)}}));
|
||||
{% endfilter -%}
|
||||
#endif
|
||||
{% endfor %}
|
||||
|
@ -1,12 +1,15 @@
|
||||
{# 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.depend_on is defined -%}{{ capability.depend_on }} {% else -%} {{ 1 }} {% endif %})
|
||||
#if ({% if capability['mbedtls/c_depend_on'] is defined -%}{{ capability['mbedtls/c_depend_on'] }} {% else -%} {{ 1 }} {% endif %})
|
||||
{%- filter indent(width = nest_indent) %}
|
||||
{% if capability.name is defined and entry_point in capability.name.keys() -%}
|
||||
status = {{ capability.name[entry_point]}}({{entry_point_attributes(driver) | indent(20)}});
|
||||
{% else -%}
|
||||
status = {{driver.prefix}}_{{driver.type}}_{{entry_point}}({{entry_point_attributes(driver) | indent(20)}});
|
||||
{% endif -%}
|
||||
status = {{ entry_point_name(capability, entry_point, driver) }}({{entry_point_param(driver) | indent(20)}});
|
||||
|
||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||
return( status );
|
||||
|
@ -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
|
||||
@ -39,13 +39,15 @@
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS)
|
||||
{% for driver in drivers -%}
|
||||
/* Headers for {{driver.prefix}} {{driver.type}} driver */
|
||||
{% if driver.dependency is defined -%}
|
||||
#if {{ driver.dependency }}
|
||||
{% if driver['mbedtls/h_depend_on'] is defined -%}
|
||||
#if {{ driver['mbedtls/h_depend_on'] }}
|
||||
{% endif -%}
|
||||
{% for header in driver.headers -%}
|
||||
#include "{{ header }}"
|
||||
{% endfor %}
|
||||
{% if driver['mbedtls/h_depend_on'] is defined -%}
|
||||
#endif
|
||||
{% endif -%}
|
||||
{% endfor %}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */
|
||||
/* END-driver headers */
|
||||
@ -60,6 +62,16 @@
|
||||
{% endfor %}
|
||||
/* END-driver id */
|
||||
|
||||
/* 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]}}
|
||||
{% 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)
|
||||
/* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style
|
||||
@ -595,7 +607,7 @@ psa_status_t psa_driver_wrapper_import_key(
|
||||
size_t *bits )
|
||||
{
|
||||
{% set entry_point = "import_key" -%}
|
||||
{% macro entry_point_attributes(driver) -%}
|
||||
{% macro entry_point_param(driver) -%}
|
||||
attributes,
|
||||
data,
|
||||
data_length,
|
||||
@ -677,7 +689,7 @@ psa_status_t psa_driver_wrapper_export_key(
|
||||
|
||||
{
|
||||
{% set entry_point = "export_key" -%}
|
||||
{% macro entry_point_attributes(driver) -%}
|
||||
{% macro entry_point_param(driver) -%}
|
||||
attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
@ -740,7 +752,7 @@ psa_status_t psa_driver_wrapper_export_public_key(
|
||||
|
||||
{
|
||||
{% set entry_point = "export_public_key" -%}
|
||||
{% macro entry_point_attributes(driver) -%}
|
||||
{% macro entry_point_param(driver) -%}
|
||||
attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
@ -812,7 +824,7 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
||||
{
|
||||
{% set entry_point = "get_builtin_key" -%}
|
||||
{% macro entry_point_attributes(driver) -%}
|
||||
{% macro entry_point_param(driver) -%}
|
||||
slot_number,
|
||||
attributes,
|
||||
key_buffer,
|
||||
@ -845,7 +857,7 @@ psa_status_t psa_driver_wrapper_copy_key(
|
||||
size_t *target_key_buffer_length )
|
||||
{
|
||||
{% set entry_point = "copy_key" -%}
|
||||
{% macro entry_point_attributes(driver) -%}
|
||||
{% macro entry_point_param(driver) -%}
|
||||
attributes,
|
||||
source_key,
|
||||
source_key_length,
|
||||
|
Reference in New Issue
Block a user