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. |
Steven Cooreman | 675501d | 2021-04-26 11:54:58 +0200 | [diff] [blame] | 4 | * This file contains the context structures of those algorithms which do not |
| 5 | * rely on other algorithms, i.e. are 'primitive' algorithms. |
Ronald Cron | dd3b539 | 2021-04-01 15:36:50 +0200 | [diff] [blame] | 6 | * |
| 7 | * \note This file may not be included directly. Applications must |
| 8 | * include psa/crypto.h. |
| 9 | * |
Ronald Cron | 789cef8 | 2023-03-27 16:31:19 +0200 | [diff] [blame] | 10 | * \note This header and its content are not part of the Mbed TLS API and |
Ronald Cron | dd3b539 | 2021-04-01 15:36:50 +0200 | [diff] [blame] | 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 |
Ronald Cron | 789cef8 | 2023-03-27 16:31:19 +0200 | [diff] [blame] | 13 | * definitions of these objects are then used by crypto_struct.h to define the |
Ronald Cron | dd3b539 | 2021-04-01 15:36:50 +0200 | [diff] [blame] | 14 | * implementation-defined types of PSA multi-part state objects. |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 15 | */ |
| 16 | /* |
| 17 | * Copyright The Mbed TLS Contributors |
| 18 | * SPDX-License-Identifier: Apache-2.0 |
| 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | * not use this file except in compliance with the License. |
| 22 | * You may obtain a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | * See the License for the specific language governing permissions and |
| 30 | * limitations under the License. |
| 31 | */ |
| 32 | |
Steven Cooreman | 675501d | 2021-04-26 11:54:58 +0200 | [diff] [blame] | 33 | #ifndef PSA_CRYPTO_BUILTIN_PRIMITIVES_H |
| 34 | #define PSA_CRYPTO_BUILTIN_PRIMITIVES_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 35 | #include "mbedtls/private_access.h" |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 36 | |
| 37 | #include <psa/crypto_driver_common.h> |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Hash multi-part operation definitions. |
| 41 | */ |
| 42 | |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 43 | #include "mbedtls/md5.h" |
| 44 | #include "mbedtls/ripemd160.h" |
| 45 | #include "mbedtls/sha1.h" |
| 46 | #include "mbedtls/sha256.h" |
| 47 | #include "mbedtls/sha512.h" |
Dave Rodgman | 98083c6 | 2023-06-25 23:27:45 +0100 | [diff] [blame] | 48 | #include "mbedtls/sha3.h" |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 49 | |
TRodziewicz | 10e8cf5 | 2021-05-31 17:58:57 +0200 | [diff] [blame] | 50 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \ |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 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) || \ |
Dave Rodgman | 98083c6 | 2023-06-25 23:27:45 +0100 | [diff] [blame] | 56 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ |
| 57 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_3) |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 58 | #define MBEDTLS_PSA_BUILTIN_HASH |
| 59 | #endif |
| 60 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 61 | typedef struct { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 62 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 63 | union { |
Ronald Cron | ef6ffe3 | 2021-10-18 10:12:20 +0200 | [diff] [blame] | 64 | unsigned dummy; /* Make the union non-empty even with no supported algorithms. */ |
| 65 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) |
| 66 | mbedtls_md5_context md5; |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 67 | #endif |
Ronald Cron | ef6ffe3 | 2021-10-18 10:12:20 +0200 | [diff] [blame] | 68 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) |
| 69 | mbedtls_ripemd160_context ripemd160; |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 70 | #endif |
Ronald Cron | ef6ffe3 | 2021-10-18 10:12:20 +0200 | [diff] [blame] | 71 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) |
| 72 | mbedtls_sha1_context sha1; |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 73 | #endif |
Ronald Cron | ef6ffe3 | 2021-10-18 10:12:20 +0200 | [diff] [blame] | 74 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 75 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) |
Ronald Cron | ef6ffe3 | 2021-10-18 10:12:20 +0200 | [diff] [blame] | 76 | mbedtls_sha256_context sha256; |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 77 | #endif |
Ronald Cron | ef6ffe3 | 2021-10-18 10:12:20 +0200 | [diff] [blame] | 78 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 79 | defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) |
Ronald Cron | ef6ffe3 | 2021-10-18 10:12:20 +0200 | [diff] [blame] | 80 | mbedtls_sha512_context sha512; |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 81 | #endif |
Dave Rodgman | 98083c6 | 2023-06-25 23:27:45 +0100 | [diff] [blame] | 82 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_3) |
| 83 | mbedtls_sha3_context sha3; |
| 84 | #endif |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 85 | } MBEDTLS_PRIVATE(ctx); |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 86 | } mbedtls_psa_hash_operation_t; |
| 87 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 88 | #define MBEDTLS_PSA_HASH_OPERATION_INIT { 0, { 0 } } |
Steven Cooreman | 830aff2 | 2021-03-09 09:50:44 +0100 | [diff] [blame] | 89 | |
| 90 | /* |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 91 | * Cipher multi-part operation definitions. |
| 92 | */ |
| 93 | |
| 94 | #include "mbedtls/cipher.h" |
| 95 | |
| 96 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \ |
| 97 | defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \ |
| 98 | defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \ |
| 99 | defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \ |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 100 | defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \ |
| 101 | defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \ |
| 102 | defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) |
| 103 | #define MBEDTLS_PSA_BUILTIN_CIPHER 1 |
| 104 | #endif |
| 105 | |
| 106 | typedef struct { |
| 107 | /* Context structure for the Mbed TLS cipher implementation. */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 108 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
| 109 | uint8_t MBEDTLS_PRIVATE(iv_length); |
| 110 | uint8_t MBEDTLS_PRIVATE(block_length); |
gabor-mezei-arm | 42cdb2a | 2021-04-12 15:47:35 +0200 | [diff] [blame] | 111 | union { |
gabor-mezei-arm | 47060db | 2021-06-30 10:31:18 +0200 | [diff] [blame] | 112 | unsigned int MBEDTLS_PRIVATE(dummy); |
gabor-mezei-arm | 42cdb2a | 2021-04-12 15:47:35 +0200 | [diff] [blame] | 113 | mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher); |
| 114 | } MBEDTLS_PRIVATE(ctx); |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 115 | } mbedtls_psa_cipher_operation_t; |
| 116 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 117 | #define MBEDTLS_PSA_CIPHER_OPERATION_INIT { 0, 0, 0, { 0 } } |
Ronald Cron | 06c84ca | 2021-04-01 11:58:25 +0200 | [diff] [blame] | 118 | |
Steven Cooreman | 675501d | 2021-04-26 11:54:58 +0200 | [diff] [blame] | 119 | #endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */ |