mbed TLS v3.1.0
|
Macros | |
#define | PSA_KEY_ATTRIBUTES_INIT { PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0 } |
#define | PSA_DH_FAMILY_CUSTOM ((psa_dh_family_t) 0x7e) |
#define | PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) |
#define | PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 3 /*without optional parts*/) |
#define | PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 2 /*p, g*/ + 34 /*q*/) |
Typedefs | |
typedef struct psa_key_attributes_s | psa_key_attributes_t |
typedef uint64_t | psa_key_slot_number_t |
#define PSA_DH_FAMILY_CUSTOM ((psa_dh_family_t) 0x7e) |
Custom Diffie-Hellman group.
For keys of type PSA_KEY_TYPE_DH_PUBLIC_KEY(PSA_DH_FAMILY_CUSTOM) or PSA_KEY_TYPE_DH_KEY_PAIR(PSA_DH_FAMILY_CUSTOM), the group data comes from domain parameters set by psa_set_key_domain_parameters().
Definition at line 433 of file crypto_extra.h.
#define PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE | ( | key_bits | ) | (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 3 /*without optional parts*/) |
Definition at line 566 of file crypto_extra.h.
#define PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE | ( | key_bits | ) | (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 2 /*p, g*/ + 34 /*q*/) |
Definition at line 568 of file crypto_extra.h.
#define PSA_KEY_ATTRIBUTES_INIT { PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0 } |
This macro returns a suitable initializer for a key attribute structure of type psa_key_attributes_t.
Definition at line 348 of file crypto_struct.h.
Referenced by psa_key_attributes_init().
#define PSA_KEY_DOMAIN_PARAMETERS_SIZE | ( | key_type, | |
key_bits | |||
) |
Safe output buffer size for psa_get_key_domain_parameters().
This macro returns a compile-time constant if its arguments are compile-time constants.
key_type | A supported key type. |
key_bits | The size of the key in bits. |
Definition at line 561 of file crypto_extra.h.
typedef struct psa_key_attributes_s psa_key_attributes_t |
The type of a structure containing key attributes.
This is an opaque structure that can represent the metadata of a key object. Metadata that can be stored in attributes includes:
The actual key material is not considered an attribute of a key. Key attributes do not contain information that is generally considered highly confidential.
An attribute structure works like a simple data structure where each function psa_set_key_xxx
sets a field and the corresponding function psa_get_key_xxx
retrieves the value of the corresponding field. However, a future version of the library may report values that are equivalent to the original one, but have a different encoding. Invalid values may be mapped to different, also invalid values.
An attribute structure may contain references to auxiliary resources, for example pointers to allocated memory or indirect references to pre-calculated values. In order to free such resources, the application must call psa_reset_key_attributes(). As an exception, calling psa_reset_key_attributes() on an attribute structure is optional if the structure has only been modified by the following functions since it was initialized or last reset with psa_reset_key_attributes():
Before calling any function on a key attribute structure, the application must initialize it by any of the following means:
A freshly initialized attribute structure contains the following values:
0
(meaning that the type is unspecified).0
(meaning that the size is unspecified).0
(which allows no usage except exporting a public key).0
(which allows no cryptographic usage, but allows exporting).A typical sequence to create a key is as follows:
A typical sequence to query a key's attributes is as follows:
psa_get_key_xxx
functions to retrieve the attribute(s) that you are interested in.Once a key has been created, it is impossible to change its attributes.
Definition at line 360 of file crypto_types.h.
typedef uint64_t psa_key_slot_number_t |
Definition at line 369 of file crypto_types.h.
psa_status_t mbedtls_psa_register_se_key | ( | const psa_key_attributes_t * | attributes | ) |
Register a key that is already present in a secure element.
The key must be located in a secure element designated by the lifetime field in attributes
, in the slot set with psa_set_key_slot_number() in the attribute structure. This function makes the key available through the key identifier specified in attributes
.
[in] | attributes | The attributes of the existing key. |
PSA_SUCCESS | The key was successfully registered. Note that depending on the design of the driver, this may or may not guarantee that a key actually exists in the designated slot and is compatible with the specified attributes. |
PSA_ERROR_ALREADY_EXISTS | There is already a key with the identifier specified in attributes . |
PSA_ERROR_NOT_SUPPORTED | The secure element driver for the specified lifetime does not support registering a key. |
PSA_ERROR_INVALID_ARGUMENT | The identifier in attributes is invalid, namely the identifier is not in the user range. |
PSA_ERROR_INVALID_ARGUMENT | attributes specifies a lifetime which is not located in a secure element. |
PSA_ERROR_INVALID_ARGUMENT | No slot number is specified in attributes , or the specified slot number is not valid. |
PSA_ERROR_NOT_PERMITTED | The caller is not authorized to register the specified key slot. |
PSA_ERROR_INSUFFICIENT_MEMORY | |
PSA_ERROR_INSUFFICIENT_STORAGE | |
PSA_ERROR_COMMUNICATION_FAILURE | |
PSA_ERROR_DATA_INVALID | |
PSA_ERROR_DATA_CORRUPT | |
PSA_ERROR_CORRUPTION_DETECTED | |
PSA_ERROR_BAD_STATE | The library has not been previously initialized by psa_crypto_init(). It is implementation-dependent whether a failure to initialize results in this error code. |
|
static |
Set the owner identifier of a key.
When key identifiers encode key owner identifiers, psa_set_key_id() does not allow to define in key attributes the owner of volatile keys as psa_set_key_id() enforces the key to be persistent.
This function allows to set in key attributes the owner identifier of a key. It is intended to be used for volatile keys. For persistent keys, it is recommended to use the PSA Cryptography API psa_set_key_id() to define the owner of a key.
[out] | attributes | The attribute structure to write to. |
owner | The key owner identifier. |
|
inlinestatic |
Remove the slot number attribute from a key attribute structure.
This function undoes the action of psa_set_key_slot_number().
[out] | attributes | The attribute structure to write to. |
Definition at line 156 of file crypto_extra.h.
References MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER.
|
static |
Retrieve the algorithm policy from key attributes.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
[in] | attributes | The key attribute structure to query. |
psa_status_t psa_get_key_attributes | ( | mbedtls_svc_key_id_t | key, |
psa_key_attributes_t * | attributes | ||
) |
Retrieve the attributes of a key.
This function first resets the attribute structure as with psa_reset_key_attributes(). It then copies the attributes of the given key into the given attribute structure.
[in] | key | Identifier of the key to query. |
[in,out] | attributes | On success, the attributes of the key. On failure, equivalent to a freshly-initialized structure. |
PSA_SUCCESS | |
PSA_ERROR_INVALID_HANDLE | |
PSA_ERROR_INSUFFICIENT_MEMORY | |
PSA_ERROR_COMMUNICATION_FAILURE | |
PSA_ERROR_CORRUPTION_DETECTED | |
PSA_ERROR_STORAGE_FAILURE | |
PSA_ERROR_DATA_CORRUPT | |
PSA_ERROR_DATA_INVALID | |
PSA_ERROR_BAD_STATE | The library has not been previously initialized by psa_crypto_init(). It is implementation-dependent whether a failure to initialize results in this error code. |
|
static |
Retrieve the key size from key attributes.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
[in] | attributes | The key attribute structure to query. |
psa_status_t psa_get_key_domain_parameters | ( | const psa_key_attributes_t * | attributes, |
uint8_t * | data, | ||
size_t | data_size, | ||
size_t * | data_length | ||
) |
Get domain parameters for a key.
Get the domain parameters for a key with this function, if any. The format of the domain parameters written to data
is specified in the documentation for psa_set_key_domain_parameters().
[in] | attributes | The key attribute structure to query. |
[out] | data | On success, the key domain parameters. |
data_size | Size of the data buffer in bytes. The buffer is guaranteed to be large enough if its size in bytes is at least the value given by PSA_KEY_DOMAIN_PARAMETERS_SIZE(). | |
[out] | data_length | On success, the number of bytes that make up the key domain parameters data. |
PSA_SUCCESS | |
PSA_ERROR_BUFFER_TOO_SMALL |
|
inlinestatic |
Retrieve the enrollment algorithm policy from key attributes.
[in] | attributes | The key attribute structure to query. |
Definition at line 85 of file crypto_extra.h.
|
static |
Retrieve the key identifier from key attributes.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
[in] | attributes | The key attribute structure to query. |
|
static |
Retrieve the lifetime from key attributes.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
[in] | attributes | The key attribute structure to query. |
psa_status_t psa_get_key_slot_number | ( | const psa_key_attributes_t * | attributes, |
psa_key_slot_number_t * | slot_number | ||
) |
Retrieve the slot number where a key is stored.
A slot number is only defined for keys that are stored in a secure element.
This information is only useful if the secure element is not entirely managed through the PSA Cryptography API. It is up to the secure element driver to decide how PSA slot numbers map to any other interface that the secure element may have.
[in] | attributes | The key attribute structure to query. |
[out] | slot_number | On success, the slot number containing the key. |
PSA_SUCCESS | The key is located in a secure element, and *slot_number indicates the slot number that contains it. |
PSA_ERROR_NOT_PERMITTED | The caller is not permitted to query the slot number. Mbed Crypto currently does not return this error. |
PSA_ERROR_INVALID_ARGUMENT | The key is not located in a secure element. |
|
static |
Retrieve the key type from key attributes.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
[in] | attributes | The key attribute structure to query. |
|
static |
Retrieve the usage flags from key attributes.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
[in] | attributes | The key attribute structure to query. |
|
static |
Return an initial value for a key attributes structure.
void psa_reset_key_attributes | ( | psa_key_attributes_t * | attributes | ) |
Reset a key attribute structure to a freshly initialized state.
You must initialize the attribute structure as described in the documentation of the type psa_key_attributes_t before calling this function. Once the structure has been initialized, you may call this function at any time.
This function frees any auxiliary resources that the structure may contain.
[in,out] | attributes | The attribute structure to reset. |
|
static |
Declare the permitted algorithm policy for a key.
The permitted algorithm policy of a key encodes which algorithm or algorithms are permitted to be used with this key. The following algorithm policies are supported:
This function overwrites any algorithm policy previously set in attributes
.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
[out] | attributes | The attribute structure to write to. |
alg | The permitted algorithm policy to write. |
|
static |
Declare the size of a key.
This function overwrites any key size previously set in attributes
.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
[out] | attributes | The attribute structure to write to. |
bits | The key size in bits. If this is 0, the key size in attributes becomes unspecified. Keys of size 0 are not supported. |
psa_status_t psa_set_key_domain_parameters | ( | psa_key_attributes_t * | attributes, |
psa_key_type_t | type, | ||
const uint8_t * | data, | ||
size_t | data_length | ||
) |
Set domain parameters for a key.
Some key types require additional domain parameters in addition to the key type identifier and the key size. Use this function instead of psa_set_key_type() when you need to specify domain parameters.
The format for the required domain parameters varies based on the key type.
Dss-Parms
format as defined by RFC 3279 §2.3.2. ``` Dss-Parms ::= SEQUENCE { p INTEGER, q INTEGER, g INTEGER } ```DomainParameters
format as defined by RFC 3279 §2.3.3. ``` DomainParameters ::= SEQUENCE { p INTEGER, – odd prime, p=jq +1 g INTEGER, – generator, g q INTEGER, – factor of p-1 j INTEGER OPTIONAL, – subgroup factor validationParms ValidationParms OPTIONAL } ValidationParms ::= SEQUENCE { seed BIT STRING, pgenCounter INTEGER } ```[in,out] | attributes | Attribute structure where the specified domain parameters will be stored. If this function fails, the content of attributes is not modified. |
type | Key type (a PSA_KEY_TYPE_XXX value). | |
[in] | data | Buffer containing the key domain parameters. The content of this buffer is interpreted according to type as described above. |
data_length | Size of the data buffer in bytes. |
|
inlinestatic |
Declare the enrollment algorithm for a key.
An operation on a key may indifferently use the algorithm set with psa_set_key_algorithm() or with this function.
[out] | attributes | The attribute structure to write to. |
alg2 | A second algorithm that the key may be used for, in addition to the algorithm set with psa_set_key_algorithm(). |
Definition at line 72 of file crypto_extra.h.
|
static |
Declare a key as persistent and set its key identifier.
If the attribute structure currently declares the key as volatile (which is the default content of an attribute structure), this function sets the lifetime attribute to PSA_KEY_LIFETIME_PERSISTENT.
This function does not access storage, it merely stores the given value in the structure. The persistent key will be written to storage when the attribute structure is passed to a key creation function such as psa_import_key(), psa_generate_key(), psa_key_derivation_output_key() or psa_copy_key().
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
[out] | attributes | The attribute structure to write to. |
key | The persistent identifier for the key. |
|
static |
Set the location of a persistent key.
To make a key persistent, you must give it a persistent key identifier with psa_set_key_id(). By default, a key that has a persistent identifier is stored in the default storage area identifier by PSA_KEY_LIFETIME_PERSISTENT. Call this function to choose a storage area, or to explicitly declare the key as volatile.
This function does not access storage, it merely stores the given value in the structure. The persistent key will be written to storage when the attribute structure is passed to a key creation function such as psa_import_key(), psa_generate_key(), psa_key_derivation_output_key() or psa_copy_key().
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
[out] | attributes | The attribute structure to write to. |
lifetime | The lifetime for the key. If this is PSA_KEY_LIFETIME_VOLATILE, the key will be volatile, and the key identifier attribute is reset to 0. |
|
inlinestatic |
Choose the slot number where a key is stored.
This function declares a slot number in the specified attribute structure.
A slot number is only meaningful for keys that are stored in a secure element. It is up to the secure element driver to decide how PSA slot numbers map to any other interface that the secure element may have.
[out] | attributes | The attribute structure to write to. |
slot_number | The slot number to set. |
Definition at line 142 of file crypto_extra.h.
References MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER.
|
static |
Declare the type of a key.
This function overwrites any key type previously set in attributes
.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
[out] | attributes | The attribute structure to write to. |
type | The key type to write. If this is 0, the key type in attributes becomes unspecified. |
|
static |
Declare usage flags for a key.
Usage flags are part of a key's usage policy. They encode what kind of operations are permitted on the key. For more details, refer to the documentation of the type psa_key_usage_t.
This function overwrites any usage flags previously set in attributes
.
This function may be declared as static
(i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
[out] | attributes | The attribute structure to write to. |
usage_flags | The usage flags to write. |