Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 1 | /* |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame^] | 2 | * Context structure declaration of the software-based drivers called |
| 3 | * through the PSA Crypto driver dispatch layer. |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 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 | |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame^] | 22 | #ifndef PSA_CRYPTO_BUILTIN_H |
| 23 | #define PSA_CRYPTO_BUILTIN_H |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 24 | |
| 25 | #include <psa/crypto_driver_common.h> |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame^] | 26 | |
| 27 | /* |
| 28 | * Hash multi-part operation definitions. |
| 29 | */ |
| 30 | |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 31 | #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 Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 51 | typedef 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 Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame^] | 84 | * 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 | |
| 100 | typedef 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 Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 111 | * BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY. |
| 112 | */ |
| 113 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 114 | |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 115 | 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] | 116 | |
Steven Cooreman | 0f8ffa8 | 2021-03-15 11:56:33 +0100 | [diff] [blame] | 117 | #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] | 118 | |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame^] | 119 | typedef mbedtls_psa_cipher_operation_t |
| 120 | mbedtls_transparent_test_driver_cipher_operation_t; |
| 121 | |
| 122 | typedef 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 Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 133 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 134 | |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame^] | 135 | #endif /* PSA_CRYPTO_BUILTIN_H */ |