PSoC64 Secure Boot Utilities Middleware Library 1.0
Key attributes

General Description

Macros

#define CY_P64_PSA_KEY_BITS_TOO_LARGE   ( (cy_p64_psa_key_bits_t) ( -1 ) )
 The maximum value of the type used to represent bit-sizes. More...
 
#define CY_P64_PSA_MAX_KEY_BITS   0xfff8U
 The maximum size of a key in bits. More...
 
#define CY_P64_PSA_CORE_KEY_ATTRIBUTES_INIT
 The initial value of the core key attributes. More...
 
#define CY_P64_PSA_KEY_ATTRIBUTES_INIT   { CY_P64_PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0 }
 The initial value of the key attributes.
 

Typedefs

typedef uint16_t cy_p64_psa_key_bits_t
 The type used internally for key sizes. More...
 
typedef uint16_t cy_p64_psa_key_attributes_flag_t
 A mask of flags that can be stored in key attributes. More...
 
typedef struct cy_p64_psa_key_attributes_s cy_p64_psa_key_attributes_t
 The type of a structure containing key attributes. More...
 
typedef struct cy_p64_psa_key_policy_s cy_p64_psa_key_policy_t
 The type of the key policy data structure. More...
 

Functions

static struct cy_p64_psa_key_attributes_s cy_p64_psa_key_attributes_init (void)
 Sets key attributes strcuture with initial value. More...
 
static void cy_p64_psa_set_key_id (cy_p64_psa_key_attributes_t *attributes, cy_p64_psa_key_id_t id)
 Sets key ID in key attributes strcuture. More...
 
static cy_p64_psa_key_id_t cy_p64_psa_get_key_id (const cy_p64_psa_key_attributes_t *attributes)
 Gets key ID from key attributes strcuture. More...
 
static void cy_p64_psa_set_key_lifetime (cy_p64_psa_key_attributes_t *attributes, cy_p64_psa_key_lifetime_t lifetime)
 Sets key lifetime in key attributes strcuture. More...
 
static cy_p64_psa_key_lifetime_t cy_p64_psa_get_key_lifetime (const cy_p64_psa_key_attributes_t *attributes)
 Gets key lifetime from key attributes strcuture. More...
 
static void cy_p64_psa_set_key_usage_flags (cy_p64_psa_key_attributes_t *attributes, cy_p64_psa_key_usage_t usage_flags)
 Sets key usage flags in key attributes strcuture. More...
 
static cy_p64_psa_key_usage_t cy_p64_psa_get_key_usage_flags (const cy_p64_psa_key_attributes_t *attributes)
 Gets key usage flags from key attributes strcuture. More...
 
static void cy_p64_psa_set_key_algorithm (cy_p64_psa_key_attributes_t *attributes, cy_p64_psa_algorithm_t alg)
 Sets key algorithm in key attributes strcuture. More...
 
static cy_p64_psa_algorithm_t cy_p64_psa_get_key_algorithm (const cy_p64_psa_key_attributes_t *attributes)
 Gets key algorithm from key attributes strcuture. More...
 
static void cy_p64_psa_set_key_type (cy_p64_psa_key_attributes_t *attributes, cy_p64_psa_key_type_t type)
 Sets key type in key attributes strcuture. More...
 
static cy_p64_psa_key_type_t cy_p64_psa_get_key_type (const cy_p64_psa_key_attributes_t *attributes)
 Gets key type from key attributes strcuture. More...
 
static void cy_p64_psa_set_key_bits (cy_p64_psa_key_attributes_t *attributes, size_t bits)
 Sets key length in bits in key attributes strcuture. More...
 
static size_t cy_p64_psa_get_key_bits (const cy_p64_psa_key_attributes_t *attributes)
 Gets key length in bits from key attributes strcuture. More...
 

Macro Definition Documentation

◆ CY_P64_PSA_KEY_BITS_TOO_LARGE

#define CY_P64_PSA_KEY_BITS_TOO_LARGE   ( (cy_p64_psa_key_bits_t) ( -1 ) )

The maximum value of the type used to represent bit-sizes.

This is used to mark an invalid key size.

◆ CY_P64_PSA_MAX_KEY_BITS

#define CY_P64_PSA_MAX_KEY_BITS   0xfff8U

The maximum size of a key in bits.

Currently defined as the maximum that can be represented, rounded down to a whole number of bytes. This is an uncast value so that it can be used in preprocessor conditionals.

◆ CY_P64_PSA_CORE_KEY_ATTRIBUTES_INIT

#define CY_P64_PSA_CORE_KEY_ATTRIBUTES_INIT
Value:
CY_P64_PSA_KEY_LIFETIME_VOLATILE, \
CY_P64_PSA_KEY_ID_INIT, \
CY_P64_PSA_KEY_POLICY_INIT, 0 }
#define CY_P64_PSA_KEY_TYPE_NONE
An invalid key type value.
Definition: cy_p64_psacrypto_values.h:291

The initial value of the core key attributes.

Typedef Documentation

◆ cy_p64_psa_key_bits_t

typedef uint16_t cy_p64_psa_key_bits_t

The type used internally for key sizes.

Public interfaces use size_t, but internally we use a smaller type.

◆ cy_p64_psa_key_attributes_flag_t

A mask of flags that can be stored in key attributes.

This type is also used internally to store flags in slots. Internal flags are defined in library/psa_crypto_core.h. Internal flags may have the same value as external flags if they are properly handled during key creation and in psa_get_key_attributes.

◆ cy_p64_psa_key_attributes_t

typedef struct cy_p64_psa_key_attributes_s cy_p64_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 location of the key in storage, indicated by its key identifier and its lifetime.
  • The key's policy, comprising usage flags and a specification of the permitted algorithm(s).
  • Information about the key itself: the key type and its size.
  • Implementations may define additional attributes.

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 can be 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, implementations may report values that are equivalent to the original one, but have a different encoding. For example, an implementation may use a more compact representation for types where many bit-patterns are invalid or not supported, and store all values that it does not support as a special marker value. In such an implementation, after setting an invalid value, the corresponding get function returns an invalid value which may not be the one that was originally stored.

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 cy_p64_psa_reset_key_attributes(). As an exception, calling cy_p64_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 cy_p64_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:

  • lifetime: CY_P64_PSA_KEY_LIFETIME_VOLATILE.
  • key identifier: 0 (which is not a valid key identifier).
  • type: 0 (meaning that the type is unspecified).
  • key size: 0 (meaning that the size is unspecified).
  • usage flags: 0 (which allows no usage except exporting a public key).
  • algorithm: 0 (which allows no cryptographic usage, but allows exporting).

A typical sequence to create a key is as follows:

  1. Create and initialize an attribute structure.
  2. If the key is persistent, call cy_p64_psa_set_key_id(). Also call cy_p64_psa_set_key_lifetime() to place the key in a non-default location.
  3. Set the key policy with cy_p64_psa_set_key_usage_flags() and cy_p64_psa_set_key_algorithm().
  4. Set the key type with cy_p64_psa_set_key_type(). Skip this step if copying an existing key with psa_copy_key().
  5. When generating a random key with cy_p64_psa_generate_key() or deriving a key with cy_p64_psa_key_derivation_output_key(), set the desired key size with cy_p64_psa_set_key_bits().
  6. Call a key creation function: cy_p64_psa_import_key(), cy_p64_psa_generate_key(), cy_p64_psa_key_derivation_output_key() or psa_copy_key(). This function reads the attribute structure, creates a key with these attributes, and outputs a handle to the newly created key.
  7. The attribute structure is now no longer necessary. You may call cy_p64_psa_reset_key_attributes(), although this is optional with the workflow presented here because the attributes currently defined in this specification do not require any additional resources beyond the structure itself.

A typical sequence to query a key's attributes is as follows:

  1. Call cy_p64_psa_get_key_attributes().
  2. Call psa_get_key_xxx functions to retrieve the attribute(s) that you are interested in.
  3. Call cy_p64_cy_p64_psa_reset_key_attributes() to free any resources that may be used by the attribute structure.

Once a key is created, it is impossible to change its attributes.

◆ cy_p64_psa_key_policy_t

typedef struct cy_p64_psa_key_policy_s cy_p64_psa_key_policy_t

The type of the key policy data structure.

This is an implementation-defined struct. Applications should not make any assumptions about the content of this structure except as directed by the documentation of a specific implementation.

Function Documentation

◆ cy_p64_psa_key_attributes_init()

