blob: c5f620c102217fa4cff8839df172e2b28359e6a7 [file] [log] [blame]
Steven Cooreman830aff22021-03-09 09:50:44 +01001/*
Ronald Crondd3b5392021-04-01 15:36:50 +02002 * Context structure declaration of the Mbed TLS software-based PSA drivers
3 * called through the PSA Crypto driver dispatch layer.
Steven Cooreman040d1ce2021-04-26 11:54:58 +02004 * This file contains the context structures of those algorithms which do not
5 * rely on other algorithms, i.e. are 'primitive' algorithms.
Ronald Crondd3b5392021-04-01 15:36:50 +02006 *
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.
Steven Cooreman830aff22021-03-09 09:50:44 +010015 */
16/*
17 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000018 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Steven Cooreman830aff22021-03-09 09:50:44 +010019 */
20
Steven Cooreman040d1ce2021-04-26 11:54:58 +020021#ifndef PSA_CRYPTO_BUILTIN_PRIMITIVES_H
22#define PSA_CRYPTO_BUILTIN_PRIMITIVES_H
Steven Cooreman830aff22021-03-09 09:50:44 +010023
24#include <psa/crypto_driver_common.h>
Ronald Cron06c84ca2021-04-01 11:58:25 +020025
26/*
27 * Hash multi-part operation definitions.
28 */
29
Steven Cooreman830aff22021-03-09 09:50:44 +010030#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
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010050typedef struct {
Steven Cooreman830aff22021-03-09 09:50:44 +010051 psa_algorithm_t alg;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010052 union {
Steven Cooreman830aff22021-03-09 09:50:44 +010053 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
Ronald Cron0d5a27b2021-10-18 10:12:20 +020054#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
Steven Cooreman830aff22021-03-09 09:50:44 +010055 mbedtls_md2_context md2;
56#endif
Ronald Cron0d5a27b2021-10-18 10:12:20 +020057#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
Steven Cooreman830aff22021-03-09 09:50:44 +010058 mbedtls_md4_context md4;
59#endif
Ronald Cron0d5a27b2021-10-18 10:12:20 +020060#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
Steven Cooreman830aff22021-03-09 09:50:44 +010061 mbedtls_md5_context md5;
62#endif
Ronald Cron0d5a27b2021-10-18 10:12:20 +020063#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
Steven Cooreman830aff22021-03-09 09:50:44 +010064 mbedtls_ripemd160_context ripemd160;
65#endif
Ronald Cron0d5a27b2021-10-18 10:12:20 +020066#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
Steven Cooreman830aff22021-03-09 09:50:44 +010067 mbedtls_sha1_context sha1;
68#endif
Ronald Cron0d5a27b2021-10-18 10:12:20 +020069#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010070 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
Steven Cooreman830aff22021-03-09 09:50:44 +010071 mbedtls_sha256_context sha256;
72#endif
Ronald Cron0d5a27b2021-10-18 10:12:20 +020073#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010074 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
Steven Cooreman830aff22021-03-09 09:50:44 +010075 mbedtls_sha512_context sha512;
76#endif
77 } ctx;
78} mbedtls_psa_hash_operation_t;
79
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010080#define MBEDTLS_PSA_HASH_OPERATION_INIT { 0, { 0 } }
Steven Cooreman830aff22021-03-09 09:50:44 +010081
82/*
Ronald Cron06c84ca2021-04-01 11:58:25 +020083 * 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) || \
Ronald Cron06c84ca2021-04-01 11:58:25 +020092 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
98typedef 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;
gabor-mezei-armf67d8af2021-04-12 15:47:35 +0200103 union {
gabor-mezei-arm05dac4a2021-06-30 10:31:18 +0200104 unsigned int dummy;
gabor-mezei-armf67d8af2021-04-12 15:47:35 +0200105 mbedtls_cipher_context_t cipher;
106 } ctx;
Ronald Cron06c84ca2021-04-01 11:58:25 +0200107} mbedtls_psa_cipher_operation_t;
108
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100109#define MBEDTLS_PSA_CIPHER_OPERATION_INIT { 0, 0, 0, { 0 } }
Ronald Cron06c84ca2021-04-01 11:58:25 +0200110
Steven Cooreman040d1ce2021-04-26 11:54:58 +0200111#endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */