File indexing completed on 2025-08-27 09:43:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 #ifndef PSA_CRYPTO_STRUCT_H
0050 #define PSA_CRYPTO_STRUCT_H
0051 #include "mbedtls/private_access.h"
0052
0053 #ifdef __cplusplus
0054 extern "C" {
0055 #endif
0056
0057
0058
0059
0060
0061
0062
0063
0064 #include "psa/build_info.h"
0065
0066
0067
0068 #include "psa/crypto_driver_contexts_primitives.h"
0069
0070 struct psa_hash_operation_s {
0071 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0072 mbedtls_psa_client_handle_t handle;
0073 #else
0074
0075
0076
0077
0078
0079
0080 unsigned int MBEDTLS_PRIVATE(id);
0081 psa_driver_hash_context_t MBEDTLS_PRIVATE(ctx);
0082 #endif
0083 };
0084 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0085 #define PSA_HASH_OPERATION_INIT { 0 }
0086 #else
0087 #define PSA_HASH_OPERATION_INIT { 0, { 0 } }
0088 #endif
0089 static inline struct psa_hash_operation_s psa_hash_operation_init(void)
0090 {
0091 const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT;
0092 return v;
0093 }
0094
0095 struct psa_cipher_operation_s {
0096 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0097 mbedtls_psa_client_handle_t handle;
0098 #else
0099
0100
0101
0102
0103
0104
0105 unsigned int MBEDTLS_PRIVATE(id);
0106
0107 unsigned int MBEDTLS_PRIVATE(iv_required) : 1;
0108 unsigned int MBEDTLS_PRIVATE(iv_set) : 1;
0109
0110 uint8_t MBEDTLS_PRIVATE(default_iv_length);
0111
0112 psa_driver_cipher_context_t MBEDTLS_PRIVATE(ctx);
0113 #endif
0114 };
0115
0116 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0117 #define PSA_CIPHER_OPERATION_INIT { 0 }
0118 #else
0119 #define PSA_CIPHER_OPERATION_INIT { 0, 0, 0, 0, { 0 } }
0120 #endif
0121 static inline struct psa_cipher_operation_s psa_cipher_operation_init(void)
0122 {
0123 const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
0124 return v;
0125 }
0126
0127
0128
0129 #include "psa/crypto_driver_contexts_composites.h"
0130
0131 struct psa_mac_operation_s {
0132 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0133 mbedtls_psa_client_handle_t handle;
0134 #else
0135
0136
0137
0138
0139
0140
0141 unsigned int MBEDTLS_PRIVATE(id);
0142 uint8_t MBEDTLS_PRIVATE(mac_size);
0143 unsigned int MBEDTLS_PRIVATE(is_sign) : 1;
0144 psa_driver_mac_context_t MBEDTLS_PRIVATE(ctx);
0145 #endif
0146 };
0147
0148 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0149 #define PSA_MAC_OPERATION_INIT { 0 }
0150 #else
0151 #define PSA_MAC_OPERATION_INIT { 0, 0, 0, { 0 } }
0152 #endif
0153 static inline struct psa_mac_operation_s psa_mac_operation_init(void)
0154 {
0155 const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT;
0156 return v;
0157 }
0158
0159 struct psa_aead_operation_s {
0160 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0161 mbedtls_psa_client_handle_t handle;
0162 #else
0163
0164
0165
0166
0167
0168
0169 unsigned int MBEDTLS_PRIVATE(id);
0170
0171 psa_algorithm_t MBEDTLS_PRIVATE(alg);
0172 psa_key_type_t MBEDTLS_PRIVATE(key_type);
0173
0174 size_t MBEDTLS_PRIVATE(ad_remaining);
0175 size_t MBEDTLS_PRIVATE(body_remaining);
0176
0177 unsigned int MBEDTLS_PRIVATE(nonce_set) : 1;
0178 unsigned int MBEDTLS_PRIVATE(lengths_set) : 1;
0179 unsigned int MBEDTLS_PRIVATE(ad_started) : 1;
0180 unsigned int MBEDTLS_PRIVATE(body_started) : 1;
0181 unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1;
0182
0183 psa_driver_aead_context_t MBEDTLS_PRIVATE(ctx);
0184 #endif
0185 };
0186
0187 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0188 #define PSA_AEAD_OPERATION_INIT { 0 }
0189 #else
0190 #define PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } }
0191 #endif
0192 static inline struct psa_aead_operation_s psa_aead_operation_init(void)
0193 {
0194 const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT;
0195 return v;
0196 }
0197
0198
0199
0200 #include "psa/crypto_driver_contexts_key_derivation.h"
0201
0202 struct psa_key_derivation_s {
0203 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0204 mbedtls_psa_client_handle_t handle;
0205 #else
0206 psa_algorithm_t MBEDTLS_PRIVATE(alg);
0207 unsigned int MBEDTLS_PRIVATE(can_output_key) : 1;
0208 size_t MBEDTLS_PRIVATE(capacity);
0209 psa_driver_key_derivation_context_t MBEDTLS_PRIVATE(ctx);
0210 #endif
0211 };
0212
0213 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0214 #define PSA_KEY_DERIVATION_OPERATION_INIT { 0 }
0215 #else
0216
0217 #define PSA_KEY_DERIVATION_OPERATION_INIT { 0, 0, 0, { 0 } }
0218 #endif
0219 static inline struct psa_key_derivation_s psa_key_derivation_operation_init(
0220 void)
0221 {
0222 const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT;
0223 return v;
0224 }
0225
0226 struct psa_custom_key_parameters_s {
0227
0228 uint32_t flags;
0229 };
0230
0231
0232
0233
0234
0235
0236
0237
0238 #define PSA_CUSTOM_KEY_PARAMETERS_INIT { 0 }
0239
0240 #ifndef __cplusplus
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252 struct psa_key_production_parameters_s {
0253 uint32_t flags;
0254 uint8_t data[];
0255 };
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 #define PSA_KEY_PRODUCTION_PARAMETERS_INIT { 0 }
0266 #endif
0267
0268 struct psa_key_policy_s {
0269 psa_key_usage_t MBEDTLS_PRIVATE(usage);
0270 psa_algorithm_t MBEDTLS_PRIVATE(alg);
0271 psa_algorithm_t MBEDTLS_PRIVATE(alg2);
0272 };
0273 typedef struct psa_key_policy_s psa_key_policy_t;
0274
0275 #define PSA_KEY_POLICY_INIT { 0, 0, 0 }
0276 static inline struct psa_key_policy_s psa_key_policy_init(void)
0277 {
0278 const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT;
0279 return v;
0280 }
0281
0282
0283
0284 typedef uint16_t psa_key_bits_t;
0285
0286
0287 #define PSA_KEY_BITS_TOO_LARGE ((psa_key_bits_t) -1)
0288
0289
0290
0291
0292
0293 #define PSA_MAX_KEY_BITS 0xfff8
0294
0295 struct psa_key_attributes_s {
0296 #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
0297 psa_key_slot_number_t MBEDTLS_PRIVATE(slot_number);
0298 int MBEDTLS_PRIVATE(has_slot_number);
0299 #endif
0300 psa_key_type_t MBEDTLS_PRIVATE(type);
0301 psa_key_bits_t MBEDTLS_PRIVATE(bits);
0302 psa_key_lifetime_t MBEDTLS_PRIVATE(lifetime);
0303 psa_key_policy_t MBEDTLS_PRIVATE(policy);
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 mbedtls_svc_key_id_t MBEDTLS_PRIVATE(id);
0316 };
0317
0318 #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
0319 #define PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER 0, 0,
0320 #else
0321 #define PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER
0322 #endif
0323 #define PSA_KEY_ATTRIBUTES_INIT { PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER \
0324 PSA_KEY_TYPE_NONE, 0, \
0325 PSA_KEY_LIFETIME_VOLATILE, \
0326 PSA_KEY_POLICY_INIT, \
0327 MBEDTLS_SVC_KEY_ID_INIT }
0328
0329 static inline struct psa_key_attributes_s psa_key_attributes_init(void)
0330 {
0331 const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT;
0332 return v;
0333 }
0334
0335 static inline void psa_set_key_id(psa_key_attributes_t *attributes,
0336 mbedtls_svc_key_id_t key)
0337 {
0338 psa_key_lifetime_t lifetime = attributes->MBEDTLS_PRIVATE(lifetime);
0339
0340 attributes->MBEDTLS_PRIVATE(id) = key;
0341
0342 if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) {
0343 attributes->MBEDTLS_PRIVATE(lifetime) =
0344 PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
0345 PSA_KEY_LIFETIME_PERSISTENT,
0346 PSA_KEY_LIFETIME_GET_LOCATION(lifetime));
0347 }
0348 }
0349
0350 static inline mbedtls_svc_key_id_t psa_get_key_id(
0351 const psa_key_attributes_t *attributes)
0352 {
0353 return attributes->MBEDTLS_PRIVATE(id);
0354 }
0355
0356 #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
0357 static inline void mbedtls_set_key_owner_id(psa_key_attributes_t *attributes,
0358 mbedtls_key_owner_id_t owner)
0359 {
0360 attributes->MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(owner) = owner;
0361 }
0362 #endif
0363
0364 static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes,
0365 psa_key_lifetime_t lifetime)
0366 {
0367 attributes->MBEDTLS_PRIVATE(lifetime) = lifetime;
0368 if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) {
0369 #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
0370 attributes->MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(key_id) = 0;
0371 #else
0372 attributes->MBEDTLS_PRIVATE(id) = 0;
0373 #endif
0374 }
0375 }
0376
0377 static inline psa_key_lifetime_t psa_get_key_lifetime(
0378 const psa_key_attributes_t *attributes)
0379 {
0380 return attributes->MBEDTLS_PRIVATE(lifetime);
0381 }
0382
0383 static inline void psa_extend_key_usage_flags(psa_key_usage_t *usage_flags)
0384 {
0385 if (*usage_flags & PSA_KEY_USAGE_SIGN_HASH) {
0386 *usage_flags |= PSA_KEY_USAGE_SIGN_MESSAGE;
0387 }
0388
0389 if (*usage_flags & PSA_KEY_USAGE_VERIFY_HASH) {
0390 *usage_flags |= PSA_KEY_USAGE_VERIFY_MESSAGE;
0391 }
0392 }
0393
0394 static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
0395 psa_key_usage_t usage_flags)
0396 {
0397 psa_extend_key_usage_flags(&usage_flags);
0398 attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage) = usage_flags;
0399 }
0400
0401 static inline psa_key_usage_t psa_get_key_usage_flags(
0402 const psa_key_attributes_t *attributes)
0403 {
0404 return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage);
0405 }
0406
0407 static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes,
0408 psa_algorithm_t alg)
0409 {
0410 attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg) = alg;
0411 }
0412
0413 static inline psa_algorithm_t psa_get_key_algorithm(
0414 const psa_key_attributes_t *attributes)
0415 {
0416 return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg);
0417 }
0418
0419 static inline void psa_set_key_type(psa_key_attributes_t *attributes,
0420 psa_key_type_t type)
0421 {
0422 attributes->MBEDTLS_PRIVATE(type) = type;
0423 }
0424
0425 static inline psa_key_type_t psa_get_key_type(
0426 const psa_key_attributes_t *attributes)
0427 {
0428 return attributes->MBEDTLS_PRIVATE(type);
0429 }
0430
0431 static inline void psa_set_key_bits(psa_key_attributes_t *attributes,
0432 size_t bits)
0433 {
0434 if (bits > PSA_MAX_KEY_BITS) {
0435 attributes->MBEDTLS_PRIVATE(bits) = PSA_KEY_BITS_TOO_LARGE;
0436 } else {
0437 attributes->MBEDTLS_PRIVATE(bits) = (psa_key_bits_t) bits;
0438 }
0439 }
0440
0441 static inline size_t psa_get_key_bits(
0442 const psa_key_attributes_t *attributes)
0443 {
0444 return attributes->MBEDTLS_PRIVATE(bits);
0445 }
0446
0447
0448
0449
0450 struct psa_sign_hash_interruptible_operation_s {
0451 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0452 mbedtls_psa_client_handle_t handle;
0453 #else
0454
0455
0456
0457
0458
0459
0460 unsigned int MBEDTLS_PRIVATE(id);
0461
0462 psa_driver_sign_hash_interruptible_context_t MBEDTLS_PRIVATE(ctx);
0463
0464 unsigned int MBEDTLS_PRIVATE(error_occurred) : 1;
0465
0466 uint32_t MBEDTLS_PRIVATE(num_ops);
0467 #endif
0468 };
0469
0470 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0471 #define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
0472 #else
0473 #define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 }
0474 #endif
0475
0476 static inline struct psa_sign_hash_interruptible_operation_s
0477 psa_sign_hash_interruptible_operation_init(void)
0478 {
0479 const struct psa_sign_hash_interruptible_operation_s v =
0480 PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT;
0481
0482 return v;
0483 }
0484
0485
0486
0487
0488 struct psa_verify_hash_interruptible_operation_s {
0489 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0490 mbedtls_psa_client_handle_t handle;
0491 #else
0492
0493
0494
0495
0496
0497
0498 unsigned int MBEDTLS_PRIVATE(id);
0499
0500 psa_driver_verify_hash_interruptible_context_t MBEDTLS_PRIVATE(ctx);
0501
0502 unsigned int MBEDTLS_PRIVATE(error_occurred) : 1;
0503
0504 uint32_t MBEDTLS_PRIVATE(num_ops);
0505 #endif
0506 };
0507
0508 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
0509 #define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
0510 #else
0511 #define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 }
0512 #endif
0513
0514 static inline struct psa_verify_hash_interruptible_operation_s
0515 psa_verify_hash_interruptible_operation_init(void)
0516 {
0517 const struct psa_verify_hash_interruptible_operation_s v =
0518 PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT;
0519
0520 return v;
0521 }
0522
0523 #ifdef __cplusplus
0524 }
0525 #endif
0526
0527 #endif