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