Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 1 | /* |
Ronald Cron | dd3b539 | 2021-04-01 15:36:50 +0200 | [diff] [blame^] | 2 | * Context structure declaration of the Mbed TLS software-based PSA drivers |
| 3 | * called through the PSA Crypto driver dispatch layer. |
| 4 | * |
| 5 | * \note This file may not be included directly. Applications must |
| 6 | * include psa/crypto.h. |
| 7 | * |
| 8 | * \note This header and its content is not part of the Mbed TLS API and |
| 9 | * applications must not depend on it. Its main purpose is to define the |
| 10 | * multi-part state objects of the Mbed TLS software-based PSA drivers. The |
| 11 | * definition of these objects are then used by crypto_struct.h to define the |
| 12 | * implementation-defined types of PSA multi-part state objects. |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 13 | */ |
| 14 | /* |
| 15 | * Copyright The Mbed TLS Contributors |
| 16 | * SPDX-License-Identifier: Apache-2.0 |
| 17 | * |
| 18 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 19 | * not use this file except in compliance with the License. |
| 20 | * You may obtain a copy of the License at |
| 21 | * |
| 22 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 23 | * |
| 24 | * Unless required by applicable law or agreed to in writing, software |
| 25 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 27 | * See the License for the specific language governing permissions and |
| 28 | * limitations under the License. |
| 29 | */ |
| 30 | |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 31 | #ifndef PSA_CRYPTO_BUILTIN_H |
| 32 | #define PSA_CRYPTO_BUILTIN_H |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 33 | |
| 34 | #include <psa/crypto_driver_common.h> |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Hash multi-part operation definitions. |
| 38 | */ |
| 39 | |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 40 | #include "mbedtls/md2.h" |
| 41 | #include "mbedtls/md4.h" |
| 42 | #include "mbedtls/md5.h" |
| 43 | #include "mbedtls/ripemd160.h" |
| 44 | #include "mbedtls/sha1.h" |
| 45 | #include "mbedtls/sha256.h" |
| 46 | #include "mbedtls/sha512.h" |
| 47 | |
| 48 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) || \ |
| 49 | defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) || \ |
| 50 | defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \ |
| 51 | defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \ |
| 52 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \ |
| 53 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \ |
| 54 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ |
| 55 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \ |
| 56 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) |
| 57 | #define MBEDTLS_PSA_BUILTIN_HASH |
| 58 | #endif |
| 59 | |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 60 | typedef struct |
| 61 | { |
| 62 | psa_algorithm_t alg; |
| 63 | union |
| 64 | { |
| 65 | unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ |
| 66 | #if defined(MBEDTLS_MD2_C) |
| 67 | mbedtls_md2_context md2; |
| 68 | #endif |
| 69 | #if defined(MBEDTLS_MD4_C) |
| 70 | mbedtls_md4_context md4; |
| 71 | #endif |
| 72 | #if defined(MBEDTLS_MD5_C) |
| 73 | mbedtls_md5_context md5; |
| 74 | #endif |
| 75 | #if defined(MBEDTLS_RIPEMD160_C) |
| 76 | mbedtls_ripemd160_context ripemd160; |
| 77 | #endif |
| 78 | #if defined(MBEDTLS_SHA1_C) |
| 79 | mbedtls_sha1_context sha1; |
| 80 | #endif |
| 81 | #if defined(MBEDTLS_SHA256_C) |
| 82 | mbedtls_sha256_context sha256; |
| 83 | #endif |
| 84 | #if defined(MBEDTLS_SHA512_C) |
| 85 | mbedtls_sha512_context sha512; |
| 86 | #endif |
| 87 | } ctx; |
| 88 | } mbedtls_psa_hash_operation_t; |
| 89 | |
| 90 | #define MBEDTLS_PSA_HASH_OPERATION_INIT {0, {0}} |
| 91 | |
| 92 | /* |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 93 | * Cipher multi-part operation definitions. |
| 94 | */ |
| 95 | |
| 96 | #include "mbedtls/cipher.h" |
| 97 | |
| 98 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \ |
| 99 | defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \ |
| 100 | defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \ |
| 101 | defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \ |
| 102 | defined(MBEDTLS_PSA_BUILTIN_ALG_XTS) || \ |
| 103 | defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \ |
| 104 | defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \ |
| 105 | defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) |
| 106 | #define MBEDTLS_PSA_BUILTIN_CIPHER 1 |
| 107 | #endif |
| 108 | |
| 109 | typedef struct { |
| 110 | /* Context structure for the Mbed TLS cipher implementation. */ |
| 111 | psa_algorithm_t alg; |
| 112 | uint8_t iv_length; |
| 113 | uint8_t block_length; |
| 114 | mbedtls_cipher_context_t cipher; |
| 115 | } mbedtls_psa_cipher_operation_t; |
| 116 | |
| 117 | #define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}} |
| 118 | |
| 119 | /* |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 120 | * BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY. |
| 121 | */ |
| 122 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 123 | |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 124 | typedef mbedtls_psa_hash_operation_t mbedtls_transparent_test_driver_hash_operation_t; |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 125 | |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 126 | #define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT MBEDTLS_PSA_HASH_OPERATION_INIT |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 127 | |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 128 | typedef mbedtls_psa_cipher_operation_t |
| 129 | mbedtls_transparent_test_driver_cipher_operation_t; |
| 130 | |
| 131 | typedef struct { |
| 132 | unsigned int initialised : 1; |
| 133 | mbedtls_transparent_test_driver_cipher_operation_t ctx; |
| 134 | } mbedtls_opaque_test_driver_cipher_operation_t; |
| 135 | |
| 136 | #define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \ |
| 137 | MBEDTLS_PSA_CIPHER_OPERATION_INIT |
| 138 | |
| 139 | #define MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT \ |
| 140 | { 0, MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT } |
| 141 | |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 142 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 143 | |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 144 | #endif /* PSA_CRYPTO_BUILTIN_H */ |