Path: blob/master/thirdparty/mbedtls/include/psa/crypto_builtin_composites.h
9904 views
/*1* Context structure declaration of the Mbed TLS software-based PSA drivers2* called through the PSA Crypto driver dispatch layer.3* This file contains the context structures of those algorithms which need to4* rely on other algorithms, i.e. are 'composite' algorithms.5*6* \note This file may not be included directly. Applications must7* include psa/crypto.h.8*9* \note This header and its content are not part of the Mbed TLS API and10* applications must not depend on it. Its main purpose is to define the11* multi-part state objects of the Mbed TLS software-based PSA drivers. The12* definitions of these objects are then used by crypto_struct.h to define the13* implementation-defined types of PSA multi-part state objects.14*/15/*16* Copyright The Mbed TLS Contributors17* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later18*/1920#ifndef PSA_CRYPTO_BUILTIN_COMPOSITES_H21#define PSA_CRYPTO_BUILTIN_COMPOSITES_H22#include "mbedtls/private_access.h"2324#include <psa/crypto_driver_common.h>2526#include "mbedtls/cmac.h"27#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)28#include "mbedtls/gcm.h"29#endif30#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)31#include "mbedtls/ccm.h"32#endif33#include "mbedtls/chachapoly.h"3435/*36* MAC multi-part operation definitions.37*/38#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \39defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)40#define MBEDTLS_PSA_BUILTIN_MAC41#endif4243#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)44typedef struct {45/** The HMAC algorithm in use */46psa_algorithm_t MBEDTLS_PRIVATE(alg);47/** The hash context. */48struct psa_hash_operation_s hash_ctx;49/** The HMAC part of the context. */50uint8_t MBEDTLS_PRIVATE(opad)[PSA_HMAC_MAX_HASH_BLOCK_SIZE];51} mbedtls_psa_hmac_operation_t;5253#define MBEDTLS_PSA_HMAC_OPERATION_INIT { 0, PSA_HASH_OPERATION_INIT, { 0 } }54#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */5556typedef struct {57psa_algorithm_t MBEDTLS_PRIVATE(alg);58union {59unsigned MBEDTLS_PRIVATE(dummy); /* Make the union non-empty even with no supported algorithms. */60#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)61mbedtls_psa_hmac_operation_t MBEDTLS_PRIVATE(hmac);62#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */63#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || defined(PSA_CRYPTO_DRIVER_TEST)64mbedtls_cipher_context_t MBEDTLS_PRIVATE(cmac);65#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */66} MBEDTLS_PRIVATE(ctx);67} mbedtls_psa_mac_operation_t;6869#define MBEDTLS_PSA_MAC_OPERATION_INIT { 0, { 0 } }7071#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM) || \72defined(MBEDTLS_PSA_BUILTIN_ALG_CCM) || \73defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)74#define MBEDTLS_PSA_BUILTIN_AEAD 175#endif7677/* Context structure for the Mbed TLS AEAD implementation. */78typedef struct {79psa_algorithm_t MBEDTLS_PRIVATE(alg);80psa_key_type_t MBEDTLS_PRIVATE(key_type);8182unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1;8384uint8_t MBEDTLS_PRIVATE(tag_length);8586union {87unsigned dummy; /* Enable easier initializing of the union. */88#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)89mbedtls_ccm_context MBEDTLS_PRIVATE(ccm);90#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */91#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)92mbedtls_gcm_context MBEDTLS_PRIVATE(gcm);93#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */94#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)95mbedtls_chachapoly_context MBEDTLS_PRIVATE(chachapoly);96#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */9798} ctx;99100} mbedtls_psa_aead_operation_t;101102#define MBEDTLS_PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, { 0 } }103104#include "mbedtls/ecdsa.h"105106/* Context structure for the Mbed TLS interruptible sign hash implementation. */107typedef struct {108#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \109defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \110defined(MBEDTLS_ECP_RESTARTABLE)111mbedtls_ecdsa_context *MBEDTLS_PRIVATE(ctx);112mbedtls_ecdsa_restart_ctx MBEDTLS_PRIVATE(restart_ctx);113114uint32_t MBEDTLS_PRIVATE(num_ops);115116size_t MBEDTLS_PRIVATE(coordinate_bytes);117psa_algorithm_t MBEDTLS_PRIVATE(alg);118mbedtls_md_type_t MBEDTLS_PRIVATE(md_alg);119uint8_t MBEDTLS_PRIVATE(hash)[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];120size_t MBEDTLS_PRIVATE(hash_length);121122#else123/* Make the struct non-empty if algs not supported. */124unsigned MBEDTLS_PRIVATE(dummy);125126#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||127* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) &&128* defined( MBEDTLS_ECP_RESTARTABLE ) */129} mbedtls_psa_sign_hash_interruptible_operation_t;130131#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \132defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \133defined(MBEDTLS_ECP_RESTARTABLE)134#define MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { { 0 }, { 0 }, 0, 0, 0, 0, 0, 0 }135#else136#define MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }137#endif138139/* Context structure for the Mbed TLS interruptible verify hash140* implementation.*/141typedef struct {142#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \143defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \144defined(MBEDTLS_ECP_RESTARTABLE)145146mbedtls_ecdsa_context *MBEDTLS_PRIVATE(ctx);147mbedtls_ecdsa_restart_ctx MBEDTLS_PRIVATE(restart_ctx);148149uint32_t MBEDTLS_PRIVATE(num_ops);150151uint8_t MBEDTLS_PRIVATE(hash)[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];152size_t MBEDTLS_PRIVATE(hash_length);153154mbedtls_mpi MBEDTLS_PRIVATE(r);155mbedtls_mpi MBEDTLS_PRIVATE(s);156157#else158/* Make the struct non-empty if algs not supported. */159unsigned MBEDTLS_PRIVATE(dummy);160161#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||162* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) &&163* defined( MBEDTLS_ECP_RESTARTABLE ) */164165} mbedtls_psa_verify_hash_interruptible_operation_t;166167#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \168defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \169defined(MBEDTLS_ECP_RESTARTABLE)170#define MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { { 0 }, { 0 }, 0, 0, 0, 0, { 0 }, \171{ 0 } }172#else173#define MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }174#endif175176177/* EC-JPAKE operation definitions */178179#include "mbedtls/ecjpake.h"180181#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)182#define MBEDTLS_PSA_BUILTIN_PAKE 1183#endif184185/* Note: the format for mbedtls_ecjpake_read/write function has an extra186* length byte for each step, plus an extra 3 bytes for ECParameters in the187* server's 2nd round. */188#define MBEDTLS_PSA_JPAKE_BUFFER_SIZE ((3 + 1 + 65 + 1 + 65 + 1 + 32) * 2)189190typedef struct {191psa_algorithm_t MBEDTLS_PRIVATE(alg);192193uint8_t *MBEDTLS_PRIVATE(password);194size_t MBEDTLS_PRIVATE(password_len);195#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)196mbedtls_ecjpake_role MBEDTLS_PRIVATE(role);197uint8_t MBEDTLS_PRIVATE(buffer[MBEDTLS_PSA_JPAKE_BUFFER_SIZE]);198size_t MBEDTLS_PRIVATE(buffer_length);199size_t MBEDTLS_PRIVATE(buffer_offset);200#endif201/* Context structure for the Mbed TLS EC-JPAKE implementation. */202union {203unsigned int MBEDTLS_PRIVATE(dummy);204#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)205mbedtls_ecjpake_context MBEDTLS_PRIVATE(jpake);206#endif207} MBEDTLS_PRIVATE(ctx);208209} mbedtls_psa_pake_operation_t;210211#define MBEDTLS_PSA_PAKE_OPERATION_INIT { { 0 } }212213#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */214215216