Loading...
Searching...
No Matches
crypto_struct.h File Reference

PSA cryptography module: Mbed TLS structured type implementations. More...

`#include "mbedtls/config.h"`
`#include "mbedtls/cmac.h"`
`#include "mbedtls/gcm.h"`
`#include "psa/crypto_driver_contexts_primitives.h"`
`#include "psa/crypto_driver_contexts_composites.h"`
Include dependency graph for crypto_struct.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | psa_hash_operation_s
struct | psa_cipher_operation_s
struct | psa_mac_operation_s
struct | psa_aead_operation_s
struct | psa_hkdf_key_derivation_t
struct | psa_tls12_prf_key_derivation_s
struct | psa_key_derivation_s
struct | psa_key_policy_s
struct | psa_core_key_attributes_t
struct | psa_key_attributes_s

## Macros

#define | PSA_HASH_OPERATION_INIT { 0, { 0 } }
#define | PSA_CIPHER_OPERATION_INIT { 0, 0, 0, 0, { 0 } }
#define | PSA_MAC_OPERATION_INIT { 0, 0, 0, { 0 } }
#define | PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, 0, { 0 } }
#define | PSA_KEY_DERIVATION_OPERATION_INIT { 0, 0, 0, { 0 } }
#define | PSA_KEY_POLICY_INIT { 0, 0, 0 }
#define | PSA_KEY_BITS_TOO_LARGE ((psa_key_bits_t) (-1))
#define | PSA_MAX_KEY_BITS 0xfff8
#define | MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER ((psa_key_attributes_flag_t) 0x0001)
#define | MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY
#define | MBEDTLS_PSA_KA_MASK_DUAL_USE
#define | PSA_CORE_KEY_ATTRIBUTES_INIT
#define | PSA_KEY_ATTRIBUTES_INIT { PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0 }

## Typedefs

typedef struct psa_tls12_prf_key_derivation_s | psa_tls12_prf_key_derivation_t
typedef struct psa_key_policy_s | psa_key_policy_t
typedef uint16_t | psa_key_bits_t
typedef uint16_t | psa_key_attributes_flag_t

## Enumerations

enum | psa_tls12_prf_key_derivation_state_t { PSA_TLS12_PRF_STATE_INIT , PSA_TLS12_PRF_STATE_SEED_SET , PSA_TLS12_PRF_STATE_KEY_SET , PSA_TLS12_PRF_STATE_LABEL_SET , PSA_TLS12_PRF_STATE_OUTPUT }

## Functions

static struct psa_hash_operation_s | psa_hash_operation_init (void)
static struct psa_cipher_operation_s | psa_cipher_operation_init (void)
static struct psa_mac_operation_s | psa_mac_operation_init (void)
static struct psa_aead_operation_s | psa_aead_operation_init (void)
static struct psa_key_derivation_s | psa_key_derivation_operation_init (void)
static struct psa_key_policy_s | psa_key_policy_init (void)
static struct psa_key_attributes_s | psa_key_attributes_init (void)
static void | psa_set_key_id (psa_key_attributes_t *attributes, mbedtls_svc_key_id_t key)
static mbedtls_svc_key_id_t | psa_get_key_id (const psa_key_attributes_t *attributes)
static void | psa_set_key_lifetime (psa_key_attributes_t *attributes, psa_key_lifetime_t lifetime)
static psa_key_lifetime_t | psa_get_key_lifetime (const psa_key_attributes_t *attributes)
static void | psa_extend_key_usage_flags (psa_key_usage_t *usage_flags)
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)
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)
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 void | psa_set_key_bits (psa_key_attributes_t *attributes, size_t bits)
static size_t | psa_get_key_bits (const psa_key_attributes_t *attributes)

## Detailed Description

PSA cryptography module: Mbed TLS structured type implementations.

Note
  This file may not be included directly. Applications must include psa/crypto.h.

This file contains the definitions of some data structures with implementation-specific definitions.

In implementations with isolation between the application and the cryptography module, it is expected that the front-end and the back-end would have different versions of this file.

### Design notes about multipart operation structures

For multipart operations without driver delegation support, each multipart operation structure contains a `psa_algorithm_t alg` field which indicates which specific algorithm the structure is for. When the structure is not in use, `alg` is 0. Most of the structure consists of a union which is discriminated by `alg`.

For multipart operations with driver delegation support, each multipart operation structure contains an `unsigned int id` field indicating which driver got assigned to do the operation. When the structure is not in use, 'id' is 0. The structure contains also a driver context which is the union of the contexts of all drivers able to handle the type of multipart operation.

Note that when `alg` or `id` is 0, the content of other fields is undefined. In particular, it is not guaranteed that a freshly-initialized structure is all-zero: we initialize structures to something like `{0, 0}`, which is only guaranteed to initializes the first member of the union; GCC and Clang initialize the whole structure to 0 (at the time of writing), but MSVC and CompCert don't.

