1a8e1175bSopenharmony_ci/* 2a8e1175bSopenharmony_ci * Context structure declaration of the Mbed TLS software-based PSA drivers 3a8e1175bSopenharmony_ci * called through the PSA Crypto driver dispatch layer. 4a8e1175bSopenharmony_ci * This file contains the context structures of those algorithms which do not 5a8e1175bSopenharmony_ci * rely on other algorithms, i.e. are 'primitive' algorithms. 6a8e1175bSopenharmony_ci * 7a8e1175bSopenharmony_ci * \note This file may not be included directly. Applications must 8a8e1175bSopenharmony_ci * include psa/crypto.h. 9a8e1175bSopenharmony_ci * 10a8e1175bSopenharmony_ci * \note This header and its content are not part of the Mbed TLS API and 11a8e1175bSopenharmony_ci * applications must not depend on it. Its main purpose is to define the 12a8e1175bSopenharmony_ci * multi-part state objects of the Mbed TLS software-based PSA drivers. The 13a8e1175bSopenharmony_ci * definitions of these objects are then used by crypto_struct.h to define the 14a8e1175bSopenharmony_ci * implementation-defined types of PSA multi-part state objects. 15a8e1175bSopenharmony_ci */ 16a8e1175bSopenharmony_ci/* 17a8e1175bSopenharmony_ci * Copyright The Mbed TLS Contributors 18a8e1175bSopenharmony_ci * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 19a8e1175bSopenharmony_ci */ 20a8e1175bSopenharmony_ci 21a8e1175bSopenharmony_ci#ifndef PSA_CRYPTO_BUILTIN_PRIMITIVES_H 22a8e1175bSopenharmony_ci#define PSA_CRYPTO_BUILTIN_PRIMITIVES_H 23a8e1175bSopenharmony_ci#include "mbedtls/private_access.h" 24a8e1175bSopenharmony_ci 25a8e1175bSopenharmony_ci#include <psa/crypto_driver_common.h> 26a8e1175bSopenharmony_ci 27a8e1175bSopenharmony_ci/* 28a8e1175bSopenharmony_ci * Hash multi-part operation definitions. 29a8e1175bSopenharmony_ci */ 30a8e1175bSopenharmony_ci 31a8e1175bSopenharmony_ci#include "mbedtls/md5.h" 32a8e1175bSopenharmony_ci#include "mbedtls/ripemd160.h" 33a8e1175bSopenharmony_ci#include "mbedtls/sha1.h" 34a8e1175bSopenharmony_ci#include "mbedtls/sha256.h" 35a8e1175bSopenharmony_ci#include "mbedtls/sha512.h" 36a8e1175bSopenharmony_ci#include "mbedtls/sha3.h" 37a8e1175bSopenharmony_ci 38a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \ 39a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \ 40a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \ 41a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \ 42a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ 43a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \ 44a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ 45a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_224) || \ 46a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_256) || \ 47a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_384) || \ 48a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_512) 49a8e1175bSopenharmony_ci#define MBEDTLS_PSA_BUILTIN_HASH 50a8e1175bSopenharmony_ci#endif 51a8e1175bSopenharmony_ci 52a8e1175bSopenharmony_citypedef struct { 53a8e1175bSopenharmony_ci psa_algorithm_t MBEDTLS_PRIVATE(alg); 54a8e1175bSopenharmony_ci union { 55a8e1175bSopenharmony_ci unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ 56a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) 57a8e1175bSopenharmony_ci mbedtls_md5_context md5; 58a8e1175bSopenharmony_ci#endif 59a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) 60a8e1175bSopenharmony_ci mbedtls_ripemd160_context ripemd160; 61a8e1175bSopenharmony_ci#endif 62a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) 63a8e1175bSopenharmony_ci mbedtls_sha1_context sha1; 64a8e1175bSopenharmony_ci#endif 65a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ 66a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) 67a8e1175bSopenharmony_ci mbedtls_sha256_context sha256; 68a8e1175bSopenharmony_ci#endif 69a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ 70a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) 71a8e1175bSopenharmony_ci mbedtls_sha512_context sha512; 72a8e1175bSopenharmony_ci#endif 73a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_224) || \ 74a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_256) || \ 75a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_384) || \ 76a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_512) 77a8e1175bSopenharmony_ci mbedtls_sha3_context sha3; 78a8e1175bSopenharmony_ci#endif 79a8e1175bSopenharmony_ci } MBEDTLS_PRIVATE(ctx); 80a8e1175bSopenharmony_ci} mbedtls_psa_hash_operation_t; 81a8e1175bSopenharmony_ci 82a8e1175bSopenharmony_ci#define MBEDTLS_PSA_HASH_OPERATION_INIT { 0, { 0 } } 83a8e1175bSopenharmony_ci 84a8e1175bSopenharmony_ci/* 85a8e1175bSopenharmony_ci * Cipher multi-part operation definitions. 86a8e1175bSopenharmony_ci */ 87a8e1175bSopenharmony_ci 88a8e1175bSopenharmony_ci#include "mbedtls/cipher.h" 89a8e1175bSopenharmony_ci 90a8e1175bSopenharmony_ci#if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \ 91a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \ 92a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \ 93a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \ 94a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \ 95a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \ 96a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) || \ 97a8e1175bSopenharmony_ci defined(MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG) 98a8e1175bSopenharmony_ci#define MBEDTLS_PSA_BUILTIN_CIPHER 1 99a8e1175bSopenharmony_ci#endif 100a8e1175bSopenharmony_ci 101a8e1175bSopenharmony_citypedef struct { 102a8e1175bSopenharmony_ci /* Context structure for the Mbed TLS cipher implementation. */ 103a8e1175bSopenharmony_ci psa_algorithm_t MBEDTLS_PRIVATE(alg); 104a8e1175bSopenharmony_ci uint8_t MBEDTLS_PRIVATE(iv_length); 105a8e1175bSopenharmony_ci uint8_t MBEDTLS_PRIVATE(block_length); 106a8e1175bSopenharmony_ci union { 107a8e1175bSopenharmony_ci unsigned int MBEDTLS_PRIVATE(dummy); 108a8e1175bSopenharmony_ci mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher); 109a8e1175bSopenharmony_ci } MBEDTLS_PRIVATE(ctx); 110a8e1175bSopenharmony_ci} mbedtls_psa_cipher_operation_t; 111a8e1175bSopenharmony_ci 112a8e1175bSopenharmony_ci#define MBEDTLS_PSA_CIPHER_OPERATION_INIT { 0, 0, 0, { 0 } } 113a8e1175bSopenharmony_ci 114a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */ 115