Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PSA hashing layer on top of Mbed TLS software crypto |
| 3 | */ |
| 4 | /* |
| 5 | * Copyright The Mbed TLS Contributors |
| 6 | * SPDX-License-Identifier: Apache-2.0 |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | * not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | |
| 21 | #include "common.h" |
| 22 | |
| 23 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 24 | |
| 25 | #include <psa/crypto.h> |
| 26 | #include "psa_crypto_core.h" |
| 27 | #include "psa_crypto_hash.h" |
| 28 | |
| 29 | #include <mbedtls/error.h> |
| 30 | #include <string.h> |
| 31 | |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 32 | /* Use builtin defines specific to this compilation unit, since the test driver |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 33 | * relies on the software driver. */ |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 34 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) || \ |
| 35 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_MD2) ) ) |
| 36 | #define BUILTIN_ALG_MD2 1 |
| 37 | #endif |
| 38 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) || \ |
| 39 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_MD4) ) ) |
| 40 | #define BUILTIN_ALG_MD4 1 |
| 41 | #endif |
| 42 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \ |
| 43 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_MD5) ) ) |
| 44 | #define BUILTIN_ALG_MD5 1 |
| 45 | #endif |
| 46 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \ |
| 47 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) ) ) |
| 48 | #define BUILTIN_ALG_RIPEMD160 1 |
| 49 | #endif |
| 50 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \ |
| 51 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) ) ) |
| 52 | #define BUILTIN_ALG_SHA_1 1 |
| 53 | #endif |
| 54 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \ |
| 55 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) ) ) |
| 56 | #define BUILTIN_ALG_SHA_224 1 |
| 57 | #endif |
| 58 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \ |
| 59 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) ) ) |
| 60 | #define BUILTIN_ALG_SHA_256 1 |
| 61 | #endif |
| 62 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \ |
| 63 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) ) ) |
| 64 | #define BUILTIN_ALG_SHA_384 1 |
| 65 | #endif |
| 66 | #if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \ |
| 67 | ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) ) ) |
| 68 | #define BUILTIN_ALG_SHA_512 1 |
| 69 | #endif |
| 70 | |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 71 | #if ( defined(BUILTIN_ALG_MD2) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD2) ) || \ |
| 72 | ( defined(BUILTIN_ALG_MD4) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD4) ) || \ |
| 73 | ( defined(BUILTIN_ALG_MD5) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD5) ) || \ |
| 74 | ( defined(BUILTIN_ALG_RIPEMD160) && !defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) ) || \ |
| 75 | ( defined(BUILTIN_ALG_SHA_1) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) ) || \ |
| 76 | ( defined(BUILTIN_ALG_SHA_224) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) ) || \ |
| 77 | ( defined(BUILTIN_ALG_SHA_256) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) ) || \ |
| 78 | ( defined(BUILTIN_ALG_SHA_384) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) ) || \ |
| 79 | ( defined(BUILTIN_ALG_SHA_512) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) ) |
| 80 | #define INCLUDE_HASH_MBEDTLS_DRIVER 1 |
| 81 | #endif |
| 82 | |
| 83 | #if defined(PSA_CRYPTO_DRIVER_TEST) && \ |
| 84 | ( defined(MBEDTLS_PSA_ACCEL_ALG_MD2) || \ |
| 85 | defined(MBEDTLS_PSA_ACCEL_ALG_MD4) || \ |
| 86 | defined(MBEDTLS_PSA_ACCEL_ALG_MD5) || \ |
| 87 | defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) || \ |
| 88 | defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) || \ |
| 89 | defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || \ |
| 90 | defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) || \ |
| 91 | defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || \ |
| 92 | defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) ) |
| 93 | #define INCLUDE_HASH_TEST_DRIVER |
| 94 | #endif |
| 95 | |
| 96 | #if defined(INCLUDE_HASH_MBEDTLS_DRIVER) || \ |
| 97 | defined(INCLUDE_HASH_TEST_DRIVER) |
| 98 | #define INCLUDE_HASH_CORE 1 |
| 99 | #endif |
| 100 | |
| 101 | /* Implement the PSA driver hash interface on top of mbed TLS if either the |
| 102 | * software driver or the test driver requires it. */ |
| 103 | #if defined(INCLUDE_HASH_CORE) |
| 104 | static psa_status_t hash_abort( |
| 105 | mbedtls_psa_hash_operation_t *operation ) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 106 | { |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 107 | switch( operation->alg ) |
| 108 | { |
| 109 | case 0: |
| 110 | /* The object has (apparently) been initialized but it is not |
| 111 | * in use. It's ok to call abort on such an object, and there's |
| 112 | * nothing to do. */ |
| 113 | break; |
| 114 | #if defined(BUILTIN_ALG_MD2) |
| 115 | case PSA_ALG_MD2: |
| 116 | mbedtls_md2_free( &operation->ctx.md2 ); |
| 117 | break; |
| 118 | #endif |
| 119 | #if defined(BUILTIN_ALG_MD4) |
| 120 | case PSA_ALG_MD4: |
| 121 | mbedtls_md4_free( &operation->ctx.md4 ); |
| 122 | break; |
| 123 | #endif |
| 124 | #if defined(BUILTIN_ALG_MD5) |
| 125 | case PSA_ALG_MD5: |
| 126 | mbedtls_md5_free( &operation->ctx.md5 ); |
| 127 | break; |
| 128 | #endif |
| 129 | #if defined(BUILTIN_ALG_RIPEMD160) |
| 130 | case PSA_ALG_RIPEMD160: |
| 131 | mbedtls_ripemd160_free( &operation->ctx.ripemd160 ); |
| 132 | break; |
| 133 | #endif |
| 134 | #if defined(BUILTIN_ALG_SHA_1) |
| 135 | case PSA_ALG_SHA_1: |
| 136 | mbedtls_sha1_free( &operation->ctx.sha1 ); |
| 137 | break; |
| 138 | #endif |
| 139 | #if defined(BUILTIN_ALG_SHA_224) |
| 140 | case PSA_ALG_SHA_224: |
| 141 | mbedtls_sha256_free( &operation->ctx.sha256 ); |
| 142 | break; |
| 143 | #endif |
| 144 | #if defined(BUILTIN_ALG_SHA_256) |
| 145 | case PSA_ALG_SHA_256: |
| 146 | mbedtls_sha256_free( &operation->ctx.sha256 ); |
| 147 | break; |
| 148 | #endif |
| 149 | #if defined(BUILTIN_ALG_SHA_384) |
| 150 | case PSA_ALG_SHA_384: |
| 151 | mbedtls_sha512_free( &operation->ctx.sha512 ); |
| 152 | break; |
| 153 | #endif |
| 154 | #if defined(BUILTIN_ALG_SHA_512) |
| 155 | case PSA_ALG_SHA_512: |
| 156 | mbedtls_sha512_free( &operation->ctx.sha512 ); |
| 157 | break; |
| 158 | #endif |
| 159 | default: |
| 160 | return( PSA_ERROR_BAD_STATE ); |
| 161 | } |
| 162 | operation->alg = 0; |
| 163 | return( PSA_SUCCESS ); |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 166 | static psa_status_t hash_setup( |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 167 | mbedtls_psa_hash_operation_t *operation, |
| 168 | psa_algorithm_t alg ) |
| 169 | { |
| 170 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 171 | |
| 172 | /* A context must be freshly initialized before it can be set up. */ |
| 173 | if( operation->alg != 0 ) |
| 174 | { |
| 175 | return( PSA_ERROR_BAD_STATE ); |
| 176 | } |
| 177 | |
| 178 | switch( alg ) |
| 179 | { |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 180 | #if defined(BUILTIN_ALG_MD2) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 181 | case PSA_ALG_MD2: |
| 182 | mbedtls_md2_init( &operation->ctx.md2 ); |
| 183 | ret = mbedtls_md2_starts_ret( &operation->ctx.md2 ); |
| 184 | break; |
| 185 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 186 | #if defined(BUILTIN_ALG_MD4) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 187 | case PSA_ALG_MD4: |
| 188 | mbedtls_md4_init( &operation->ctx.md4 ); |
| 189 | ret = mbedtls_md4_starts_ret( &operation->ctx.md4 ); |
| 190 | break; |
| 191 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 192 | #if defined(BUILTIN_ALG_MD5) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 193 | case PSA_ALG_MD5: |
| 194 | mbedtls_md5_init( &operation->ctx.md5 ); |
| 195 | ret = mbedtls_md5_starts_ret( &operation->ctx.md5 ); |
| 196 | break; |
| 197 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 198 | #if defined(BUILTIN_ALG_RIPEMD160) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 199 | case PSA_ALG_RIPEMD160: |
| 200 | mbedtls_ripemd160_init( &operation->ctx.ripemd160 ); |
| 201 | ret = mbedtls_ripemd160_starts_ret( &operation->ctx.ripemd160 ); |
| 202 | break; |
| 203 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 204 | #if defined(BUILTIN_ALG_SHA_1) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 205 | case PSA_ALG_SHA_1: |
| 206 | mbedtls_sha1_init( &operation->ctx.sha1 ); |
| 207 | ret = mbedtls_sha1_starts_ret( &operation->ctx.sha1 ); |
| 208 | break; |
| 209 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 210 | #if defined(BUILTIN_ALG_SHA_224) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 211 | case PSA_ALG_SHA_224: |
| 212 | mbedtls_sha256_init( &operation->ctx.sha256 ); |
| 213 | ret = mbedtls_sha256_starts_ret( &operation->ctx.sha256, 1 ); |
| 214 | break; |
| 215 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 216 | #if defined(BUILTIN_ALG_SHA_256) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 217 | case PSA_ALG_SHA_256: |
| 218 | mbedtls_sha256_init( &operation->ctx.sha256 ); |
| 219 | ret = mbedtls_sha256_starts_ret( &operation->ctx.sha256, 0 ); |
| 220 | break; |
| 221 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 222 | #if defined(BUILTIN_ALG_SHA_384) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 223 | case PSA_ALG_SHA_384: |
| 224 | mbedtls_sha512_init( &operation->ctx.sha512 ); |
| 225 | ret = mbedtls_sha512_starts_ret( &operation->ctx.sha512, 1 ); |
| 226 | break; |
| 227 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 228 | #if defined(BUILTIN_ALG_SHA_512) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 229 | case PSA_ALG_SHA_512: |
| 230 | mbedtls_sha512_init( &operation->ctx.sha512 ); |
| 231 | ret = mbedtls_sha512_starts_ret( &operation->ctx.sha512, 0 ); |
| 232 | break; |
| 233 | #endif |
| 234 | default: |
| 235 | return( PSA_ALG_IS_HASH( alg ) ? |
| 236 | PSA_ERROR_NOT_SUPPORTED : |
| 237 | PSA_ERROR_INVALID_ARGUMENT ); |
| 238 | } |
| 239 | if( ret == 0 ) |
| 240 | operation->alg = alg; |
| 241 | else |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 242 | hash_abort( operation ); |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 243 | return( mbedtls_to_psa_error( ret ) ); |
| 244 | } |
| 245 | |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 246 | static psa_status_t hash_clone( |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 247 | const mbedtls_psa_hash_operation_t *source_operation, |
| 248 | mbedtls_psa_hash_operation_t *target_operation ) |
| 249 | { |
| 250 | switch( source_operation->alg ) |
| 251 | { |
| 252 | case 0: |
| 253 | return( PSA_ERROR_BAD_STATE ); |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 254 | #if defined(BUILTIN_ALG_MD2) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 255 | case PSA_ALG_MD2: |
| 256 | mbedtls_md2_clone( &target_operation->ctx.md2, |
| 257 | &source_operation->ctx.md2 ); |
| 258 | break; |
| 259 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 260 | #if defined(BUILTIN_ALG_MD4) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 261 | case PSA_ALG_MD4: |
| 262 | mbedtls_md4_clone( &target_operation->ctx.md4, |
| 263 | &source_operation->ctx.md4 ); |
| 264 | break; |
| 265 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 266 | #if defined(BUILTIN_ALG_MD5) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 267 | case PSA_ALG_MD5: |
| 268 | mbedtls_md5_clone( &target_operation->ctx.md5, |
| 269 | &source_operation->ctx.md5 ); |
| 270 | break; |
| 271 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 272 | #if defined(BUILTIN_ALG_RIPEMD160) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 273 | case PSA_ALG_RIPEMD160: |
| 274 | mbedtls_ripemd160_clone( &target_operation->ctx.ripemd160, |
| 275 | &source_operation->ctx.ripemd160 ); |
| 276 | break; |
| 277 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 278 | #if defined(BUILTIN_ALG_SHA_1) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 279 | case PSA_ALG_SHA_1: |
| 280 | mbedtls_sha1_clone( &target_operation->ctx.sha1, |
| 281 | &source_operation->ctx.sha1 ); |
| 282 | break; |
| 283 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 284 | #if defined(BUILTIN_ALG_SHA_224) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 285 | case PSA_ALG_SHA_224: |
| 286 | mbedtls_sha256_clone( &target_operation->ctx.sha256, |
| 287 | &source_operation->ctx.sha256 ); |
| 288 | break; |
| 289 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 290 | #if defined(BUILTIN_ALG_SHA_256) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 291 | case PSA_ALG_SHA_256: |
| 292 | mbedtls_sha256_clone( &target_operation->ctx.sha256, |
| 293 | &source_operation->ctx.sha256 ); |
| 294 | break; |
| 295 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 296 | #if defined(BUILTIN_ALG_SHA_384) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 297 | case PSA_ALG_SHA_384: |
| 298 | mbedtls_sha512_clone( &target_operation->ctx.sha512, |
| 299 | &source_operation->ctx.sha512 ); |
| 300 | break; |
| 301 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 302 | #if defined(BUILTIN_ALG_SHA_512) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 303 | case PSA_ALG_SHA_512: |
| 304 | mbedtls_sha512_clone( &target_operation->ctx.sha512, |
| 305 | &source_operation->ctx.sha512 ); |
| 306 | break; |
| 307 | #endif |
| 308 | default: |
Steven Cooreman | 5adf52c | 2021-03-04 18:09:49 +0100 | [diff] [blame] | 309 | (void) source_operation; |
| 310 | (void) target_operation; |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 311 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 312 | } |
| 313 | |
| 314 | target_operation->alg = source_operation->alg; |
| 315 | return( PSA_SUCCESS ); |
| 316 | } |
| 317 | |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 318 | static psa_status_t hash_update( |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 319 | mbedtls_psa_hash_operation_t *operation, |
| 320 | const uint8_t *input, |
| 321 | size_t input_length ) |
| 322 | { |
| 323 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 324 | |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 325 | switch( operation->alg ) |
| 326 | { |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 327 | #if defined(BUILTIN_ALG_MD2) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 328 | case PSA_ALG_MD2: |
| 329 | ret = mbedtls_md2_update_ret( &operation->ctx.md2, |
| 330 | input, input_length ); |
| 331 | break; |
| 332 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 333 | #if defined(BUILTIN_ALG_MD4) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 334 | case PSA_ALG_MD4: |
| 335 | ret = mbedtls_md4_update_ret( &operation->ctx.md4, |
| 336 | input, input_length ); |
| 337 | break; |
| 338 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 339 | #if defined(BUILTIN_ALG_MD5) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 340 | case PSA_ALG_MD5: |
| 341 | ret = mbedtls_md5_update_ret( &operation->ctx.md5, |
| 342 | input, input_length ); |
| 343 | break; |
| 344 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 345 | #if defined(BUILTIN_ALG_RIPEMD160) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 346 | case PSA_ALG_RIPEMD160: |
| 347 | ret = mbedtls_ripemd160_update_ret( &operation->ctx.ripemd160, |
| 348 | input, input_length ); |
| 349 | break; |
| 350 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 351 | #if defined(BUILTIN_ALG_SHA_1) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 352 | case PSA_ALG_SHA_1: |
| 353 | ret = mbedtls_sha1_update_ret( &operation->ctx.sha1, |
| 354 | input, input_length ); |
| 355 | break; |
| 356 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 357 | #if defined(BUILTIN_ALG_SHA_224) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 358 | case PSA_ALG_SHA_224: |
| 359 | ret = mbedtls_sha256_update_ret( &operation->ctx.sha256, |
| 360 | input, input_length ); |
| 361 | break; |
| 362 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 363 | #if defined(BUILTIN_ALG_SHA_256) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 364 | case PSA_ALG_SHA_256: |
| 365 | ret = mbedtls_sha256_update_ret( &operation->ctx.sha256, |
| 366 | input, input_length ); |
| 367 | break; |
| 368 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 369 | #if defined(BUILTIN_ALG_SHA_384) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 370 | case PSA_ALG_SHA_384: |
| 371 | ret = mbedtls_sha512_update_ret( &operation->ctx.sha512, |
| 372 | input, input_length ); |
| 373 | break; |
| 374 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 375 | #if defined(BUILTIN_ALG_SHA_512) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 376 | case PSA_ALG_SHA_512: |
| 377 | ret = mbedtls_sha512_update_ret( &operation->ctx.sha512, |
| 378 | input, input_length ); |
| 379 | break; |
| 380 | #endif |
| 381 | default: |
Steven Cooreman | 5adf52c | 2021-03-04 18:09:49 +0100 | [diff] [blame] | 382 | (void) input; |
| 383 | (void) input_length; |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 384 | return( PSA_ERROR_BAD_STATE ); |
| 385 | } |
| 386 | |
| 387 | if( ret != 0 ) |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 388 | hash_abort( operation ); |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 389 | return( mbedtls_to_psa_error( ret ) ); |
| 390 | } |
| 391 | |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 392 | static psa_status_t hash_finish( |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 393 | mbedtls_psa_hash_operation_t *operation, |
| 394 | uint8_t *hash, |
| 395 | size_t hash_size, |
| 396 | size_t *hash_length ) |
| 397 | { |
| 398 | psa_status_t status; |
| 399 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 400 | size_t actual_hash_length = PSA_HASH_LENGTH( operation->alg ); |
| 401 | |
| 402 | /* Fill the output buffer with something that isn't a valid hash |
| 403 | * (barring an attack on the hash and deliberately-crafted input), |
| 404 | * in case the caller doesn't check the return status properly. */ |
| 405 | *hash_length = hash_size; |
| 406 | /* If hash_size is 0 then hash may be NULL and then the |
| 407 | * call to memset would have undefined behavior. */ |
| 408 | if( hash_size != 0 ) |
| 409 | memset( hash, '!', hash_size ); |
| 410 | |
| 411 | if( hash_size < actual_hash_length ) |
| 412 | { |
| 413 | status = PSA_ERROR_BUFFER_TOO_SMALL; |
| 414 | goto exit; |
| 415 | } |
| 416 | |
| 417 | switch( operation->alg ) |
| 418 | { |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 419 | #if defined(BUILTIN_ALG_MD2) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 420 | case PSA_ALG_MD2: |
| 421 | ret = mbedtls_md2_finish_ret( &operation->ctx.md2, hash ); |
| 422 | break; |
| 423 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 424 | #if defined(BUILTIN_ALG_MD4) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 425 | case PSA_ALG_MD4: |
| 426 | ret = mbedtls_md4_finish_ret( &operation->ctx.md4, hash ); |
| 427 | break; |
| 428 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 429 | #if defined(BUILTIN_ALG_MD5) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 430 | case PSA_ALG_MD5: |
| 431 | ret = mbedtls_md5_finish_ret( &operation->ctx.md5, hash ); |
| 432 | break; |
| 433 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 434 | #if defined(BUILTIN_ALG_RIPEMD160) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 435 | case PSA_ALG_RIPEMD160: |
| 436 | ret = mbedtls_ripemd160_finish_ret( &operation->ctx.ripemd160, hash ); |
| 437 | break; |
| 438 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 439 | #if defined(BUILTIN_ALG_SHA_1) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 440 | case PSA_ALG_SHA_1: |
| 441 | ret = mbedtls_sha1_finish_ret( &operation->ctx.sha1, hash ); |
| 442 | break; |
| 443 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 444 | #if defined(BUILTIN_ALG_SHA_224) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 445 | case PSA_ALG_SHA_224: |
| 446 | ret = mbedtls_sha256_finish_ret( &operation->ctx.sha256, hash ); |
| 447 | break; |
| 448 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 449 | #if defined(BUILTIN_ALG_SHA_256) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 450 | case PSA_ALG_SHA_256: |
| 451 | ret = mbedtls_sha256_finish_ret( &operation->ctx.sha256, hash ); |
| 452 | break; |
| 453 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 454 | #if defined(BUILTIN_ALG_SHA_384) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 455 | case PSA_ALG_SHA_384: |
| 456 | ret = mbedtls_sha512_finish_ret( &operation->ctx.sha512, hash ); |
| 457 | break; |
| 458 | #endif |
Steven Cooreman | 4f7d058 | 2021-03-08 13:59:42 +0100 | [diff] [blame] | 459 | #if defined(BUILTIN_ALG_SHA_512) |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 460 | case PSA_ALG_SHA_512: |
| 461 | ret = mbedtls_sha512_finish_ret( &operation->ctx.sha512, hash ); |
| 462 | break; |
| 463 | #endif |
| 464 | default: |
Steven Cooreman | 5adf52c | 2021-03-04 18:09:49 +0100 | [diff] [blame] | 465 | (void) hash; |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 466 | return( PSA_ERROR_BAD_STATE ); |
| 467 | } |
| 468 | status = mbedtls_to_psa_error( ret ); |
| 469 | |
| 470 | exit: |
| 471 | if( status == PSA_SUCCESS ) |
| 472 | { |
| 473 | *hash_length = actual_hash_length; |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 474 | return( hash_abort( operation ) ); |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 475 | } |
| 476 | else |
| 477 | { |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 478 | hash_abort( operation ); |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 479 | return( status ); |
| 480 | } |
| 481 | } |
| 482 | |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 483 | static psa_status_t hash_compute( |
| 484 | psa_algorithm_t alg, |
| 485 | const uint8_t *input, |
| 486 | size_t input_length, |
| 487 | uint8_t *hash, |
| 488 | size_t hash_size, |
| 489 | size_t *hash_length) |
| 490 | { |
| 491 | mbedtls_psa_hash_operation_t operation = MBEDTLS_PSA_HASH_OPERATION_INIT; |
| 492 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 493 | |
| 494 | *hash_length = hash_size; |
| 495 | status = hash_setup( &operation, alg ); |
| 496 | if( status != PSA_SUCCESS ) |
| 497 | goto exit; |
| 498 | status = hash_update( &operation, input, input_length ); |
| 499 | if( status != PSA_SUCCESS ) |
| 500 | goto exit; |
| 501 | status = hash_finish( &operation, hash, hash_size, hash_length ); |
| 502 | if( status != PSA_SUCCESS ) |
| 503 | goto exit; |
| 504 | |
| 505 | exit: |
| 506 | if( status == PSA_SUCCESS ) |
| 507 | status = hash_abort( &operation ); |
| 508 | else |
| 509 | hash_abort( &operation ); |
| 510 | return( status ); |
| 511 | } |
| 512 | #endif /* INCLUDE_HASH_CORE */ |
| 513 | |
| 514 | #if defined(INCLUDE_HASH_MBEDTLS_DRIVER) |
| 515 | psa_status_t mbedtls_psa_hash_compute( |
| 516 | psa_algorithm_t alg, |
| 517 | const uint8_t *input, |
| 518 | size_t input_length, |
| 519 | uint8_t *hash, |
| 520 | size_t hash_size, |
| 521 | size_t *hash_length) |
| 522 | { |
| 523 | return( hash_compute( alg, input, input_length, |
| 524 | hash, hash_size, hash_length ) ); |
| 525 | } |
| 526 | |
| 527 | psa_status_t mbedtls_psa_hash_setup( |
| 528 | mbedtls_psa_hash_operation_t *operation, |
| 529 | psa_algorithm_t alg ) |
| 530 | { |
| 531 | return( hash_setup( operation, alg ) ); |
| 532 | } |
| 533 | |
| 534 | psa_status_t mbedtls_psa_hash_clone( |
| 535 | const mbedtls_psa_hash_operation_t *source_operation, |
| 536 | mbedtls_psa_hash_operation_t *target_operation ) |
| 537 | { |
| 538 | return( hash_clone( source_operation, target_operation ) ); |
| 539 | } |
| 540 | |
| 541 | psa_status_t mbedtls_psa_hash_update( |
| 542 | mbedtls_psa_hash_operation_t *operation, |
| 543 | const uint8_t *input, |
| 544 | size_t input_length ) |
| 545 | { |
| 546 | return( hash_update( operation, input, input_length ) ); |
| 547 | } |
| 548 | |
| 549 | psa_status_t mbedtls_psa_hash_finish( |
| 550 | mbedtls_psa_hash_operation_t *operation, |
| 551 | uint8_t *hash, |
| 552 | size_t hash_size, |
| 553 | size_t *hash_length ) |
| 554 | { |
| 555 | return( hash_finish( operation, hash, hash_size, hash_length ) ); |
| 556 | } |
| 557 | |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 558 | psa_status_t mbedtls_psa_hash_abort( |
| 559 | mbedtls_psa_hash_operation_t *operation ) |
| 560 | { |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 561 | return( hash_abort( operation ) ); |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 562 | } |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 563 | #endif /* INCLUDE_HASH_MBEDTLS_DRIVER */ |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 564 | |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 565 | /* |
| 566 | * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY. |
| 567 | */ |
| 568 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
| 569 | |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 570 | #if defined(INCLUDE_HASH_TEST_DRIVER) |
| 571 | psa_status_t is_hash_accelerated( psa_algorithm_t alg ) |
| 572 | { |
| 573 | switch( alg ) |
| 574 | { |
| 575 | #if defined(MBEDTLS_PSA_ACCEL_ALG_MD2) |
| 576 | case PSA_ALG_MD2: |
| 577 | return( PSA_SUCCESS ); |
| 578 | #endif |
| 579 | #if defined(MBEDTLS_PSA_ACCEL_ALG_MD4) |
| 580 | case PSA_ALG_MD4: |
| 581 | return( PSA_SUCCESS ); |
| 582 | #endif |
| 583 | #if defined(MBEDTLS_PSA_ACCEL_ALG_MD5) |
| 584 | case PSA_ALG_MD5: |
| 585 | return( PSA_SUCCESS ); |
| 586 | #endif |
| 587 | #if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) |
| 588 | case PSA_ALG_RIPEMD160: |
| 589 | return( PSA_SUCCESS ); |
| 590 | #endif |
| 591 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) |
| 592 | case PSA_ALG_SHA_1: |
| 593 | return( PSA_SUCCESS ); |
| 594 | #endif |
| 595 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) |
| 596 | case PSA_ALG_SHA_224: |
| 597 | return( PSA_SUCCESS ); |
| 598 | #endif |
| 599 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) |
| 600 | case PSA_ALG_SHA_256: |
| 601 | return( PSA_SUCCESS ); |
| 602 | #endif |
| 603 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) |
| 604 | case PSA_ALG_SHA_384: |
| 605 | return( PSA_SUCCESS ); |
| 606 | #endif |
| 607 | #if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) |
| 608 | case PSA_ALG_SHA_512: |
| 609 | return( PSA_SUCCESS ); |
| 610 | #endif |
| 611 | default: |
| 612 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 613 | } |
| 614 | } |
| 615 | #endif /* INCLUDE_HASH_TEST_DRIVER */ |
| 616 | |
Steven Cooreman | 2555522 | 2021-03-08 16:20:04 +0100 | [diff] [blame] | 617 | psa_status_t mbedtls_transparent_test_driver_hash_compute( |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 618 | psa_algorithm_t alg, |
| 619 | const uint8_t *input, |
| 620 | size_t input_length, |
| 621 | uint8_t *hash, |
| 622 | size_t hash_size, |
| 623 | size_t *hash_length) |
| 624 | { |
| 625 | #if defined(INCLUDE_HASH_TEST_DRIVER) |
| 626 | if( is_hash_accelerated( alg ) == PSA_SUCCESS ) |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 627 | return( hash_compute( alg, input, input_length, |
| 628 | hash, hash_size, hash_length ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 629 | else |
| 630 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 631 | #else |
| 632 | (void) alg; |
| 633 | (void) input; |
| 634 | (void) input_length; |
| 635 | (void) hash; |
| 636 | (void) hash_size; |
| 637 | (void) hash_length; |
| 638 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 639 | #endif |
| 640 | } |
| 641 | |
Steven Cooreman | 2555522 | 2021-03-08 16:20:04 +0100 | [diff] [blame] | 642 | psa_status_t mbedtls_transparent_test_driver_hash_setup( |
| 643 | mbedtls_transparent_test_driver_hash_operation_t *operation, |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 644 | psa_algorithm_t alg ) |
| 645 | { |
| 646 | #if defined(INCLUDE_HASH_TEST_DRIVER) |
| 647 | if( is_hash_accelerated( alg ) == PSA_SUCCESS ) |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 648 | return( hash_setup( &operation->operation, alg ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 649 | else |
| 650 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 651 | #else |
| 652 | (void) alg; |
| 653 | (void) operation; |
| 654 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 655 | #endif |
| 656 | } |
| 657 | |
Steven Cooreman | 2555522 | 2021-03-08 16:20:04 +0100 | [diff] [blame] | 658 | psa_status_t mbedtls_transparent_test_driver_hash_clone( |
| 659 | const mbedtls_transparent_test_driver_hash_operation_t *source_operation, |
| 660 | mbedtls_transparent_test_driver_hash_operation_t *target_operation ) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 661 | { |
| 662 | #if defined(INCLUDE_HASH_TEST_DRIVER) |
| 663 | if( is_hash_accelerated( source_operation->operation.alg ) == PSA_SUCCESS ) |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 664 | return( hash_clone( &source_operation->operation, |
| 665 | &target_operation->operation ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 666 | else |
| 667 | return( PSA_ERROR_BAD_STATE ); |
| 668 | #else |
| 669 | (void) source_operation; |
| 670 | (void) target_operation; |
| 671 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 672 | #endif |
| 673 | } |
| 674 | |
Steven Cooreman | 2555522 | 2021-03-08 16:20:04 +0100 | [diff] [blame] | 675 | psa_status_t mbedtls_transparent_test_driver_hash_update( |
| 676 | mbedtls_transparent_test_driver_hash_operation_t *operation, |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 677 | const uint8_t *input, |
| 678 | size_t input_length ) |
| 679 | { |
| 680 | #if defined(INCLUDE_HASH_TEST_DRIVER) |
| 681 | if( is_hash_accelerated( operation->operation.alg ) == PSA_SUCCESS ) |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 682 | return( hash_update( &operation->operation, |
| 683 | input, input_length ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 684 | else |
| 685 | return( PSA_ERROR_BAD_STATE ); |
| 686 | #else |
| 687 | (void) operation; |
| 688 | (void) input; |
| 689 | (void) input_length; |
| 690 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 691 | #endif |
| 692 | } |
| 693 | |
Steven Cooreman | 2555522 | 2021-03-08 16:20:04 +0100 | [diff] [blame] | 694 | psa_status_t mbedtls_transparent_test_driver_hash_finish( |
| 695 | mbedtls_transparent_test_driver_hash_operation_t *operation, |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 696 | uint8_t *hash, |
| 697 | size_t hash_size, |
| 698 | size_t *hash_length ) |
| 699 | { |
| 700 | #if defined(INCLUDE_HASH_TEST_DRIVER) |
| 701 | if( is_hash_accelerated( operation->operation.alg ) == PSA_SUCCESS ) |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 702 | return( hash_finish( &operation->operation, |
| 703 | hash, hash_size, hash_length ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 704 | else |
| 705 | return( PSA_ERROR_BAD_STATE ); |
| 706 | #else |
| 707 | (void) operation; |
| 708 | (void) hash; |
| 709 | (void) hash_size; |
| 710 | (void) hash_length; |
| 711 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 712 | #endif |
| 713 | } |
| 714 | |
Steven Cooreman | 2555522 | 2021-03-08 16:20:04 +0100 | [diff] [blame] | 715 | psa_status_t mbedtls_transparent_test_driver_hash_abort( |
| 716 | mbedtls_transparent_test_driver_hash_operation_t *operation ) |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 717 | { |
| 718 | #if defined(INCLUDE_HASH_TEST_DRIVER) |
Steven Cooreman | 83f300e | 2021-03-08 17:09:48 +0100 | [diff] [blame^] | 719 | return( hash_abort( &operation->operation ) ); |
Steven Cooreman | f763810 | 2021-03-04 15:14:36 +0100 | [diff] [blame] | 720 | #else |
| 721 | (void) operation; |
| 722 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 723 | #endif |
| 724 | } |
| 725 | |
| 726 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 727 | |
Steven Cooreman | 0e30764 | 2021-02-18 16:18:32 +0100 | [diff] [blame] | 728 | #endif /* MBEDTLS_PSA_CRYPTO_C */ |