In Mbed TLS, multipart operation structures live independently from the key. This allows Mbed TLS to free the key objects when destroying a key slot. If a multipart operation needs to remember the key after the setup function returns, the operation structure needs to contain a copy of the key.

Definition in file crypto_struct.h.

## Macro Definition Documentation

## MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER

#define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER ((psa_key_attributes_flag_t) 0x0001)

Definition at line 273 of file crypto_struct.h.

## MBEDTLS_PSA_KA_MASK_DUAL_USE

#define MBEDTLS_PSA_KA_MASK_DUAL_USE

Value:
( \
0)

Definition at line 284 of file crypto_struct.h.

## MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY

#define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY

Value:
( \
MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \
0)
MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER
#define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER
Definition crypto_struct.h:273

Definition at line 278 of file crypto_struct.h.

## PSA_CORE_KEY_ATTRIBUTES_INIT

#define PSA_CORE_KEY_ATTRIBUTES_INIT

Value:
{ PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, \
MBEDTLS_SVC_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0 }
PSA_KEY_POLICY_INIT
#define PSA_KEY_POLICY_INIT
Definition crypto_struct.h:244
PSA_KEY_TYPE_NONE
#define PSA_KEY_TYPE_NONE
Definition crypto_values.h:343
MBEDTLS_SVC_KEY_ID_INIT
#define MBEDTLS_SVC_KEY_ID_INIT
Definition crypto_values.h:2128
PSA_KEY_LIFETIME_VOLATILE
#define PSA_KEY_LIFETIME_VOLATILE
Definition crypto_values.h:1998

Definition at line 296 of file crypto_struct.h.

## PSA_KEY_BITS_TOO_LARGE

#define PSA_KEY_BITS_TOO_LARGE ((psa_key_bits_t) (-1))

Definition at line 256 of file crypto_struct.h.

## PSA_KEY_POLICY_INIT

#define PSA_KEY_POLICY_INIT { 0, 0, 0 }

Definition at line 244 of file crypto_struct.h.

## PSA_MAX_KEY_BITS

#define PSA_MAX_KEY_BITS 0xfff8

Definition at line 262 of file crypto_struct.h.

## Typedef Documentation

## psa_key_attributes_flag_t

typedef uint16_t 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.

Definition at line 271 of file crypto_struct.h.

## psa_key_bits_t

typedef uint16_t psa_key_bits_t

Definition at line 253 of file crypto_struct.h.

## psa_key_policy_t

typedef struct psa_key_policy_s psa_key_policy_t

Definition at line 242 of file crypto_struct.h.

## psa_tls12_prf_key_derivation_t

typedef struct psa_tls12_prf_key_derivation_s psa_tls12_prf_key_derivation_t

## Enumeration Type Documentation

## psa_tls12_prf_key_derivation_state_t

enum psa_tls12_prf_key_derivation_state_t

Enumerator
PSA_TLS12_PRF_STATE_INIT |
PSA_TLS12_PRF_STATE_SEED_SET |
PSA_TLS12_PRF_STATE_KEY_SET |
PSA_TLS12_PRF_STATE_LABEL_SET |
PSA_TLS12_PRF_STATE_OUTPUT |

Definition at line 175 of file crypto_struct.h.

## Function Documentation

## psa_aead_operation_init()

static struct psa_aead_operation_s psa_aead_operation_init | ( | void |  | ) |

inline static

Definition at line 150 of file crypto_struct.h.

References PSA_AEAD_OPERATION_INIT.

## psa_cipher_operation_init()

static struct psa_cipher_operation_s psa_cipher_operation_init | ( | void |  | ) |

inline static

Definition at line 107 of file crypto_struct.h.

References PSA_CIPHER_OPERATION_INIT.

## psa_extend_key_usage_flags()

static void psa_extend_key_usage_flags | ( | psa_key_usage_t * | usage_flags | ) |

inline static

Definition at line 368 of file crypto_struct.h.

References PSA_KEY_USAGE_SIGN_HASH, PSA_KEY_USAGE_SIGN_MESSAGE, PSA_KEY_USAGE_VERIFY_HASH, and PSA_KEY_USAGE_VERIFY_MESSAGE.

Referenced by psa_set_key_usage_flags().

## psa_get_key_algorithm()

static psa_algorithm_t psa_get_key_algorithm | ( | const psa_key_attributes_t * | attributes | ) |

inline static

Definition at line 398 of file crypto_struct.h.

References psa_key_policy_s::alg, psa_key_attributes_s::core, and psa_core_key_attributes_t::policy.

## psa_get_key_bits()

static size_t psa_get_key_bits | ( | const psa_key_attributes_t * | attributes | ) |

inline static

Definition at line 442 of file crypto_struct.h.

References psa_core_key_attributes_t::bits, and psa_key_attributes_s::core.

## psa_get_key_id()

