mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Implement atomic-creation psa_import_key
Implement the new, attribute-based psa_import_key and some basic functions to access psa_key_attributes_t. Replace psa_import_key_to_handle by psa_import_key in a few test functions. This commit does not handle persistence attributes yet.
This commit is contained in:
@@ -109,6 +109,39 @@ psa_status_t psa_crypto_init(void);
|
||||
*/
|
||||
typedef struct psa_key_attributes_s psa_key_attributes_t;
|
||||
|
||||
static void psa_make_key_persistent(psa_key_attributes_t *attributes,
|
||||
psa_key_id_t id,
|
||||
psa_key_lifetime_t lifetime);
|
||||
|
||||
static psa_key_id_t psa_get_key_id(const psa_key_attributes_t *attributes);
|
||||
|
||||
static psa_key_lifetime_t psa_get_key_lifetime(
|
||||
const psa_key_attributes_t *attributes);
|
||||
|
||||
static void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
|
||||
psa_key_usage_t usage_flags);
|
||||
|
||||
static psa_key_usage_t psa_get_key_usage_flags(
|
||||
const psa_key_attributes_t *attributes);
|
||||
|
||||
static void psa_set_key_algorithm(psa_key_attributes_t *attributes,
|
||||
psa_algorithm_t alg);
|
||||
|
||||
static psa_algorithm_t psa_get_key_algorithm(
|
||||
const psa_key_attributes_t *attributes);
|
||||
|
||||
static void psa_set_key_type(psa_key_attributes_t *attributes,
|
||||
psa_key_type_t type);
|
||||
|
||||
static psa_key_type_t psa_get_key_type(const psa_key_attributes_t *attributes);
|
||||
|
||||
static size_t psa_get_key_bits(const psa_key_attributes_t *attributes);
|
||||
|
||||
psa_status_t psa_get_key_attributes(psa_key_handle_t handle,
|
||||
psa_key_attributes_t *attributes);
|
||||
|
||||
psa_status_t psa_reset_key_attributes(psa_key_attributes_t *attributes);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup policy Key policies
|
||||
@@ -380,7 +413,6 @@ psa_status_t psa_close_key(psa_key_handle_t handle);
|
||||
*/
|
||||
psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
|
||||
psa_key_handle_t *handle,
|
||||
psa_key_type_t type,
|
||||
const uint8_t *data,
|
||||
size_t data_length);
|
||||
|
||||
@@ -2970,7 +3002,6 @@ psa_status_t psa_generator_read(psa_crypto_generator_t *generator,
|
||||
*/
|
||||
psa_status_t psa_generator_import_key(const psa_key_attributes_t *attributes,
|
||||
psa_key_handle_t *handle,
|
||||
psa_key_type_t type,
|
||||
size_t bits,
|
||||
psa_crypto_generator_t *generator);
|
||||
|
||||
@@ -3363,7 +3394,6 @@ typedef struct {
|
||||
*/
|
||||
psa_status_t psa_generate_key(const psa_key_attributes_t *attributes,
|
||||
psa_key_handle_t *handle,
|
||||
psa_key_type_t type,
|
||||
size_t bits,
|
||||
const void *extra,
|
||||
size_t extra_size);
|
||||
|
@@ -260,4 +260,56 @@ static inline struct psa_key_policy_s psa_key_policy_init( void )
|
||||
return( v );
|
||||
}
|
||||
|
||||
struct psa_key_attributes_s
|
||||
{
|
||||
psa_key_id_t id;
|
||||
psa_key_lifetime_t lifetime;
|
||||
psa_key_policy_t policy;
|
||||
psa_key_type_t type;
|
||||
size_t bits;
|
||||
};
|
||||
|
||||
#define PSA_KEY_ATTRIBUTES_INIT {0, 0, {0, 0}, 0, 0}
|
||||
static inline struct psa_key_attributes_s psa_key_attributes_init( void )
|
||||
{
|
||||
const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT;
|
||||
return( v );
|
||||
}
|
||||
|
||||
static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
|
||||
psa_key_usage_t usage_flags)
|
||||
{
|
||||
attributes->policy.usage = usage_flags;
|
||||
}
|
||||
|
||||
static inline psa_key_usage_t psa_get_key_usage_flags(
|
||||
const psa_key_attributes_t *attributes)
|
||||
{
|
||||
return( attributes->policy.usage );
|
||||
}
|
||||
|
||||
static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes,
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
attributes->policy.alg = alg;
|
||||
}
|
||||
|
||||
static inline psa_algorithm_t psa_get_key_algorithm(
|
||||
const psa_key_attributes_t *attributes)
|
||||
{
|
||||
return( attributes->policy.alg );
|
||||
}
|
||||
|
||||
static inline void psa_set_key_type(psa_key_attributes_t *attributes,
|
||||
psa_key_type_t type)
|
||||
{
|
||||
attributes->type = type;
|
||||
}
|
||||
|
||||
static inline psa_key_type_t psa_get_key_type(
|
||||
const psa_key_attributes_t *attributes)
|
||||
{
|
||||
return( attributes->type );
|
||||
}
|
||||
|
||||
#endif /* PSA_CRYPTO_STRUCT_H */
|
||||
|
Reference in New Issue
Block a user