static struct cy_p64_psa_key_attributes_s cy_p64_psa_key_attributes_init ( void  )
static

Sets key attributes strcuture with initial value.

Return values
/pcy_p64_psa_key_attributes_s structure

◆ cy_p64_psa_set_key_id()

static void cy_p64_psa_set_key_id ( cy_p64_psa_key_attributes_t attributes,
cy_p64_psa_key_id_t  id 
)
inlinestatic

Sets key ID in key attributes strcuture.

Parameters
[in]attributesKey attributes structure
[in]idKey ID

◆ cy_p64_psa_get_key_id()

static cy_p64_psa_key_id_t cy_p64_psa_get_key_id ( const cy_p64_psa_key_attributes_t attributes)
inlinestatic

Gets key ID from key attributes strcuture.

Parameters
[in]attributesKey attributes structure
Return values
KeyID

◆ cy_p64_psa_set_key_lifetime()

static void cy_p64_psa_set_key_lifetime ( cy_p64_psa_key_attributes_t attributes,
cy_p64_psa_key_lifetime_t  lifetime 
)
inlinestatic

Sets key lifetime in key attributes strcuture.

Parameters
[in]attributesKey attributes structure
[in]lifetimeKey lifetime

◆ cy_p64_psa_get_key_lifetime()

static cy_p64_psa_key_lifetime_t cy_p64_psa_get_key_lifetime ( const cy_p64_psa_key_attributes_t attributes)
inlinestatic

Gets key lifetime from key attributes strcuture.

Parameters
[in]attributesKey attributes structure
Return values
Keylifetime

◆ cy_p64_psa_set_key_usage_flags()

static void cy_p64_psa_set_key_usage_flags ( cy_p64_psa_key_attributes_t attributes,
cy_p64_psa_key_usage_t  usage_flags 
)
inlinestatic

Sets key usage flags in key attributes strcuture.

Parameters
[in]attributesKey attributes structure
[in]usage_flagsKey usage flags

◆ cy_p64_psa_get_key_usage_flags()

static cy_p64_psa_key_usage_t cy_p64_psa_get_key_usage_flags ( const cy_p64_psa_key_attributes_t attributes)
inlinestatic

Gets key usage flags from key attributes strcuture.

Parameters
[in]attributesKey attributes structure
Return values
Keyusage flags

◆ cy_p64_psa_set_key_algorithm()

static void cy_p64_psa_set_key_algorithm ( cy_p64_psa_key_attributes_t attributes,
cy_p64_psa_algorithm_t  alg 
)
inlinestatic

Sets key algorithm in key attributes strcuture.

Parameters
[in]attributesKey attributes structure
[in]algKey algorithm

◆ cy_p64_psa_get_key_algorithm()

static cy_p64_psa_algorithm_t cy_p64_psa_get_key_algorithm ( const cy_p64_psa_key_attributes_t attributes)
inlinestatic

Gets key algorithm from key attributes strcuture.

Parameters
[in]attributesKey attributes structure
Return values
Keyalgorithm

◆ cy_p64_psa_set_key_type()

static void cy_p64_psa_set_key_type ( cy_p64_psa_key_attributes_t attributes,
cy_p64_psa_key_type_t  type 
)
inlinestatic

Sets key type in key attributes strcuture.

Parameters
[in]attributesKey attributes structure
[in]typeKey type

◆ cy_p64_psa_get_key_type()

static cy_p64_psa_key_type_t cy_p64_psa_get_key_type ( const cy_p64_psa_key_attributes_t attributes)
inlinestatic

Gets key type from key attributes strcuture.

Parameters
[in]attributesKey attributes structure
Return values
Keytype

◆ cy_p64_psa_set_key_bits()

static void cy_p64_psa_set_key_bits ( cy_p64_psa_key_attributes_t attributes,
size_t  bits 
)
inlinestatic

Sets key length in bits in key attributes strcuture.

Parameters
[in]attributesKey attributes structure
[in]bitsKey length in bits

◆ cy_p64_psa_get_key_bits()

static size_t cy_p64_psa_get_key_bits ( const cy_p64_psa_key_attributes_t attributes)
inlinestatic

Gets key length in bits from key attributes strcuture.

Parameters
[in]attributesKey attributes structure
Return values
Keylength in bits