blob: 7b661728da7bc77e6cfcbbdb055c107a9de596e0 [file] [log] [blame]
Steven Cooreman830aff22021-03-09 09:50:44 +01001/*
Ronald Cron06c84ca2021-04-01 11:58:25 +02002 * Context structure declaration of the software-based drivers called
3 * through the PSA Crypto driver dispatch layer.
Steven Cooreman830aff22021-03-09 09:50:44 +01004 */
5/*
6 * Copyright The Mbed TLS Contributors
7 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
Ronald Cron06c84ca2021-04-01 11:58:25 +020022#ifndef PSA_CRYPTO_BUILTIN_H
23#define PSA_CRYPTO_BUILTIN_H
Steven Cooreman830aff22021-03-09 09:50:44 +010024
25#include <psa/crypto_driver_common.h>
Ronald Cron06c84ca2021-04-01 11:58:25 +020026
27/*
28 * Hash multi-part operation definitions.
29 */
30
Steven Cooreman830aff22021-03-09 09:50:44 +010031#include "mbedtls/md2.h"
32#include "mbedtls/md4.h"
33#include "mbedtls/md5.h"
34#include "mbedtls/ripemd160.h"
35#include "mbedtls/sha1.h"
36#include "mbedtls/sha256.h"
37#include "mbedtls/sha512.h"
38
39#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) || \
40 defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) || \
41 defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \
42 defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \
43 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \
44 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \
45 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \
46 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \
47 defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
48#define MBEDTLS_PSA_BUILTIN_HASH
49#endif
50
Steven Cooreman830aff22021-03-09 09:50:44 +010051typedef struct
52{
53 psa_algorithm_t alg;
54 union
55 {
56 unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
57#if defined(MBEDTLS_MD2_C)
58 mbedtls_md2_context md2;
59#endif
60#if defined(MBEDTLS_MD4_C)
61 mbedtls_md4_context md4;
62#endif
63#if defined(MBEDTLS_MD5_C)
64 mbedtls_md5_context md5;
65#endif
66#if defined(MBEDTLS_RIPEMD160_C)
67 mbedtls_ripemd160_context ripemd160;
68#endif
69#if defined(MBEDTLS_SHA1_C)
70 mbedtls_sha1_context sha1;
71#endif
72#if defined(MBEDTLS_SHA256_C)
73 mbedtls_sha256_context sha256;
74#endif
75#if defined(MBEDTLS_SHA512_C)
76 mbedtls_sha512_context sha512;
77#endif
78 } ctx;
79} mbedtls_psa_hash_operation_t;
80
81#define MBEDTLS_PSA_HASH_OPERATION_INIT {0, {0}}
82
83/*
Ronald Cron06c84ca2021-04-01 11:58:25 +020084 * Cipher multi-part operation definitions.
85 */
86
87#include "mbedtls/cipher.h"
88
89#if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \
90 defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \
91 defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \
92 defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \
93 defined(MBEDTLS_PSA_BUILTIN_ALG_XTS) || \
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#define MBEDTLS_PSA_BUILTIN_CIPHER 1
98#endif
99
100typedef struct {
101 /* Context structure for the Mbed TLS cipher implementation. */
102 psa_algorithm_t alg;
103 uint8_t iv_length;
104 uint8_t block_length;
105 mbedtls_cipher_context_t cipher;
106} mbedtls_psa_cipher_operation_t;
107
108#define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}}
109
110/*
Steven Cooreman830aff22021-03-09 09:50:44 +0100111 * BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY.
112 */
113#if defined(PSA_CRYPTO_DRIVER_TEST)
114
Steven Cooreman0f8ffa82021-03-15 11:56:33 +0100115typedef mbedtls_psa_hash_operation_t mbedtls_transparent_test_driver_hash_operation_t;
Steven Cooreman830aff22021-03-09 09:50:44 +0100116
Steven Cooreman0f8ffa82021-03-15 11:56:33 +0100117#define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT MBEDTLS_PSA_HASH_OPERATION_INIT
Steven Cooreman830aff22021-03-09 09:50:44 +0100118
Ronald Cron06c84ca2021-04-01 11:58:25 +0200119typedef mbedtls_psa_cipher_operation_t
120 mbedtls_transparent_test_driver_cipher_operation_t;
121
122typedef struct {
123 unsigned int initialised : 1;
124 mbedtls_transparent_test_driver_cipher_operation_t ctx;
125} mbedtls_opaque_test_driver_cipher_operation_t;
126
127#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \
128 MBEDTLS_PSA_CIPHER_OPERATION_INIT
129
130#define MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT \
131 { 0, MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT }
132
Steven Cooreman830aff22021-03-09 09:50:44 +0100133#endif /* PSA_CRYPTO_DRIVER_TEST */
134
Ronald Cron06c84ca2021-04-01 11:58:25 +0200135#endif /* PSA_CRYPTO_BUILTIN_H */