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 are 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 * definitions 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 #include "mbedtls/private_access.h" 24 25 #include <psa/crypto_driver_common.h> 26 27 /* 28 * Hash multi-part operation definitions. 29 */ 30 31 #include "mbedtls/md5.h" 32 #include "mbedtls/ripemd160.h" 33 #include "mbedtls/sha1.h" 34 #include "mbedtls/sha256.h" 35 #include "mbedtls/sha512.h" 36 #include "mbedtls/sha3.h" 37 38 #if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \ 39 defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \ 40 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \ 41 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \ 42 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ 43 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \ 44 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ 45 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_224) || \ 46 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_256) || \ 47 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_384) || \ 48 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_512) 49 #define MBEDTLS_PSA_BUILTIN_HASH 50 #endif 51 52 typedef struct { 53 psa_algorithm_t MBEDTLS_PRIVATE(alg); 54 union { 55 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ 56 #if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) 57 mbedtls_md5_context md5; 58 #endif 59 #if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) 60 mbedtls_ripemd160_context ripemd160; 61 #endif 62 #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) 63 mbedtls_sha1_context sha1; 64 #endif 65 #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ 66 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) 67 mbedtls_sha256_context sha256; 68 #endif 69 #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ 70 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) 71 mbedtls_sha512_context sha512; 72 #endif 73 #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_224) || \ 74 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_256) || \ 75 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_384) || \ 76 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA3_512) 77 mbedtls_sha3_context sha3; 78 #endif 79 } MBEDTLS_PRIVATE(ctx); 80 } mbedtls_psa_hash_operation_t; 81 82 #define MBEDTLS_PSA_HASH_OPERATION_INIT { 0, { 0 } } 83 84 /* 85 * Cipher multi-part operation definitions. 86 */ 87 88 #include "mbedtls/cipher.h" 89 90 #if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \ 91 defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \ 92 defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \ 93 defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \ 94 defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \ 95 defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \ 96 defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) || \ 97 defined(MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG) 98 #define MBEDTLS_PSA_BUILTIN_CIPHER 1 99 #endif 100 101 typedef struct { 102 /* Context structure for the Mbed TLS cipher implementation. */ 103 psa_algorithm_t MBEDTLS_PRIVATE(alg); 104 uint8_t MBEDTLS_PRIVATE(iv_length); 105 uint8_t MBEDTLS_PRIVATE(block_length); 106 union { 107 unsigned int MBEDTLS_PRIVATE(dummy); 108 mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher); 109 } MBEDTLS_PRIVATE(ctx); 110 } mbedtls_psa_cipher_operation_t; 111 112 #define MBEDTLS_PSA_CIPHER_OPERATION_INIT { 0, 0, 0, { 0 } } 113 114 #endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */ 115