2021-04-26 12:16:27 +02:00
|
|
|
/*
|
|
|
|
* Context structure declaration of the Mbed TLS software-based PSA drivers
|
|
|
|
* called through the PSA Crypto driver dispatch layer.
|
|
|
|
* This file contains the context structures of those algorithms which need to
|
|
|
|
* rely on other algorithms, i.e. are 'composite' algorithms.
|
|
|
|
*
|
|
|
|
* \note This file may not be included directly. Applications must
|
|
|
|
* include psa/crypto.h.
|
|
|
|
*
|
2023-03-27 16:31:19 +02:00
|
|
|
* \note This header and its content are not part of the Mbed TLS API and
|
2021-04-26 12:16:27 +02:00
|
|
|
* applications must not depend on it. Its main purpose is to define the
|
|
|
|
* multi-part state objects of the Mbed TLS software-based PSA drivers. The
|
2023-03-27 16:31:19 +02:00
|
|
|
* definitions of these objects are then used by crypto_struct.h to define the
|
2021-04-26 12:16:27 +02:00
|
|
|
* implementation-defined types of PSA multi-part state objects.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright The Mbed TLS Contributors
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PSA_CRYPTO_BUILTIN_COMPOSITES_H
|
|
|
|
#define PSA_CRYPTO_BUILTIN_COMPOSITES_H
|
2021-05-19 19:44:07 +02:00
|
|
|
#include "mbedtls/private_access.h"
|
2021-04-26 12:16:27 +02:00
|
|
|
|
|
|
|
#include <psa/crypto_driver_common.h>
|
|
|
|
|
2023-01-05 19:06:58 +01:00
|
|
|
#include "mbedtls/cmac.h"
|
|
|
|
#include "mbedtls/gcm.h"
|
|
|
|
#include "mbedtls/ccm.h"
|
|
|
|
#include "mbedtls/chachapoly.h"
|
|
|
|
|
2021-04-26 12:16:27 +02:00
|
|
|
/*
|
|
|
|
* MAC multi-part operation definitions.
|
|
|
|
*/
|
2021-03-19 17:05:52 +01:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \
|
|
|
|
defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
|
|
|
#define MBEDTLS_PSA_BUILTIN_MAC
|
|
|
|
#endif
|
2021-04-26 12:16:27 +02:00
|
|
|
|
2021-04-29 18:01:53 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
2021-03-22 14:49:06 +01:00
|
|
|
/** The HMAC algorithm in use */
|
2021-05-19 19:44:07 +02:00
|
|
|
psa_algorithm_t MBEDTLS_PRIVATE(alg);
|
2021-03-22 14:49:06 +01:00
|
|
|
/** The hash context. */
|
|
|
|
struct psa_hash_operation_s hash_ctx;
|
|
|
|
/** The HMAC part of the context. */
|
2021-05-19 19:44:07 +02:00
|
|
|
uint8_t MBEDTLS_PRIVATE(opad)[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
|
2021-04-29 17:49:11 +02:00
|
|
|
} mbedtls_psa_hmac_operation_t;
|
2021-03-22 12:21:10 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_PSA_HMAC_OPERATION_INIT { 0, PSA_HASH_OPERATION_INIT, { 0 } }
|
2021-04-29 18:01:53 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
2021-04-26 12:16:27 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
2021-05-19 19:44:07 +02:00
|
|
|
psa_algorithm_t MBEDTLS_PRIVATE(alg);
|
2023-01-11 14:50:10 +01:00
|
|
|
union {
|
2021-05-19 19:44:07 +02:00
|
|
|
unsigned MBEDTLS_PRIVATE(dummy); /* Make the union non-empty even with no supported algorithms. */
|
2021-04-29 18:01:53 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
|
2021-05-19 19:44:07 +02:00
|
|
|
mbedtls_psa_hmac_operation_t MBEDTLS_PRIVATE(hmac);
|
2021-04-29 18:01:53 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
|
2021-05-19 19:44:07 +02:00
|
|
|
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cmac);
|
2021-04-29 18:01:53 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
2021-05-19 19:44:07 +02:00
|
|
|
} MBEDTLS_PRIVATE(ctx);
|
2021-03-19 15:24:23 +01:00
|
|
|
} mbedtls_psa_mac_operation_t;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_PSA_MAC_OPERATION_INIT { 0, { 0 } }
|
2021-03-19 15:24:23 +01:00
|
|
|
|
2021-05-20 19:32:57 +02:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM) || \
|
|
|
|
defined(MBEDTLS_PSA_BUILTIN_ALG_CCM) || \
|
|
|
|
defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
|
|
|
#define MBEDTLS_PSA_BUILTIN_AEAD 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Context structure for the Mbed TLS AEAD implementation. */
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
2021-09-23 18:35:08 +02:00
|
|
|
psa_algorithm_t MBEDTLS_PRIVATE(alg);
|
|
|
|
psa_key_type_t MBEDTLS_PRIVATE(key_type);
|
2021-05-20 19:32:57 +02:00
|
|
|
|
2021-09-23 18:35:08 +02:00
|
|
|
unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1;
|
2021-05-20 19:32:57 +02:00
|
|
|
|
2021-09-23 18:35:08 +02:00
|
|
|
uint8_t MBEDTLS_PRIVATE(tag_length);
|
2021-05-20 19:32:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
union {
|
2021-05-20 19:32:57 +02:00
|
|
|
unsigned dummy; /* Enable easier initializing of the union. */
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
2021-09-23 18:35:08 +02:00
|
|
|
mbedtls_ccm_context MBEDTLS_PRIVATE(ccm);
|
2021-05-20 19:32:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
2021-09-23 18:35:08 +02:00
|
|
|
mbedtls_gcm_context MBEDTLS_PRIVATE(gcm);
|
2021-05-20 19:32:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
2021-09-23 18:35:08 +02:00
|
|
|
mbedtls_chachapoly_context MBEDTLS_PRIVATE(chachapoly);
|
2021-05-20 19:32:57 +02:00
|
|
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
|
|
|
|
|
|
|
} ctx;
|
|
|
|
|
|
|
|
} mbedtls_psa_aead_operation_t;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, { 0 } }
|
2021-05-20 19:32:57 +02:00
|
|
|
|
2022-12-02 19:10:26 +01:00
|
|
|
#include "mbedtls/ecdsa.h"
|
|
|
|
|
|
|
|
/* Context structure for the Mbed TLS interruptible sign hash implementation. */
|
|
|
|
typedef struct {
|
2023-01-24 16:23:25 +01:00
|
|
|
#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
|
|
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
|
|
|
|
defined(MBEDTLS_ECP_RESTARTABLE)
|
2022-12-02 19:10:26 +01:00
|
|
|
mbedtls_ecdsa_context *MBEDTLS_PRIVATE(ctx);
|
|
|
|
mbedtls_ecdsa_restart_ctx MBEDTLS_PRIVATE(restart_ctx);
|
|
|
|
|
2023-02-15 19:14:21 +01:00
|
|
|
uint32_t MBEDTLS_PRIVATE(num_ops);
|
|
|
|
|
2023-02-05 14:41:57 +01:00
|
|
|
size_t MBEDTLS_PRIVATE(coordinate_bytes);
|
2022-12-02 19:10:26 +01:00
|
|
|
psa_algorithm_t MBEDTLS_PRIVATE(alg);
|
|
|
|
mbedtls_md_type_t MBEDTLS_PRIVATE(md_alg);
|
2023-02-07 18:32:04 +01:00
|
|
|
uint8_t MBEDTLS_PRIVATE(hash)[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];
|
2022-12-02 19:10:26 +01:00
|
|
|
size_t MBEDTLS_PRIVATE(hash_length);
|
|
|
|
|
2023-01-24 16:23:25 +01:00
|
|
|
#else
|
|
|
|
/* Make the struct non-empty if algs not supported. */
|
|
|
|
unsigned MBEDTLS_PRIVATE(dummy);
|
2022-12-02 19:10:26 +01:00
|
|
|
|
2023-02-10 12:04:27 +01:00
|
|
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
|
|
|
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) &&
|
|
|
|
* defined( MBEDTLS_ECP_RESTARTABLE ) */
|
2022-12-02 19:10:26 +01:00
|
|
|
} mbedtls_psa_sign_hash_interruptible_operation_t;
|
|
|
|
|
2023-02-03 15:49:37 +01:00
|
|
|
#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
|
|
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
|
|
|
|
defined(MBEDTLS_ECP_RESTARTABLE)
|
2023-02-15 19:14:21 +01:00
|
|
|
#define MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { { 0 }, { 0 }, 0, 0, 0, 0, 0, 0 }
|
2023-02-03 15:49:37 +01:00
|
|
|
#else
|
|
|
|
#define MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
|
|
|
|
#endif
|
2022-12-02 19:10:26 +01:00
|
|
|
|
|
|
|
/* Context structure for the Mbed TLS interruptible verify hash
|
|
|
|
* implementation.*/
|
|
|
|
typedef struct {
|
2023-01-16 13:18:46 +01:00
|
|
|
#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
|
|
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
|
|
|
|
defined(MBEDTLS_ECP_RESTARTABLE)
|
2022-12-02 19:10:26 +01:00
|
|
|
|
|
|
|
mbedtls_ecdsa_context *MBEDTLS_PRIVATE(ctx);
|
|
|
|
mbedtls_ecdsa_restart_ctx MBEDTLS_PRIVATE(restart_ctx);
|
|
|
|
|
2023-02-15 19:14:21 +01:00
|
|
|
uint32_t MBEDTLS_PRIVATE(num_ops);
|
|
|
|
|
2023-02-07 18:32:04 +01:00
|
|
|
uint8_t MBEDTLS_PRIVATE(hash)[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)];
|
2022-12-02 19:10:26 +01:00
|
|
|
size_t MBEDTLS_PRIVATE(hash_length);
|
|
|
|
|
|
|
|
mbedtls_mpi MBEDTLS_PRIVATE(r);
|
|
|
|
mbedtls_mpi MBEDTLS_PRIVATE(s);
|
|
|
|
|
2023-01-24 16:23:25 +01:00
|
|
|
#else
|
|
|
|
/* Make the struct non-empty if algs not supported. */
|
|
|
|
unsigned MBEDTLS_PRIVATE(dummy);
|
|
|
|
|
2023-02-10 12:04:27 +01:00
|
|
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
|
|
|
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) &&
|
|
|
|
* defined( MBEDTLS_ECP_RESTARTABLE ) */
|
2022-12-02 19:10:26 +01:00
|
|
|
|
|
|
|
} mbedtls_psa_verify_hash_interruptible_operation_t;
|
|
|
|
|
2023-02-03 15:49:37 +01:00
|
|
|
#if (defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
|
|
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) && \
|
|
|
|
defined(MBEDTLS_ECP_RESTARTABLE)
|
2023-02-15 19:14:21 +01:00
|
|
|
#define MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { { 0 }, { 0 }, 0, 0, 0, 0, { 0 }, \
|
2022-12-02 19:10:26 +01:00
|
|
|
{ 0 } }
|
2023-02-03 15:49:37 +01:00
|
|
|
#else
|
|
|
|
#define MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
|
|
|
|
#endif
|
2022-12-02 19:10:26 +01:00
|
|
|
|
|
|
|
|
2022-12-07 11:52:08 +01:00
|
|
|
/* EC-JPAKE operation definitions */
|
|
|
|
|
|
|
|
#include "mbedtls/ecjpake.h"
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
|
|
|
|
#define MBEDTLS_PSA_BUILTIN_PAKE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Note: the format for mbedtls_ecjpake_read/write function has an extra
|
|
|
|
* length byte for each step, plus an extra 3 bytes for ECParameters in the
|
|
|
|
* server's 2nd round. */
|
2023-02-17 14:30:50 +01:00
|
|
|
#define MBEDTLS_PSA_JPAKE_BUFFER_SIZE ((3 + 1 + 65 + 1 + 65 + 1 + 32) * 2)
|
2022-12-07 11:52:08 +01:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
psa_algorithm_t MBEDTLS_PRIVATE(alg);
|
2022-12-21 12:54:46 +01:00
|
|
|
|
2022-12-07 11:52:08 +01:00
|
|
|
uint8_t *MBEDTLS_PRIVATE(password);
|
|
|
|
size_t MBEDTLS_PRIVATE(password_len);
|
2023-02-17 14:30:50 +01:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
|
2023-03-21 16:49:43 +01:00
|
|
|
mbedtls_ecjpake_role MBEDTLS_PRIVATE(role);
|
2023-02-17 14:30:50 +01:00
|
|
|
uint8_t MBEDTLS_PRIVATE(buffer[MBEDTLS_PSA_JPAKE_BUFFER_SIZE]);
|
2022-12-07 11:52:08 +01:00
|
|
|
size_t MBEDTLS_PRIVATE(buffer_length);
|
|
|
|
size_t MBEDTLS_PRIVATE(buffer_offset);
|
|
|
|
#endif
|
|
|
|
/* Context structure for the Mbed TLS EC-JPAKE implementation. */
|
|
|
|
union {
|
|
|
|
unsigned int MBEDTLS_PRIVATE(dummy);
|
2023-02-17 14:30:50 +01:00
|
|
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE)
|
2023-02-27 10:20:06 +01:00
|
|
|
mbedtls_ecjpake_context MBEDTLS_PRIVATE(jpake);
|
2023-02-17 14:30:50 +01:00
|
|
|
#endif
|
2022-12-07 11:52:08 +01:00
|
|
|
} MBEDTLS_PRIVATE(ctx);
|
|
|
|
|
|
|
|
} mbedtls_psa_pake_operation_t;
|
|
|
|
|
|
|
|
#define MBEDTLS_PSA_PAKE_OPERATION_INIT { { 0 } }
|
2022-12-02 19:10:26 +01:00
|
|
|
|
2021-04-26 12:16:27 +02:00
|
|
|
#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */
|