static mbedtls_svc_key_id_t psa_get_key_id | ( | const psa_key_attributes_t * | attributes | ) |

inline static

Definition at line 335 of file crypto_struct.h.

References psa_key_attributes_s::core, and psa_core_key_attributes_t::id.

## psa_get_key_lifetime()

static psa_key_lifetime_t psa_get_key_lifetime | ( | const psa_key_attributes_t * | attributes | ) |

inline static

Definition at line 362 of file crypto_struct.h.

References psa_key_attributes_s::core, and psa_core_key_attributes_t::lifetime.

## psa_get_key_type()

static psa_key_type_t psa_get_key_type | ( | const psa_key_attributes_t * | attributes | ) |

inline static

Definition at line 426 of file crypto_struct.h.

References psa_key_attributes_s::core, and psa_core_key_attributes_t::type.

## psa_get_key_usage_flags()

static psa_key_usage_t psa_get_key_usage_flags | ( | const psa_key_attributes_t * | attributes | ) |

inline static

Definition at line 386 of file crypto_struct.h.

References psa_key_attributes_s::core, psa_core_key_attributes_t::policy, and psa_key_policy_s::usage.

## psa_hash_operation_init()

static struct psa_hash_operation_s psa_hash_operation_init | ( | void |  | ) |

inline static

Definition at line 83 of file crypto_struct.h.

References PSA_HASH_OPERATION_INIT.

## psa_key_attributes_init()

static struct psa_key_attributes_s psa_key_attributes_init | ( | void |  | ) |

inline static

Definition at line 314 of file crypto_struct.h.

References PSA_KEY_ATTRIBUTES_INIT.

## psa_key_derivation_operation_init()

static struct psa_key_derivation_s psa_key_derivation_operation_init | ( | void |  | ) |

inline static

Definition at line 231 of file crypto_struct.h.

References PSA_KEY_DERIVATION_OPERATION_INIT.

## psa_key_policy_init()

static struct psa_key_policy_s psa_key_policy_init | ( | void |  | ) |

inline static

Definition at line 245 of file crypto_struct.h.

References PSA_KEY_POLICY_INIT.

## psa_mac_operation_init()

static struct psa_mac_operation_s psa_mac_operation_init | ( | void |  | ) |

inline static

Definition at line 131 of file crypto_struct.h.

References PSA_MAC_OPERATION_INIT.

## psa_set_key_algorithm()

static void psa_set_key_algorithm | ( | psa_key_attributes_t * | attributes,
|  | psa_algorithm_t | alg
| ) |  |

inline static

Definition at line 392 of file crypto_struct.h.

References psa_key_policy_s::alg, psa_key_attributes_s::core, and psa_core_key_attributes_t::policy.

## psa_set_key_bits()

static void psa_set_key_bits | ( | psa_key_attributes_t * | attributes,
|  | size_t | bits
| ) |  |

inline static

Definition at line 432 of file crypto_struct.h.

References psa_core_key_attributes_t::bits, psa_key_attributes_s::core, PSA_KEY_BITS_TOO_LARGE, and PSA_MAX_KEY_BITS.

## psa_set_key_domain_parameters()

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
| ) |  |

Referenced by psa_set_key_type().

## psa_set_key_id()

static void psa_set_key_id | ( | psa_key_attributes_t * | attributes,
|  | mbedtls_svc_key_id_t | key
| ) |  |

inline static

Definition at line 320 of file crypto_struct.h.

References psa_key_attributes_s::core, psa_core_key_attributes_t::id, psa_core_key_attributes_t::lifetime, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION, PSA_KEY_LIFETIME_GET_LOCATION, PSA_KEY_LIFETIME_IS_VOLATILE, and PSA_KEY_LIFETIME_PERSISTENT.

## psa_set_key_lifetime()

static void psa_set_key_lifetime | ( | psa_key_attributes_t * | attributes,
|  | psa_key_lifetime_t | lifetime
| ) |  |

inline static

Definition at line 349 of file crypto_struct.h.

References psa_key_attributes_s::core, psa_core_key_attributes_t::id, psa_core_key_attributes_t::lifetime, and PSA_KEY_LIFETIME_IS_VOLATILE.

## psa_set_key_type()

static void psa_set_key_type | ( | psa_key_attributes_t * | attributes,
|  | psa_key_type_t | type
| ) |  |

inline static

Definition at line 411 of file crypto_struct.h.

References psa_key_attributes_s::core, psa_key_attributes_s::domain_parameters, psa_set_key_domain_parameters(), and psa_core_key_attributes_t::type.

## psa_set_key_usage_flags()

static void psa_set_key_usage_flags | ( | psa_key_attributes_t * | attributes,
|  | psa_key_usage_t | usage_flags
| ) |  |

inline static

Definition at line 379 of file crypto_struct.h.

References psa_key_attributes_s::core, psa_core_key_attributes_t::policy, psa_extend_key_usage_flags(), and psa_key_policy_s::usage.