mirror of
https://github.com/ARMmbed/mbedtls.git
synced 2025-05-11 17:32:34 +08:00
Initial empty driver wrapper implementation
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
1265f00494
commit
2d247923e5
@ -498,10 +498,18 @@ static inline size_t psa_get_key_bits(
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct psa_sign_hash_interruptible_operation_s {
|
struct psa_sign_hash_interruptible_operation_s {
|
||||||
|
/** Unique ID indicating which driver got assigned to do the
|
||||||
|
* operation. Since driver contexts are driver-specific, swapping
|
||||||
|
* drivers halfway through the operation is not supported.
|
||||||
|
* ID values are auto-generated in psa_crypto_driver_wrappers.h
|
||||||
|
* ID value zero means the context is not valid or not assigned to
|
||||||
|
* any driver (i.e. none of the driver contexts are active). */
|
||||||
|
unsigned int MBEDTLS_PRIVATE(id);
|
||||||
|
|
||||||
size_t MBEDTLS_PRIVATE(num_ops);
|
size_t MBEDTLS_PRIVATE(num_ops);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
|
#define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, 0 }
|
||||||
|
|
||||||
static inline struct psa_sign_hash_interruptible_operation_s
|
static inline struct psa_sign_hash_interruptible_operation_s
|
||||||
psa_sign_hash_interruptible_operation_init(void)
|
psa_sign_hash_interruptible_operation_init(void)
|
||||||
@ -519,10 +527,18 @@ psa_sign_hash_interruptible_operation_init(void)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct psa_verify_hash_interruptible_operation_s {
|
struct psa_verify_hash_interruptible_operation_s {
|
||||||
|
/** Unique ID indicating which driver got assigned to do the
|
||||||
|
* operation. Since driver contexts are driver-specific, swapping
|
||||||
|
* drivers halfway through the operation is not supported.
|
||||||
|
* ID values are auto-generated in psa_crypto_driver_wrappers.h
|
||||||
|
* ID value zero means the context is not valid or not assigned to
|
||||||
|
* any driver (i.e. none of the driver contexts are active). */
|
||||||
|
unsigned int MBEDTLS_PRIVATE(id);
|
||||||
|
|
||||||
size_t MBEDTLS_PRIVATE(num_ops);
|
size_t MBEDTLS_PRIVATE(num_ops);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
|
#define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, 0 }
|
||||||
|
|
||||||
static inline struct psa_verify_hash_interruptible_operation_s
|
static inline struct psa_verify_hash_interruptible_operation_s
|
||||||
psa_verify_hash_interruptible_operation_init(void)
|
psa_verify_hash_interruptible_operation_init(void)
|
||||||
|
@ -66,6 +66,47 @@ psa_status_t psa_driver_wrapper_verify_hash(
|
|||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
||||||
const uint8_t *signature, size_t signature_length);
|
const uint8_t *signature, size_t signature_length);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interruptible Signature functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
void psa_driver_wrapper_interruptible_set_max_ops(uint32_t max_ops);
|
||||||
|
|
||||||
|
uint32_t psa_driver_wrapper_interruptible_get_max_ops(void);
|
||||||
|
|
||||||
|
uint32_t psa_driver_wrapper_sign_hash_get_num_ops(
|
||||||
|
const psa_sign_hash_interruptible_operation_t *operation);
|
||||||
|
|
||||||
|
uint32_t psa_driver_wrapper_verify_hash_get_num_ops(
|
||||||
|
const psa_verify_hash_interruptible_operation_t *operation);
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_sign_hash_start(
|
||||||
|
psa_sign_hash_interruptible_operation_t *operation,
|
||||||
|
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
|
||||||
|
size_t key_buffer_size, psa_algorithm_t alg,
|
||||||
|
const uint8_t *hash, size_t hash_length);
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_sign_hash_complete(
|
||||||
|
psa_sign_hash_interruptible_operation_t *operation,
|
||||||
|
uint8_t *signature, size_t signature_size,
|
||||||
|
size_t *signature_length);
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_sign_hash_abort(
|
||||||
|
psa_sign_hash_interruptible_operation_t *operation);
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_verify_hash_start(
|
||||||
|
psa_verify_hash_interruptible_operation_t *operation,
|
||||||
|
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
|
||||||
|
size_t key_buffer_size, psa_algorithm_t alg,
|
||||||
|
const uint8_t *hash, size_t hash_length,
|
||||||
|
const uint8_t *signature, size_t signature_length);
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_verify_hash_complete(
|
||||||
|
psa_verify_hash_interruptible_operation_t *operation);
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_verify_hash_abort(
|
||||||
|
psa_verify_hash_interruptible_operation_t *operation);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key handling functions
|
* Key handling functions
|
||||||
*/
|
*/
|
||||||
|
@ -433,6 +433,242 @@ psa_status_t psa_driver_wrapper_verify_hash(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void psa_driver_wrapper_interruptible_set_max_ops( uint32_t max_ops )
|
||||||
|
{
|
||||||
|
( void ) max_ops;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t psa_driver_wrapper_interruptible_get_max_ops( void )
|
||||||
|
{
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t psa_driver_wrapper_sign_hash_get_num_ops(
|
||||||
|
const psa_sign_hash_interruptible_operation_t *operation )
|
||||||
|
{
|
||||||
|
switch( operation->id )
|
||||||
|
{
|
||||||
|
case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
}
|
||||||
|
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t psa_driver_wrapper_verify_hash_get_num_ops(
|
||||||
|
const psa_verify_hash_interruptible_operation_t *operation )
|
||||||
|
{
|
||||||
|
switch( operation->id )
|
||||||
|
{
|
||||||
|
case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
}
|
||||||
|
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_sign_hash_start(
|
||||||
|
psa_sign_hash_interruptible_operation_t *operation,
|
||||||
|
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
|
||||||
|
size_t key_buffer_size, psa_algorithm_t alg,
|
||||||
|
const uint8_t *hash, size_t hash_length )
|
||||||
|
{
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
psa_key_location_t location =
|
||||||
|
PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
||||||
|
|
||||||
|
switch( location )
|
||||||
|
{
|
||||||
|
case PSA_KEY_LOCATION_LOCAL_STORAGE:
|
||||||
|
/* 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)
|
||||||
|
|
||||||
|
/* Add test driver tests here */
|
||||||
|
|
||||||
|
/* Declared with fallback == true */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
|
||||||
|
/* Fell through, meaning no accelerator supports this operation */
|
||||||
|
operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Key is declared with a lifetime not known to us */
|
||||||
|
( void ) status;
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
( void ) operation;
|
||||||
|
( void ) key_buffer;
|
||||||
|
( void ) key_buffer_size;
|
||||||
|
( void ) alg;
|
||||||
|
( void ) hash;
|
||||||
|
( void ) hash_length;
|
||||||
|
|
||||||
|
return( status );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_sign_hash_complete(
|
||||||
|
psa_sign_hash_interruptible_operation_t *operation,
|
||||||
|
uint8_t *signature, size_t signature_size,
|
||||||
|
size_t *signature_length )
|
||||||
|
{
|
||||||
|
switch( operation->id )
|
||||||
|
{
|
||||||
|
case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
}
|
||||||
|
|
||||||
|
( void ) signature;
|
||||||
|
( void ) signature_size;
|
||||||
|
( void ) signature_length;
|
||||||
|
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_sign_hash_abort(
|
||||||
|
psa_sign_hash_interruptible_operation_t *operation )
|
||||||
|
{
|
||||||
|
switch( operation->id )
|
||||||
|
{
|
||||||
|
case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
}
|
||||||
|
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_verify_hash_start(
|
||||||
|
psa_verify_hash_interruptible_operation_t *operation,
|
||||||
|
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
|
||||||
|
size_t key_buffer_size, psa_algorithm_t alg,
|
||||||
|
const uint8_t *hash, size_t hash_length,
|
||||||
|
const uint8_t *signature, size_t signature_length )
|
||||||
|
{
|
||||||
|
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
psa_key_location_t location =
|
||||||
|
PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
||||||
|
|
||||||
|
switch( location )
|
||||||
|
{
|
||||||
|
case PSA_KEY_LOCATION_LOCAL_STORAGE:
|
||||||
|
/* 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)
|
||||||
|
|
||||||
|
/* Add test driver tests here */
|
||||||
|
|
||||||
|
/* Declared with fallback == true */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
|
||||||
|
/* Fell through, meaning no accelerator supports this operation */
|
||||||
|
operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Key is declared with a lifetime not known to us */
|
||||||
|
( void ) status;
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
( void ) operation;
|
||||||
|
( void ) key_buffer;
|
||||||
|
( void ) key_buffer_size;
|
||||||
|
( void ) alg;
|
||||||
|
( void ) hash;
|
||||||
|
( void ) hash_length;
|
||||||
|
( void ) signature;
|
||||||
|
( void ) signature_length;
|
||||||
|
|
||||||
|
return( status );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_verify_hash_complete(
|
||||||
|
psa_verify_hash_interruptible_operation_t *operation )
|
||||||
|
{
|
||||||
|
switch( operation->id )
|
||||||
|
{
|
||||||
|
case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
}
|
||||||
|
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_verify_hash_abort(
|
||||||
|
psa_verify_hash_interruptible_operation_t *operation )
|
||||||
|
{
|
||||||
|
switch( operation->id )
|
||||||
|
{
|
||||||
|
case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
case MBEDTLS_TEST_TRANSPARENT_DRIVER_ID:
|
||||||
|
|
||||||
|
/* Add cases for opaque driver here */
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
|
}
|
||||||
|
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
|
|
||||||
/** Calculate the key buffer size required to store the key material of a key
|
/** Calculate the key buffer size required to store the key material of a key
|
||||||
* associated with an opaque driver from input key data.
|
* associated with an opaque driver from input key data.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user