blob: 72d3e8d7a578ef4a99c958019f2b5a8b40ed250f [file] [log] [blame]
Ronald Cron7cb9c3d2021-03-10 12:21:48 +01001/*
2 * Context structure declaration of the software-based driver which performs
3 * cipher operations through the PSA Crypto driver dispatch layer.
4 */
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
22#ifndef PSA_CRYPTO_BUILTIN_CIPHER_H
23#define PSA_CRYPTO_BUILTIN_CIPHER_H
24
25#include <psa/crypto_driver_common.h>
26#include "mbedtls/cipher.h"
27
Ronald Cron5d9b00d2021-03-10 14:43:20 +010028#if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \
29 defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \
30 defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \
31 defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \
32 defined(MBEDTLS_PSA_BUILTIN_ALG_XTS) || \
33 defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \
34 defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \
35 defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7)
36#define MBEDTLS_PSA_BUILTIN_CIPHER 1
37#endif
38
Ronald Cron7cb9c3d2021-03-10 12:21:48 +010039typedef struct {
40 /** Context structure for the Mbed TLS cipher implementation. */
41 psa_algorithm_t alg;
42 uint8_t iv_size;
43 uint8_t block_size;
44 mbedtls_cipher_context_t cipher;
45} mbedtls_psa_cipher_operation_t;
46
47#define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}}
48
49/*
50 * BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY.
51 */
52#if defined(PSA_CRYPTO_DRIVER_TEST)
53
54typedef mbedtls_psa_cipher_operation_t
55 mbedtls_transparent_test_driver_cipher_operation_t;
56
57typedef struct {
58 unsigned int initialised : 1;
59 mbedtls_transparent_test_driver_cipher_operation_t ctx;
60} mbedtls_opaque_test_driver_cipher_operation_t;
61
62#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \
63 MBEDTLS_PSA_CIPHER_OPERATION_INIT
64
65#define MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT \
66 { 0, MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT }
67
68#endif /* PSA_CRYPTO_DRIVER_TEST */
69
70#endif /* PSA_CRYPTO_BUILTIN_CIPHER_H */