mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-28 09:39:53 +00:00
Driver Wrapper CodeGen Rev 1.1
(1) Add in driver jsons. (2) Improve Python scripts to take JSON file directory and template directory paths as arguments. (3) Add in file augment template files to template common functionality (4) render tempplates for Header files, ID generation and key management. (5) Changed driver ID nomenclature to be in synch with function names. Signed-off-by: Archana <archana.madhavan@silabs.com> Signed-off-by: Asfandyar Orakzai <asfandyar.orakzai@silabs.com>
This commit is contained in:
parent
c11bffe989
commit
e829cd6953
1
scripts/data_files/driver_jsons/driverlist.json
Normal file
1
scripts/data_files/driver_jsons/driverlist.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
["mbedtls_test_opaque_driver.json","mbedtls_test_transparent_driver.json"]
|
@ -0,0 +1,18 @@
|
|||||||
|
[{
|
||||||
|
"prefix": "mbedtls_test",
|
||||||
|
"type": "opaque",
|
||||||
|
"location": "0x7fffff",
|
||||||
|
"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)",
|
||||||
|
"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"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}]
|
@ -0,0 +1,13 @@
|
|||||||
|
[{
|
||||||
|
"prefix": "mbedtls_test",
|
||||||
|
"type": "transparent",
|
||||||
|
"headers": ["test/drivers/test_driver.h"],
|
||||||
|
"capabilities": [
|
||||||
|
{
|
||||||
|
"_comment": "The mbedTLS transparent driver supports import key/export key/export_public key",
|
||||||
|
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
|
||||||
|
"entry_points": ["import_key", "export_key", "export_public_key"],
|
||||||
|
"fallback": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}]
|
10
scripts/data_files/driver_templates/OS-template-opaque.jinja
Normal file
10
scripts/data_files/driver_templates/OS-template-opaque.jinja
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% 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 %})
|
||||||
|
{%- filter indent(width = nest_indent) %}
|
||||||
|
case {{ driver.location }}:
|
||||||
|
return({{driver.prefix}}_{{driver.type}}_{{entry_point}}({{entry_point_attributes(driver) | indent(20)}}));
|
||||||
|
{% endfilter -%}
|
||||||
|
#endif
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
@ -0,0 +1,12 @@
|
|||||||
|
{% 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 %})
|
||||||
|
{%- filter indent(width = nest_indent) %}
|
||||||
|
status = {{driver.prefix}}_{{driver.type}}_{{entry_point}}({{entry_point_attributes(driver) | indent(20)}});
|
||||||
|
|
||||||
|
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||||
|
return( status );
|
||||||
|
{% endfilter -%}
|
||||||
|
#endif
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
@ -19,6 +19,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* BEGIN-common headers */
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "psa_crypto_aead.h"
|
#include "psa_crypto_aead.h"
|
||||||
#include "psa_crypto_cipher.h"
|
#include "psa_crypto_cipher.h"
|
||||||
@ -29,34 +31,30 @@
|
|||||||
#include "psa_crypto_rsa.h"
|
#include "psa_crypto_rsa.h"
|
||||||
|
|
||||||
#include "mbedtls/platform.h"
|
#include "mbedtls/platform.h"
|
||||||
|
/* END-common headers */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
||||||
|
|
||||||
|
/* BEGIN-driver headers */
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS)
|
#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS)
|
||||||
|
{% for driver in drivers -%}
|
||||||
/* Include test driver definition when running tests */
|
/* Headers for {{driver.prefix}} {{driver.type}} driver */
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
{% for header in driver.headers -%}
|
||||||
#ifndef PSA_CRYPTO_DRIVER_PRESENT
|
#include "{{ header }}"
|
||||||
#define PSA_CRYPTO_DRIVER_PRESENT
|
{% endfor %}
|
||||||
#endif
|
{% endfor %}
|
||||||
#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 /* MBEDTLS_PSA_CRYPTO_DRIVERS */
|
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */
|
||||||
|
/* END-driver headers */
|
||||||
|
|
||||||
/* Auto-generated values depending on which drivers are registered.
|
/* Auto-generated values depending on which drivers are registered.
|
||||||
* ID 0 is reserved for unallocated operations.
|
* ID 0 is reserved for unallocated operations.
|
||||||
* ID 1 is reserved for the Mbed TLS software driver. */
|
* ID 1 is reserved for the Mbed TLS software driver. */
|
||||||
|
/* BEGIN-driver id definition */
|
||||||
#define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1)
|
#define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1)
|
||||||
|
{% for driver in drivers -%}
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#define {{(driver.prefix + "_" + driver.type + "_driver_id").upper()}} ({{ loop.index + 1 }})
|
||||||
#define PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID (2)
|
{% endfor %}
|
||||||
#define PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID (3)
|
/* END-driver id */
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
/* Support the 'old' SE interface when asked to */
|
/* Support the 'old' SE interface when asked to */
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||||
@ -592,6 +590,16 @@ 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" -%}
|
||||||
|
{% macro entry_point_attributes(driver) -%}
|
||||||
|
attributes,
|
||||||
|
data,
|
||||||
|
data_length,
|
||||||
|
key_buffer,
|
||||||
|
key_buffer_size,
|
||||||
|
key_buffer_length,
|
||||||
|
bits
|
||||||
|
{% endmacro %}
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
|
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
|
||||||
psa_get_key_lifetime( attributes ) );
|
psa_get_key_lifetime( attributes ) );
|
||||||
@ -631,17 +639,13 @@ psa_status_t psa_driver_wrapper_import_key(
|
|||||||
/* 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)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
/* BEGIN-Templating */
|
||||||
status = mbedtls_test_transparent_import_key(
|
{% with nest_indent=12 %}
|
||||||
attributes,
|
{% include "OS-template-transparent.jinja" -%}
|
||||||
data, data_length,
|
{% endwith -%}
|
||||||
key_buffer, key_buffer_size,
|
/* END-Templating */
|
||||||
key_buffer_length, bits );
|
|
||||||
/* Declared with fallback == true */
|
|
||||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
|
||||||
return( status );
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
#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_import_key_into_slot( attributes,
|
return( psa_import_key_into_slot( attributes,
|
||||||
data, data_length,
|
data, data_length,
|
||||||
@ -649,14 +653,11 @@ psa_status_t psa_driver_wrapper_import_key(
|
|||||||
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)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
/* BEGIN-Templating */
|
||||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
{% with nest_indent=8 %}
|
||||||
return( mbedtls_test_opaque_import_key(
|
{% include "OS-template-opaque.jinja" -%}
|
||||||
attributes,
|
{% endwith -%}
|
||||||
data, data_length,
|
/* END-Templating */
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length, bits ) );
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
default:
|
default:
|
||||||
(void)status;
|
(void)status;
|
||||||
@ -671,6 +672,15 @@ 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" -%}
|
||||||
|
{% macro entry_point_attributes(driver) -%}
|
||||||
|
attributes,
|
||||||
|
key_buffer,
|
||||||
|
key_buffer_size,
|
||||||
|
data,
|
||||||
|
data_size,
|
||||||
|
data_length
|
||||||
|
{% endmacro %}
|
||||||
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
|
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
|
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
|
||||||
psa_get_key_lifetime( attributes ) );
|
psa_get_key_lifetime( attributes ) );
|
||||||
@ -707,15 +717,11 @@ psa_status_t psa_driver_wrapper_export_key(
|
|||||||
|
|
||||||
/* 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)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
/* BEGIN-Templating */
|
||||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
{% with nest_indent=8 %}
|
||||||
return( mbedtls_test_opaque_export_key( attributes,
|
{% include "OS-template-opaque.jinja" -%}
|
||||||
key_buffer,
|
{% endwith -%}
|
||||||
key_buffer_size,
|
/* END-Templating */
|
||||||
data,
|
|
||||||
data_size,
|
|
||||||
data_length ) );
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
#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 */
|
||||||
@ -729,6 +735,15 @@ 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" -%}
|
||||||
|
{% macro entry_point_attributes(driver) -%}
|
||||||
|
attributes,
|
||||||
|
key_buffer,
|
||||||
|
key_buffer_size,
|
||||||
|
data,
|
||||||
|
data_size,
|
||||||
|
data_length
|
||||||
|
{% endmacro %}
|
||||||
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
|
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
|
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
|
||||||
psa_get_key_lifetime( attributes ) );
|
psa_get_key_lifetime( attributes ) );
|
||||||
@ -759,18 +774,11 @@ psa_status_t psa_driver_wrapper_export_public_key(
|
|||||||
/* 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)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
/* BEGIN-Templating */
|
||||||
status = mbedtls_test_transparent_export_public_key(
|
{% with nest_indent=12 %}
|
||||||
attributes,
|
{% include "OS-template-transparent.jinja" -%}
|
||||||
key_buffer,
|
{% endwith -%}
|
||||||
key_buffer_size,
|
/* END-Templating */
|
||||||
data,
|
|
||||||
data_size,
|
|
||||||
data_length );
|
|
||||||
/* Declared with fallback == true */
|
|
||||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
|
||||||
return( status );
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
#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,
|
||||||
@ -782,15 +790,11 @@ psa_status_t psa_driver_wrapper_export_public_key(
|
|||||||
|
|
||||||
/* 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)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
/* BEGIN-Templating */
|
||||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
{% with nest_indent=8 %}
|
||||||
return( mbedtls_test_opaque_export_public_key( attributes,
|
{% include "OS-template-opaque.jinja" -%}
|
||||||
key_buffer,
|
{% endwith -%}
|
||||||
key_buffer_size,
|
/* END-Templating */
|
||||||
data,
|
|
||||||
data_size,
|
|
||||||
data_length ) );
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
#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 */
|
||||||
@ -803,15 +807,23 @@ 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" -%}
|
||||||
|
{% macro entry_point_attributes(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 );
|
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
||||||
switch( location )
|
switch( location )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
/* BEGIN-Templating */
|
||||||
return( mbedtls_test_opaque_get_builtin_key(
|
{% with nest_indent=8 %}
|
||||||
slot_number,
|
{% include "OS-template-opaque.jinja" -%}
|
||||||
attributes,
|
{% endwith -%}
|
||||||
key_buffer, key_buffer_size, key_buffer_length ) );
|
/* END-Templating */
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
default:
|
default:
|
||||||
(void) slot_number;
|
(void) slot_number;
|
||||||
@ -828,6 +840,15 @@ 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" -%}
|
||||||
|
{% macro entry_point_attributes(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_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_key_location_t location =
|
psa_key_location_t location =
|
||||||
PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
||||||
@ -846,14 +867,11 @@ psa_status_t psa_driver_wrapper_copy_key(
|
|||||||
switch( location )
|
switch( location )
|
||||||
{
|
{
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
/* BEGIN-Templating */
|
||||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
{% with nest_indent=8 %}
|
||||||
return( mbedtls_test_opaque_copy_key( attributes, source_key,
|
{% include "OS-template-opaque.jinja" -%}
|
||||||
source_key_length,
|
{% endwith -%}
|
||||||
target_key_buffer,
|
/* END-Templating */
|
||||||
target_key_buffer_size,
|
|
||||||
target_key_buffer_length) );
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
default:
|
default:
|
||||||
(void)source_key;
|
(void)source_key;
|
||||||
@ -1068,7 +1086,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
|
|||||||
alg );
|
alg );
|
||||||
/* Declared with fallback == true */
|
/* Declared with fallback == true */
|
||||||
if( status == PSA_SUCCESS )
|
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 )
|
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||||
return( status );
|
return( status );
|
||||||
@ -1100,7 +1118,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
|
|||||||
alg );
|
alg );
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
|
operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
@ -1141,7 +1159,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
|
|||||||
alg );
|
alg );
|
||||||
/* Declared with fallback == true */
|
/* Declared with fallback == true */
|
||||||
if( status == PSA_SUCCESS )
|
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 )
|
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||||
return( status );
|
return( status );
|
||||||
@ -1172,7 +1190,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
|
|||||||
alg );
|
alg );
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
|
operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
@ -1204,12 +1222,12 @@ psa_status_t psa_driver_wrapper_cipher_set_iv(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_cipher_set_iv(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
iv, iv_length ) );
|
iv, iv_length ) );
|
||||||
|
|
||||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
|
||||||
return( mbedtls_test_opaque_cipher_set_iv(
|
return( mbedtls_test_opaque_cipher_set_iv(
|
||||||
&operation->ctx.opaque_test_driver_ctx,
|
&operation->ctx.opaque_test_driver_ctx,
|
||||||
iv, iv_length ) );
|
iv, iv_length ) );
|
||||||
@ -1245,13 +1263,13 @@ psa_status_t psa_driver_wrapper_cipher_update(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_cipher_update(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
input, input_length,
|
input, input_length,
|
||||||
output, output_size, output_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(
|
return( mbedtls_test_opaque_cipher_update(
|
||||||
&operation->ctx.opaque_test_driver_ctx,
|
&operation->ctx.opaque_test_driver_ctx,
|
||||||
input, input_length,
|
input, input_length,
|
||||||
@ -1287,12 +1305,12 @@ psa_status_t psa_driver_wrapper_cipher_finish(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_cipher_finish(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
|
|
||||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
|
||||||
return( mbedtls_test_opaque_cipher_finish(
|
return( mbedtls_test_opaque_cipher_finish(
|
||||||
&operation->ctx.opaque_test_driver_ctx,
|
&operation->ctx.opaque_test_driver_ctx,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
@ -1321,7 +1339,7 @@ psa_status_t psa_driver_wrapper_cipher_abort(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
status = mbedtls_test_transparent_cipher_abort(
|
||||||
&operation->ctx.transparent_test_driver_ctx );
|
&operation->ctx.transparent_test_driver_ctx );
|
||||||
mbedtls_platform_zeroize(
|
mbedtls_platform_zeroize(
|
||||||
@ -1329,7 +1347,7 @@ psa_status_t psa_driver_wrapper_cipher_abort(
|
|||||||
sizeof( operation->ctx.transparent_test_driver_ctx ) );
|
sizeof( operation->ctx.transparent_test_driver_ctx ) );
|
||||||
return( status );
|
return( status );
|
||||||
|
|
||||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
|
||||||
status = mbedtls_test_opaque_cipher_abort(
|
status = mbedtls_test_opaque_cipher_abort(
|
||||||
&operation->ctx.opaque_test_driver_ctx );
|
&operation->ctx.opaque_test_driver_ctx );
|
||||||
mbedtls_platform_zeroize(
|
mbedtls_platform_zeroize(
|
||||||
@ -1394,7 +1412,7 @@ psa_status_t psa_driver_wrapper_hash_setup(
|
|||||||
status = mbedtls_test_transparent_hash_setup(
|
status = mbedtls_test_transparent_hash_setup(
|
||||||
&operation->ctx.test_driver_ctx, alg );
|
&operation->ctx.test_driver_ctx, alg );
|
||||||
if( status == PSA_SUCCESS )
|
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 )
|
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||||
return( status );
|
return( status );
|
||||||
@ -1429,8 +1447,8 @@ psa_status_t psa_driver_wrapper_hash_clone(
|
|||||||
&target_operation->ctx.mbedtls_ctx ) );
|
&target_operation->ctx.mbedtls_ctx ) );
|
||||||
#endif
|
#endif
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
|
||||||
target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
|
target_operation->id = MBEDTLS_TEST_TRANSPARENT_DRIVER_ID;
|
||||||
return( mbedtls_test_transparent_hash_clone(
|
return( mbedtls_test_transparent_hash_clone(
|
||||||
&source_operation->ctx.test_driver_ctx,
|
&source_operation->ctx.test_driver_ctx,
|
||||||
&target_operation->ctx.test_driver_ctx ) );
|
&target_operation->ctx.test_driver_ctx ) );
|
||||||
@ -1454,7 +1472,7 @@ psa_status_t psa_driver_wrapper_hash_update(
|
|||||||
input, input_length ) );
|
input, input_length ) );
|
||||||
#endif
|
#endif
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_hash_update(
|
||||||
&operation->ctx.test_driver_ctx,
|
&operation->ctx.test_driver_ctx,
|
||||||
input, input_length ) );
|
input, input_length ) );
|
||||||
@ -1480,7 +1498,7 @@ psa_status_t psa_driver_wrapper_hash_finish(
|
|||||||
hash, hash_size, hash_length ) );
|
hash, hash_size, hash_length ) );
|
||||||
#endif
|
#endif
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_hash_finish(
|
||||||
&operation->ctx.test_driver_ctx,
|
&operation->ctx.test_driver_ctx,
|
||||||
hash, hash_size, hash_length ) );
|
hash, hash_size, hash_length ) );
|
||||||
@ -1503,7 +1521,7 @@ psa_status_t psa_driver_wrapper_hash_abort(
|
|||||||
return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) );
|
return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) );
|
||||||
#endif
|
#endif
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_hash_abort(
|
||||||
&operation->ctx.test_driver_ctx ) );
|
&operation->ctx.test_driver_ctx ) );
|
||||||
#endif
|
#endif
|
||||||
@ -1650,7 +1668,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
status = mbedtls_test_transparent_aead_encrypt_setup(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
attributes, key_buffer, key_buffer_size,
|
attributes, key_buffer, key_buffer_size,
|
||||||
@ -1698,7 +1716,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
status = mbedtls_test_transparent_aead_decrypt_setup(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
attributes,
|
attributes,
|
||||||
@ -1747,7 +1765,7 @@ psa_status_t psa_driver_wrapper_aead_set_nonce(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_aead_set_nonce(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
nonce, nonce_length ) );
|
nonce, nonce_length ) );
|
||||||
@ -1781,7 +1799,7 @@ psa_status_t psa_driver_wrapper_aead_set_lengths(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_aead_set_lengths(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
ad_length, plaintext_length ) );
|
ad_length, plaintext_length ) );
|
||||||
@ -1815,7 +1833,7 @@ psa_status_t psa_driver_wrapper_aead_update_ad(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_aead_update_ad(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
input, input_length ) );
|
input, input_length ) );
|
||||||
@ -1853,7 +1871,7 @@ psa_status_t psa_driver_wrapper_aead_update(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_aead_update(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
input, input_length, output, output_size,
|
input, input_length, output, output_size,
|
||||||
@ -1897,7 +1915,7 @@ psa_status_t psa_driver_wrapper_aead_finish(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_aead_finish(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
ciphertext, ciphertext_size,
|
ciphertext, ciphertext_size,
|
||||||
@ -1961,7 +1979,7 @@ psa_status_t psa_driver_wrapper_aead_verify(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_aead_verify(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
plaintext, plaintext_size,
|
plaintext, plaintext_size,
|
||||||
@ -1995,7 +2013,7 @@ psa_status_t psa_driver_wrapper_aead_abort(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_aead_abort(
|
||||||
&operation->ctx.transparent_test_driver_ctx ) );
|
&operation->ctx.transparent_test_driver_ctx ) );
|
||||||
|
|
||||||
@ -2104,7 +2122,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(
|
|||||||
alg );
|
alg );
|
||||||
/* Declared with fallback == true */
|
/* Declared with fallback == true */
|
||||||
if( status == PSA_SUCCESS )
|
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 )
|
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||||
return( status );
|
return( status );
|
||||||
@ -2135,7 +2153,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(
|
|||||||
alg );
|
alg );
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
|
operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
@ -2176,7 +2194,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(
|
|||||||
alg );
|
alg );
|
||||||
/* Declared with fallback == true */
|
/* Declared with fallback == true */
|
||||||
if( status == PSA_SUCCESS )
|
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 )
|
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||||
return( status );
|
return( status );
|
||||||
@ -2207,7 +2225,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(
|
|||||||
alg );
|
alg );
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
operation->id = PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID;
|
operation->id = MBEDTLS_TEST_OPAQUE_DRIVER_ID;
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
@ -2238,12 +2256,12 @@ psa_status_t psa_driver_wrapper_mac_update(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_mac_update(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
input, input_length ) );
|
input, input_length ) );
|
||||||
|
|
||||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
|
||||||
return( mbedtls_test_opaque_mac_update(
|
return( mbedtls_test_opaque_mac_update(
|
||||||
&operation->ctx.opaque_test_driver_ctx,
|
&operation->ctx.opaque_test_driver_ctx,
|
||||||
input, input_length ) );
|
input, input_length ) );
|
||||||
@ -2272,12 +2290,12 @@ psa_status_t psa_driver_wrapper_mac_sign_finish(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_mac_sign_finish(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
mac, mac_size, mac_length ) );
|
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(
|
return( mbedtls_test_opaque_mac_sign_finish(
|
||||||
&operation->ctx.opaque_test_driver_ctx,
|
&operation->ctx.opaque_test_driver_ctx,
|
||||||
mac, mac_size, mac_length ) );
|
mac, mac_size, mac_length ) );
|
||||||
@ -2306,12 +2324,12 @@ psa_status_t psa_driver_wrapper_mac_verify_finish(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_mac_verify_finish(
|
||||||
&operation->ctx.transparent_test_driver_ctx,
|
&operation->ctx.transparent_test_driver_ctx,
|
||||||
mac, mac_length ) );
|
mac, mac_length ) );
|
||||||
|
|
||||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
case MBEDTLS_TEST_OPAQUE_DRIVER_ID:
|
||||||
return( mbedtls_test_opaque_mac_verify_finish(
|
return( mbedtls_test_opaque_mac_verify_finish(
|
||||||
&operation->ctx.opaque_test_driver_ctx,
|
&operation->ctx.opaque_test_driver_ctx,
|
||||||
mac, mac_length ) );
|
mac, mac_length ) );
|
||||||
@ -2336,10 +2354,10 @@ psa_status_t psa_driver_wrapper_mac_abort(
|
|||||||
|
|
||||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
#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(
|
return( mbedtls_test_transparent_mac_abort(
|
||||||
&operation->ctx.transparent_test_driver_ctx ) );
|
&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(
|
return( mbedtls_test_opaque_mac_abort(
|
||||||
&operation->ctx.opaque_test_driver_ctx ) );
|
&operation->ctx.opaque_test_driver_ctx ) );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
@ -22,52 +22,90 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
import jinja2
|
import jinja2
|
||||||
from mbedtls_dev import build_tree
|
from mbedtls_dev import build_tree
|
||||||
|
|
||||||
def render(template_path: str) -> str:
|
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(
|
environment = jinja2.Environment(
|
||||||
loader=jinja2.FileSystemLoader(os.path.dirname(template_path)),
|
loader=jinja2.FileSystemLoader(os.path.dirname(template_path)),
|
||||||
keep_trailing_newline=True)
|
keep_trailing_newline=True)
|
||||||
template = environment.get_template(os.path.basename(template_path))
|
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.
|
Generate the file psa_crypto_driver_wrapper.c.
|
||||||
"""
|
"""
|
||||||
driver_wrapper_template_filename = \
|
driver_wrapper_template_filename = \
|
||||||
os.path.join(mbedtls_root, \
|
os.path.join(template_dir, "psa_crypto_driver_wrappers.c.jinja")
|
||||||
"scripts/data_files/driver_templates/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:
|
with open(os.path.join(output_dir, "psa_crypto_driver_wrappers.c"), 'w') as out_file:
|
||||||
out_file.write(result)
|
out_file.write(result)
|
||||||
|
|
||||||
|
def validate_mergedjson(merged_driverjson: list) -> int:
|
||||||
|
"""
|
||||||
|
Validate the merged Driver JSON for errors that we can catch early
|
||||||
|
"""
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def merge_driverjsonfiles(json_directory: str, jsondriverlistName: str) -> list:
|
||||||
|
"""
|
||||||
|
Merge driver JSON files into a single ordered JSON.
|
||||||
|
"""
|
||||||
|
result = list()
|
||||||
|
driverlist = list()
|
||||||
|
with open(os.path.join(json_directory, jsondriverlistName), 'r') as driverlistfile:
|
||||||
|
driverlist = json.load(driverlistfile)
|
||||||
|
for file_name in driverlist:
|
||||||
|
with open(os.path.join(json_directory, file_name), 'r') as infile:
|
||||||
|
result.extend(json.load(infile))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
"""
|
"""
|
||||||
Main with command line arguments.
|
Main with command line arguments.
|
||||||
"""
|
"""
|
||||||
def_arg_mbedtls_root = build_tree.guess_mbedtls_root()
|
def_arg_mbedtls_root = build_tree.guess_mbedtls_root()
|
||||||
def_arg_output_dir = os.path.join(def_arg_mbedtls_root, 'library')
|
def_arg_output_dir = os.path.join(def_arg_mbedtls_root, 'library')
|
||||||
|
def_arg_template_dir = os.path.join(def_arg_mbedtls_root, 'scripts/data_files/driver_templates/')
|
||||||
|
def_arg_json_dir = os.path.join(def_arg_mbedtls_root, 'scripts/data_files/driver_jsons/')
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--mbedtls-root', nargs='?', default=def_arg_mbedtls_root,
|
parser.add_argument('--mbedtls-root', nargs='?', default=def_arg_mbedtls_root,
|
||||||
help='root directory of mbedtls source code')
|
help='root directory of mbedtls source code')
|
||||||
|
parser.add_argument('--template_dir', nargs='?', default=def_arg_template_dir,
|
||||||
|
help='root directory of mbedtls source code')
|
||||||
|
parser.add_argument('--json_dir', nargs='?', default=def_arg_json_dir,
|
||||||
|
help='root directory of mbedtls source code')
|
||||||
parser.add_argument('output_directory', nargs='?',
|
parser.add_argument('output_directory', nargs='?',
|
||||||
default=def_arg_output_dir, help='output file\'s location')
|
default=def_arg_output_dir, help='output file\'s location')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
mbedtls_root = os.path.abspath(args.mbedtls_root)
|
mbedtls_root = os.path.abspath(args.mbedtls_root)
|
||||||
output_directory = args.output_directory
|
output_directory = args.output_directory
|
||||||
|
template_directory = args.template_dir
|
||||||
|
json_directory = args.json_dir
|
||||||
|
|
||||||
generate_driver_wrapper_file(mbedtls_root, output_directory)
|
# load list of driver jsons from driverlist.json
|
||||||
|
merged_driverjson = merge_driverjsonfiles(json_directory, 'driverlist.json')
|
||||||
|
ret = validate_mergedjson(merged_driverjson)
|
||||||
|
if ret == 1:
|
||||||
|
print("Validation failed ")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
generate_driver_wrapper_file(template_directory, output_directory, merged_driverjson)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -20,6 +20,14 @@
|
|||||||
#ifndef PSA_CRYPTO_TEST_DRIVER_H
|
#ifndef PSA_CRYPTO_TEST_DRIVER_H
|
||||||
#define 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
|
#define PSA_CRYPTO_TEST_DRIVER_LOCATION 0x7fffff
|
||||||
|
|
||||||
#include "test/drivers/aead.h"
|
#include "test/drivers/aead.h"
|
||||||
@ -30,4 +38,5 @@
|
|||||||
#include "test/drivers/signature.h"
|
#include "test/drivers/signature.h"
|
||||||
#include "test/drivers/asymmetric_encryption.h"
|
#include "test/drivers/asymmetric_encryption.h"
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
#endif /* PSA_CRYPTO_TEST_DRIVER_H */
|
#endif /* PSA_CRYPTO_TEST_DRIVER_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user