Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PSA RSA layer on top of Mbed TLS 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" |
Ronald Cron | 9e18fc1 | 2020-11-05 17:36:40 +0100 | [diff] [blame] | 27 | #include "psa_crypto_random_impl.h" |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 28 | #include "psa_crypto_rsa.h" |
Steven Cooreman | 5f88e77 | 2021-03-15 11:07:12 +0100 | [diff] [blame] | 29 | #include "psa_crypto_hash.h" |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 30 | |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | #include "mbedtls/platform.h" |
| 34 | #if !defined(MBEDTLS_PLATFORM_C) |
| 35 | #define mbedtls_calloc calloc |
| 36 | #define mbedtls_free free |
| 37 | #endif |
| 38 | |
| 39 | #include <mbedtls/rsa.h> |
| 40 | #include <mbedtls/error.h> |
| 41 | #include <mbedtls/pk.h> |
Dave Rodgman | 3b5e6f0 | 2021-04-06 17:58:16 +0100 | [diff] [blame] | 42 | #include "pk_wrap.h" |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 43 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 44 | #if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \ |
| 45 | ( defined(PSA_CRYPTO_DRIVER_TEST) && \ |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame^] | 46 | defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \ |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 47 | defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) ) ) |
| 48 | #define BUILTIN_KEY_TYPE_RSA_KEY_PAIR 1 |
| 49 | #endif |
| 50 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame^] | 51 | #if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) || \ |
| 52 | ( defined(PSA_CRYPTO_DRIVER_TEST) && \ |
| 53 | defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \ |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 54 | defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) ) ) |
| 55 | #define BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY 1 |
| 56 | #endif |
| 57 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 58 | #if ( defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ |
| 59 | ( defined(PSA_CRYPTO_DRIVER_TEST) && \ |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame^] | 60 | defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \ |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 61 | defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) && \ |
| 62 | defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V15) ) ) |
| 63 | #define BUILTIN_ALG_RSA_PKCS1V15_SIGN 1 |
| 64 | #endif |
| 65 | |
| 66 | #if ( defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \ |
| 67 | ( defined(PSA_CRYPTO_DRIVER_TEST) && \ |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame^] | 68 | defined(MBEDTLS_PSA_CRYPTO_CONFIG) && \ |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 69 | defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) && \ |
| 70 | defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) ) ) |
| 71 | #define BUILTIN_ALG_RSA_PSS 1 |
| 72 | #endif |
| 73 | |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 74 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \ |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 75 | defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \ |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 76 | defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ |
| 77 | defined(BUILTIN_ALG_RSA_PSS) || \ |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 78 | defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \ |
| 79 | defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 80 | |
| 81 | /* Mbed TLS doesn't support non-byte-aligned key sizes (i.e. key sizes |
| 82 | * that are not a multiple of 8) well. For example, there is only |
| 83 | * mbedtls_rsa_get_len(), which returns a number of bytes, and no |
| 84 | * way to return the exact bit size of a key. |
| 85 | * To keep things simple, reject non-byte-aligned key sizes. */ |
| 86 | static psa_status_t psa_check_rsa_key_byte_aligned( |
| 87 | const mbedtls_rsa_context *rsa ) |
| 88 | { |
| 89 | mbedtls_mpi n; |
| 90 | psa_status_t status; |
| 91 | mbedtls_mpi_init( &n ); |
| 92 | status = mbedtls_to_psa_error( |
| 93 | mbedtls_rsa_export( rsa, &n, NULL, NULL, NULL, NULL ) ); |
| 94 | if( status == PSA_SUCCESS ) |
| 95 | { |
| 96 | if( mbedtls_mpi_bitlen( &n ) % 8 != 0 ) |
| 97 | status = PSA_ERROR_NOT_SUPPORTED; |
| 98 | } |
| 99 | mbedtls_mpi_free( &n ); |
| 100 | return( status ); |
| 101 | } |
| 102 | |
| 103 | psa_status_t mbedtls_psa_rsa_load_representation( |
| 104 | psa_key_type_t type, const uint8_t *data, size_t data_length, |
| 105 | mbedtls_rsa_context **p_rsa ) |
| 106 | { |
| 107 | psa_status_t status; |
| 108 | mbedtls_pk_context ctx; |
| 109 | size_t bits; |
| 110 | mbedtls_pk_init( &ctx ); |
| 111 | |
| 112 | /* Parse the data. */ |
| 113 | if( PSA_KEY_TYPE_IS_KEY_PAIR( type ) ) |
| 114 | status = mbedtls_to_psa_error( |
Manuel Pégourié-Gonnard | 84dea01 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 115 | mbedtls_pk_parse_key( &ctx, data, data_length, NULL, 0, |
| 116 | mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE ) ); |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 117 | else |
| 118 | status = mbedtls_to_psa_error( |
| 119 | mbedtls_pk_parse_public_key( &ctx, data, data_length ) ); |
| 120 | if( status != PSA_SUCCESS ) |
| 121 | goto exit; |
| 122 | |
| 123 | /* We have something that the pkparse module recognizes. If it is a |
| 124 | * valid RSA key, store it. */ |
| 125 | if( mbedtls_pk_get_type( &ctx ) != MBEDTLS_PK_RSA ) |
| 126 | { |
| 127 | status = PSA_ERROR_INVALID_ARGUMENT; |
| 128 | goto exit; |
| 129 | } |
| 130 | |
| 131 | /* The size of an RSA key doesn't have to be a multiple of 8. Mbed TLS |
| 132 | * supports non-byte-aligned key sizes, but not well. For example, |
| 133 | * mbedtls_rsa_get_len() returns the key size in bytes, not in bits. */ |
| 134 | bits = PSA_BYTES_TO_BITS( mbedtls_rsa_get_len( mbedtls_pk_rsa( ctx ) ) ); |
| 135 | if( bits > PSA_VENDOR_RSA_MAX_KEY_BITS ) |
| 136 | { |
| 137 | status = PSA_ERROR_NOT_SUPPORTED; |
| 138 | goto exit; |
| 139 | } |
| 140 | status = psa_check_rsa_key_byte_aligned( mbedtls_pk_rsa( ctx ) ); |
| 141 | if( status != PSA_SUCCESS ) |
| 142 | goto exit; |
| 143 | |
| 144 | /* Copy out the pointer to the RSA context, and reset the PK context |
| 145 | * such that pk_free doesn't free the RSA context we just grabbed. */ |
| 146 | *p_rsa = mbedtls_pk_rsa( ctx ); |
| 147 | ctx.pk_info = NULL; |
| 148 | |
| 149 | exit: |
| 150 | mbedtls_pk_free( &ctx ); |
| 151 | return( status ); |
| 152 | } |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 153 | #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 154 | * defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 155 | * defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) || |
| 156 | * defined(BUILTIN_ALG_RSA_PSS) || |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 157 | * defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || |
| 158 | * defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 159 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 160 | #if defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \ |
| 161 | defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) |
Ronald Cron | abf2aef | 2020-11-27 18:13:44 +0100 | [diff] [blame] | 162 | |
Ronald Cron | 784fb32 | 2020-11-30 13:55:05 +0100 | [diff] [blame] | 163 | static psa_status_t rsa_import_key( |
Ronald Cron | abf2aef | 2020-11-27 18:13:44 +0100 | [diff] [blame] | 164 | const psa_key_attributes_t *attributes, |
| 165 | const uint8_t *data, size_t data_length, |
| 166 | uint8_t *key_buffer, size_t key_buffer_size, |
| 167 | size_t *key_buffer_length, size_t *bits ) |
| 168 | { |
| 169 | psa_status_t status; |
| 170 | mbedtls_rsa_context *rsa = NULL; |
| 171 | |
| 172 | /* Parse input */ |
| 173 | status = mbedtls_psa_rsa_load_representation( attributes->core.type, |
| 174 | data, |
| 175 | data_length, |
| 176 | &rsa ); |
| 177 | if( status != PSA_SUCCESS ) |
| 178 | goto exit; |
| 179 | |
| 180 | *bits = (psa_key_bits_t) PSA_BYTES_TO_BITS( mbedtls_rsa_get_len( rsa ) ); |
| 181 | |
| 182 | /* Re-export the data to PSA export format, such that we can store export |
| 183 | * representation in the key slot. Export representation in case of RSA is |
| 184 | * the smallest representation that's allowed as input, so a straight-up |
| 185 | * allocation of the same size as the input buffer will be large enough. */ |
| 186 | status = mbedtls_psa_rsa_export_key( attributes->core.type, |
| 187 | rsa, |
| 188 | key_buffer, |
| 189 | key_buffer_size, |
| 190 | key_buffer_length ); |
| 191 | exit: |
| 192 | /* Always free the RSA object */ |
| 193 | mbedtls_rsa_free( rsa ); |
| 194 | mbedtls_free( rsa ); |
| 195 | |
| 196 | return( status ); |
| 197 | } |
| 198 | |
Ronald Cron | e5ca3d8 | 2020-11-26 16:36:16 +0100 | [diff] [blame] | 199 | psa_status_t mbedtls_psa_rsa_export_key( psa_key_type_t type, |
| 200 | mbedtls_rsa_context *rsa, |
| 201 | uint8_t *data, |
| 202 | size_t data_size, |
| 203 | size_t *data_length ) |
| 204 | { |
| 205 | #if defined(MBEDTLS_PK_WRITE_C) |
| 206 | int ret; |
| 207 | mbedtls_pk_context pk; |
| 208 | uint8_t *pos = data + data_size; |
| 209 | |
| 210 | mbedtls_pk_init( &pk ); |
| 211 | pk.pk_info = &mbedtls_rsa_info; |
| 212 | pk.pk_ctx = rsa; |
| 213 | |
| 214 | /* PSA Crypto API defines the format of an RSA key as a DER-encoded |
| 215 | * representation of the non-encrypted PKCS#1 RSAPrivateKey for a |
| 216 | * private key and of the RFC3279 RSAPublicKey for a public key. */ |
| 217 | if( PSA_KEY_TYPE_IS_KEY_PAIR( type ) ) |
| 218 | ret = mbedtls_pk_write_key_der( &pk, data, data_size ); |
| 219 | else |
| 220 | ret = mbedtls_pk_write_pubkey( &pos, data, &pk ); |
| 221 | |
| 222 | if( ret < 0 ) |
| 223 | { |
| 224 | /* Clean up in case pk_write failed halfway through. */ |
| 225 | memset( data, 0, data_size ); |
| 226 | return( mbedtls_to_psa_error( ret ) ); |
| 227 | } |
| 228 | |
| 229 | /* The mbedtls_pk_xxx functions write to the end of the buffer. |
| 230 | * Move the data to the beginning and erase remaining data |
| 231 | * at the original location. */ |
| 232 | if( 2 * (size_t) ret <= data_size ) |
| 233 | { |
| 234 | memcpy( data, data + data_size - ret, ret ); |
| 235 | memset( data + data_size - ret, 0, ret ); |
| 236 | } |
| 237 | else if( (size_t) ret < data_size ) |
| 238 | { |
| 239 | memmove( data, data + data_size - ret, ret ); |
| 240 | memset( data + ret, 0, data_size - ret ); |
| 241 | } |
| 242 | |
| 243 | *data_length = ret; |
| 244 | return( PSA_SUCCESS ); |
| 245 | #else |
| 246 | (void) type; |
| 247 | (void) rsa; |
| 248 | (void) data; |
| 249 | (void) data_size; |
| 250 | (void) data_length; |
| 251 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 252 | #endif /* MBEDTLS_PK_WRITE_C */ |
| 253 | } |
| 254 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 255 | static psa_status_t rsa_export_public_key( |
Ronald Cron | e5ca3d8 | 2020-11-26 16:36:16 +0100 | [diff] [blame] | 256 | const psa_key_attributes_t *attributes, |
| 257 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 258 | uint8_t *data, size_t data_size, size_t *data_length ) |
| 259 | { |
| 260 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 261 | mbedtls_rsa_context *rsa = NULL; |
| 262 | |
| 263 | status = mbedtls_psa_rsa_load_representation( |
| 264 | attributes->core.type, key_buffer, key_buffer_size, &rsa ); |
| 265 | if( status != PSA_SUCCESS ) |
| 266 | return( status ); |
| 267 | |
| 268 | status = mbedtls_psa_rsa_export_key( PSA_KEY_TYPE_RSA_PUBLIC_KEY, |
| 269 | rsa, |
| 270 | data, |
| 271 | data_size, |
| 272 | data_length ); |
| 273 | |
| 274 | mbedtls_rsa_free( rsa ); |
| 275 | mbedtls_free( rsa ); |
| 276 | |
| 277 | return( status ); |
| 278 | } |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 279 | #endif /* defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || |
| 280 | * defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ |
| 281 | |
Jaeden Amero | 424fa93 | 2021-05-14 08:34:32 +0100 | [diff] [blame] | 282 | #if defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) && \ |
| 283 | defined(MBEDTLS_GENPRIME) |
Ronald Cron | 2365fde | 2021-02-08 09:52:24 +0100 | [diff] [blame] | 284 | static psa_status_t psa_rsa_read_exponent( const uint8_t *domain_parameters, |
Ronald Cron | 9e18fc1 | 2020-11-05 17:36:40 +0100 | [diff] [blame] | 285 | size_t domain_parameters_size, |
| 286 | int *exponent ) |
| 287 | { |
| 288 | size_t i; |
| 289 | uint32_t acc = 0; |
| 290 | |
| 291 | if( domain_parameters_size == 0 ) |
| 292 | { |
| 293 | *exponent = 65537; |
| 294 | return( PSA_SUCCESS ); |
| 295 | } |
| 296 | |
| 297 | /* Mbed TLS encodes the public exponent as an int. For simplicity, only |
| 298 | * support values that fit in a 32-bit integer, which is larger than |
| 299 | * int on just about every platform anyway. */ |
| 300 | if( domain_parameters_size > sizeof( acc ) ) |
| 301 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 302 | for( i = 0; i < domain_parameters_size; i++ ) |
| 303 | acc = ( acc << 8 ) | domain_parameters[i]; |
| 304 | if( acc > INT_MAX ) |
| 305 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 306 | *exponent = acc; |
| 307 | return( PSA_SUCCESS ); |
| 308 | } |
| 309 | |
Ronald Cron | 3a9c46b | 2020-11-06 09:38:35 +0100 | [diff] [blame] | 310 | static psa_status_t rsa_generate_key( |
Ronald Cron | 9e18fc1 | 2020-11-05 17:36:40 +0100 | [diff] [blame] | 311 | const psa_key_attributes_t *attributes, |
| 312 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) |
| 313 | { |
| 314 | psa_status_t status; |
| 315 | mbedtls_rsa_context rsa; |
| 316 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 317 | int exponent; |
| 318 | |
Ronald Cron | 2365fde | 2021-02-08 09:52:24 +0100 | [diff] [blame] | 319 | status = psa_rsa_read_exponent( attributes->domain_parameters, |
Ronald Cron | 9e18fc1 | 2020-11-05 17:36:40 +0100 | [diff] [blame] | 320 | attributes->domain_parameters_size, |
| 321 | &exponent ); |
| 322 | if( status != PSA_SUCCESS ) |
| 323 | return( status ); |
| 324 | |
Ronald Cron | c1905a1 | 2021-06-05 11:11:14 +0200 | [diff] [blame] | 325 | mbedtls_rsa_init( &rsa ); |
Ronald Cron | 9e18fc1 | 2020-11-05 17:36:40 +0100 | [diff] [blame] | 326 | ret = mbedtls_rsa_gen_key( &rsa, |
| 327 | mbedtls_psa_get_random, |
| 328 | MBEDTLS_PSA_RANDOM_STATE, |
| 329 | (unsigned int)attributes->core.bits, |
| 330 | exponent ); |
| 331 | if( ret != 0 ) |
| 332 | return( mbedtls_to_psa_error( ret ) ); |
| 333 | |
| 334 | status = mbedtls_psa_rsa_export_key( attributes->core.type, |
| 335 | &rsa, key_buffer, key_buffer_size, |
| 336 | key_buffer_length ); |
| 337 | mbedtls_rsa_free( &rsa ); |
| 338 | |
| 339 | return( status ); |
| 340 | } |
Jaeden Amero | 424fa93 | 2021-05-14 08:34:32 +0100 | [diff] [blame] | 341 | #endif /* defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) |
| 342 | * defined(MBEDTLS_GENPRIME) */ |
Ronald Cron | 9e18fc1 | 2020-11-05 17:36:40 +0100 | [diff] [blame] | 343 | |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 344 | /****************************************************************/ |
| 345 | /* Sign/verify hashes */ |
| 346 | /****************************************************************/ |
| 347 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 348 | #if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) || defined(BUILTIN_ALG_RSA_PSS) |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 349 | |
| 350 | /* Decode the hash algorithm from alg and store the mbedtls encoding in |
| 351 | * md_alg. Verify that the hash length is acceptable. */ |
| 352 | static psa_status_t psa_rsa_decode_md_type( psa_algorithm_t alg, |
| 353 | size_t hash_length, |
| 354 | mbedtls_md_type_t *md_alg ) |
| 355 | { |
| 356 | psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH( alg ); |
| 357 | const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa( hash_alg ); |
| 358 | *md_alg = mbedtls_md_get_type( md_info ); |
| 359 | |
| 360 | /* The Mbed TLS RSA module uses an unsigned int for hash length |
| 361 | * parameters. Validate that it fits so that we don't risk an |
| 362 | * overflow later. */ |
| 363 | #if SIZE_MAX > UINT_MAX |
| 364 | if( hash_length > UINT_MAX ) |
| 365 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 366 | #endif |
| 367 | |
Janos Follath | 0af093b | 2021-06-07 14:34:10 +0100 | [diff] [blame] | 368 | /* For signatures using a hash, the hash length must be correct. */ |
| 369 | if( alg != PSA_ALG_RSA_PKCS1V15_SIGN_RAW ) |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 370 | { |
| 371 | if( md_info == NULL ) |
| 372 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 373 | if( mbedtls_md_get_size( md_info ) != hash_length ) |
| 374 | return( PSA_ERROR_INVALID_ARGUMENT ); |
| 375 | } |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 376 | |
| 377 | return( PSA_SUCCESS ); |
| 378 | } |
| 379 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 380 | static psa_status_t rsa_sign_hash( |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 381 | const psa_key_attributes_t *attributes, |
| 382 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 383 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 384 | uint8_t *signature, size_t signature_size, size_t *signature_length ) |
| 385 | { |
| 386 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 387 | mbedtls_rsa_context *rsa = NULL; |
| 388 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 389 | mbedtls_md_type_t md_alg; |
| 390 | |
| 391 | status = mbedtls_psa_rsa_load_representation( attributes->core.type, |
| 392 | key_buffer, |
| 393 | key_buffer_size, |
| 394 | &rsa ); |
| 395 | if( status != PSA_SUCCESS ) |
| 396 | return( status ); |
| 397 | |
| 398 | status = psa_rsa_decode_md_type( alg, hash_length, &md_alg ); |
| 399 | if( status != PSA_SUCCESS ) |
| 400 | goto exit; |
| 401 | |
| 402 | if( signature_size < mbedtls_rsa_get_len( rsa ) ) |
| 403 | { |
| 404 | status = PSA_ERROR_BUFFER_TOO_SMALL; |
| 405 | goto exit; |
| 406 | } |
| 407 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 408 | #if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 409 | if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ) |
| 410 | { |
Ronald Cron | ea7631b | 2021-06-03 18:51:59 +0200 | [diff] [blame] | 411 | ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15, |
| 412 | MBEDTLS_MD_NONE ); |
| 413 | if( ret == 0 ) |
| 414 | { |
| 415 | ret = mbedtls_rsa_pkcs1_sign( rsa, |
| 416 | mbedtls_psa_get_random, |
| 417 | MBEDTLS_PSA_RANDOM_STATE, |
| 418 | md_alg, |
| 419 | (unsigned int) hash_length, |
| 420 | hash, |
| 421 | signature ); |
| 422 | } |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 423 | } |
| 424 | else |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 425 | #endif /* BUILTIN_ALG_RSA_PKCS1V15_SIGN */ |
| 426 | #if defined(BUILTIN_ALG_RSA_PSS) |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 427 | if( PSA_ALG_IS_RSA_PSS( alg ) ) |
| 428 | { |
Ronald Cron | ea7631b | 2021-06-03 18:51:59 +0200 | [diff] [blame] | 429 | ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg ); |
| 430 | |
| 431 | if( ret == 0 ) |
| 432 | { |
| 433 | ret = mbedtls_rsa_rsassa_pss_sign( rsa, |
| 434 | mbedtls_psa_get_random, |
| 435 | MBEDTLS_PSA_RANDOM_STATE, |
| 436 | MBEDTLS_MD_NONE, |
| 437 | (unsigned int) hash_length, |
| 438 | hash, |
| 439 | signature ); |
| 440 | } |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 441 | } |
| 442 | else |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 443 | #endif /* BUILTIN_ALG_RSA_PSS */ |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 444 | { |
| 445 | status = PSA_ERROR_INVALID_ARGUMENT; |
| 446 | goto exit; |
| 447 | } |
| 448 | |
| 449 | if( ret == 0 ) |
| 450 | *signature_length = mbedtls_rsa_get_len( rsa ); |
| 451 | status = mbedtls_to_psa_error( ret ); |
| 452 | |
| 453 | exit: |
| 454 | mbedtls_rsa_free( rsa ); |
| 455 | mbedtls_free( rsa ); |
| 456 | |
| 457 | return( status ); |
| 458 | } |
| 459 | |
Gilles Peskine | b9b817e | 2021-10-04 22:15:05 +0200 | [diff] [blame] | 460 | #if defined(BUILTIN_ALG_RSA_PSS) |
| 461 | static int rsa_pss_expected_salt_len( psa_algorithm_t alg, |
| 462 | const mbedtls_rsa_context *rsa, |
| 463 | size_t hash_length ) |
| 464 | { |
| 465 | if( PSA_ALG_IS_RSA_PSS_ANY_SALT( alg ) ) |
| 466 | return( MBEDTLS_RSA_SALT_LEN_ANY ); |
| 467 | /* Otherwise: standard salt length, i.e. largest possible salt length |
| 468 | * up to the hash length. */ |
Gilles Peskine | f6892de | 2021-10-08 16:28:32 +0200 | [diff] [blame] | 469 | int klen = (int) mbedtls_rsa_get_len( rsa ); // known to fit |
Gilles Peskine | b9b817e | 2021-10-04 22:15:05 +0200 | [diff] [blame] | 470 | int hlen = (int) hash_length; // known to fit |
| 471 | int room = klen - 2 - hlen; |
| 472 | if( room < 0 ) |
| 473 | return( 0 ); // there is no valid signature in this case anyway |
| 474 | else if( room > hlen ) |
| 475 | return( hlen ); |
| 476 | else |
| 477 | return( room ); |
| 478 | } |
| 479 | #endif |
| 480 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 481 | static psa_status_t rsa_verify_hash( |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 482 | const psa_key_attributes_t *attributes, |
| 483 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 484 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 485 | const uint8_t *signature, size_t signature_length ) |
| 486 | { |
| 487 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 488 | mbedtls_rsa_context *rsa = NULL; |
| 489 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
| 490 | mbedtls_md_type_t md_alg; |
| 491 | |
| 492 | status = mbedtls_psa_rsa_load_representation( attributes->core.type, |
| 493 | key_buffer, |
| 494 | key_buffer_size, |
| 495 | &rsa ); |
| 496 | if( status != PSA_SUCCESS ) |
| 497 | goto exit; |
| 498 | |
| 499 | status = psa_rsa_decode_md_type( alg, hash_length, &md_alg ); |
| 500 | if( status != PSA_SUCCESS ) |
| 501 | goto exit; |
| 502 | |
| 503 | if( signature_length != mbedtls_rsa_get_len( rsa ) ) |
| 504 | { |
| 505 | status = PSA_ERROR_INVALID_SIGNATURE; |
| 506 | goto exit; |
| 507 | } |
| 508 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 509 | #if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 510 | if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ) |
| 511 | { |
Ronald Cron | ea7631b | 2021-06-03 18:51:59 +0200 | [diff] [blame] | 512 | ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15, |
| 513 | MBEDTLS_MD_NONE ); |
| 514 | if( ret == 0 ) |
| 515 | { |
| 516 | ret = mbedtls_rsa_pkcs1_verify( rsa, |
| 517 | md_alg, |
| 518 | (unsigned int) hash_length, |
| 519 | hash, |
| 520 | signature ); |
| 521 | } |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 522 | } |
| 523 | else |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 524 | #endif /* BUILTIN_ALG_RSA_PKCS1V15_SIGN */ |
| 525 | #if defined(BUILTIN_ALG_RSA_PSS) |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 526 | if( PSA_ALG_IS_RSA_PSS( alg ) ) |
| 527 | { |
Ronald Cron | ea7631b | 2021-06-03 18:51:59 +0200 | [diff] [blame] | 528 | ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg ); |
| 529 | if( ret == 0 ) |
| 530 | { |
Gilles Peskine | b9b817e | 2021-10-04 22:15:05 +0200 | [diff] [blame] | 531 | int slen = rsa_pss_expected_salt_len( alg, rsa, hash_length ); |
| 532 | ret = mbedtls_rsa_rsassa_pss_verify_ext( rsa, |
| 533 | md_alg, |
| 534 | (unsigned) hash_length, |
| 535 | hash, |
| 536 | md_alg, |
| 537 | slen, |
| 538 | signature ); |
Ronald Cron | ea7631b | 2021-06-03 18:51:59 +0200 | [diff] [blame] | 539 | } |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 540 | } |
| 541 | else |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 542 | #endif /* BUILTIN_ALG_RSA_PSS */ |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 543 | { |
| 544 | status = PSA_ERROR_INVALID_ARGUMENT; |
| 545 | goto exit; |
| 546 | } |
| 547 | |
| 548 | /* Mbed TLS distinguishes "invalid padding" from "valid padding but |
| 549 | * the rest of the signature is invalid". This has little use in |
| 550 | * practice and PSA doesn't report this distinction. */ |
| 551 | status = ( ret == MBEDTLS_ERR_RSA_INVALID_PADDING ) ? |
| 552 | PSA_ERROR_INVALID_SIGNATURE : |
| 553 | mbedtls_to_psa_error( ret ); |
| 554 | |
| 555 | exit: |
| 556 | mbedtls_rsa_free( rsa ); |
| 557 | mbedtls_free( rsa ); |
| 558 | |
| 559 | return( status ); |
| 560 | } |
| 561 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 562 | #endif /* defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) || |
| 563 | * defined(BUILTIN_ALG_RSA_PSS) */ |
Ronald Cron | 7bdbca3 | 2020-12-09 13:34:54 +0100 | [diff] [blame] | 564 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 565 | #if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \ |
| 566 | defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) |
| 567 | |
Ronald Cron | 784fb32 | 2020-11-30 13:55:05 +0100 | [diff] [blame] | 568 | psa_status_t mbedtls_psa_rsa_import_key( |
| 569 | const psa_key_attributes_t *attributes, |
| 570 | const uint8_t *data, size_t data_length, |
| 571 | uint8_t *key_buffer, size_t key_buffer_size, |
| 572 | size_t *key_buffer_length, size_t *bits ) |
| 573 | { |
| 574 | return( rsa_import_key( attributes, data, data_length, |
| 575 | key_buffer, key_buffer_size, |
| 576 | key_buffer_length, bits ) ); |
| 577 | } |
| 578 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 579 | psa_status_t mbedtls_psa_rsa_export_public_key( |
| 580 | const psa_key_attributes_t *attributes, |
| 581 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 582 | uint8_t *data, size_t data_size, size_t *data_length ) |
| 583 | { |
| 584 | return( rsa_export_public_key( attributes, key_buffer, key_buffer_size, |
| 585 | data, data_size, data_length ) ); |
| 586 | } |
| 587 | |
Ronald Cron | e5ca3d8 | 2020-11-26 16:36:16 +0100 | [diff] [blame] | 588 | #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || |
| 589 | * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */ |
| 590 | |
Jaeden Amero | 424fa93 | 2021-05-14 08:34:32 +0100 | [diff] [blame] | 591 | #if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) && \ |
| 592 | defined(MBEDTLS_GENPRIME) |
Ronald Cron | 3a9c46b | 2020-11-06 09:38:35 +0100 | [diff] [blame] | 593 | psa_status_t mbedtls_psa_rsa_generate_key( |
| 594 | const psa_key_attributes_t *attributes, |
| 595 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) |
| 596 | { |
| 597 | return( rsa_generate_key( attributes, key_buffer, key_buffer_size, |
| 598 | key_buffer_length ) ); |
| 599 | } |
Jaeden Amero | 424fa93 | 2021-05-14 08:34:32 +0100 | [diff] [blame] | 600 | #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) |
| 601 | * defined(MBEDTLS_GENPRIME) */ |
Ronald Cron | 3a9c46b | 2020-11-06 09:38:35 +0100 | [diff] [blame] | 602 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 603 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ |
| 604 | defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) |
| 605 | psa_status_t mbedtls_psa_rsa_sign_hash( |
| 606 | const psa_key_attributes_t *attributes, |
| 607 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 608 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 609 | uint8_t *signature, size_t signature_size, size_t *signature_length ) |
| 610 | { |
| 611 | return( rsa_sign_hash( |
| 612 | attributes, |
| 613 | key_buffer, key_buffer_size, |
| 614 | alg, hash, hash_length, |
| 615 | signature, signature_size, signature_length ) ); |
| 616 | } |
| 617 | |
| 618 | psa_status_t mbedtls_psa_rsa_verify_hash( |
| 619 | const psa_key_attributes_t *attributes, |
| 620 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 621 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 622 | const uint8_t *signature, size_t signature_length ) |
| 623 | { |
| 624 | return( rsa_verify_hash( |
| 625 | attributes, |
| 626 | key_buffer, key_buffer_size, |
| 627 | alg, hash, hash_length, |
| 628 | signature, signature_length ) ); |
| 629 | } |
| 630 | #endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || |
| 631 | * defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) */ |
| 632 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 633 | /* |
| 634 | * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY. |
| 635 | */ |
| 636 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame^] | 637 | #if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_CRYPTO_CONFIG) |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 638 | |
| 639 | #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \ |
| 640 | defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) |
Ronald Cron | 784fb32 | 2020-11-30 13:55:05 +0100 | [diff] [blame] | 641 | |
Archana | 4d7ae1d | 2021-07-07 02:50:22 +0530 | [diff] [blame] | 642 | psa_status_t mbedtls_test_driver_rsa_import_key( |
Ronald Cron | 784fb32 | 2020-11-30 13:55:05 +0100 | [diff] [blame] | 643 | const psa_key_attributes_t *attributes, |
| 644 | const uint8_t *data, size_t data_length, |
| 645 | uint8_t *key_buffer, size_t key_buffer_size, |
| 646 | size_t *key_buffer_length, size_t *bits ) |
| 647 | { |
| 648 | return( rsa_import_key( attributes, data, data_length, |
| 649 | key_buffer, key_buffer_size, |
| 650 | key_buffer_length, bits ) ); |
| 651 | } |
| 652 | |
Archana | 4d7ae1d | 2021-07-07 02:50:22 +0530 | [diff] [blame] | 653 | psa_status_t mbedtls_test_driver_rsa_export_public_key( |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 654 | const psa_key_attributes_t *attributes, |
| 655 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 656 | uint8_t *data, size_t data_size, size_t *data_length ) |
| 657 | { |
| 658 | return( rsa_export_public_key( attributes, key_buffer, key_buffer_size, |
| 659 | data, data_size, data_length ) ); |
| 660 | } |
Ronald Cron | 784fb32 | 2020-11-30 13:55:05 +0100 | [diff] [blame] | 661 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 662 | #endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || |
| 663 | defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) */ |
| 664 | |
Ronald Cron | 3a9c46b | 2020-11-06 09:38:35 +0100 | [diff] [blame] | 665 | #if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) |
| 666 | psa_status_t mbedtls_transparent_test_driver_rsa_generate_key( |
| 667 | const psa_key_attributes_t *attributes, |
| 668 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ) |
| 669 | { |
| 670 | return( rsa_generate_key( attributes, key_buffer, key_buffer_size, |
| 671 | key_buffer_length ) ); |
| 672 | } |
| 673 | #endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) */ |
| 674 | |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 675 | #if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \ |
| 676 | defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) |
| 677 | psa_status_t mbedtls_transparent_test_driver_rsa_sign_hash( |
| 678 | const psa_key_attributes_t *attributes, |
| 679 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 680 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 681 | uint8_t *signature, size_t signature_size, size_t *signature_length ) |
| 682 | { |
| 683 | #if defined(MBEDTLS_RSA_C) && \ |
| 684 | (defined(MBEDTLS_PKCS1_V15) || defined(MBEDTLS_PKCS1_V21)) |
| 685 | return( rsa_sign_hash( |
| 686 | attributes, |
| 687 | key_buffer, key_buffer_size, |
| 688 | alg, hash, hash_length, |
| 689 | signature, signature_size, signature_length ) ); |
| 690 | #else |
| 691 | (void)attributes; |
| 692 | (void)key_buffer; |
| 693 | (void)key_buffer_size; |
| 694 | (void)alg; |
| 695 | (void)hash; |
| 696 | (void)hash_length; |
| 697 | (void)signature; |
| 698 | (void)signature_size; |
| 699 | (void)signature_length; |
| 700 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 701 | #endif |
| 702 | } |
| 703 | |
| 704 | psa_status_t mbedtls_transparent_test_driver_rsa_verify_hash( |
| 705 | const psa_key_attributes_t *attributes, |
| 706 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 707 | psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, |
| 708 | const uint8_t *signature, size_t signature_length ) |
| 709 | { |
| 710 | #if defined(MBEDTLS_RSA_C) && \ |
| 711 | (defined(MBEDTLS_PKCS1_V15) || defined(MBEDTLS_PKCS1_V21)) |
| 712 | return( rsa_verify_hash( |
| 713 | attributes, |
| 714 | key_buffer, key_buffer_size, |
| 715 | alg, hash, hash_length, |
| 716 | signature, signature_length ) ); |
| 717 | #else |
| 718 | (void)attributes; |
| 719 | (void)key_buffer; |
| 720 | (void)key_buffer_size; |
| 721 | (void)alg; |
| 722 | (void)hash; |
| 723 | (void)hash_length; |
| 724 | (void)signature; |
| 725 | (void)signature_length; |
| 726 | return( PSA_ERROR_NOT_SUPPORTED ); |
| 727 | #endif |
| 728 | } |
| 729 | #endif /* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || |
| 730 | * defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) */ |
| 731 | |
Ronald Cron | 73c9d9e | 2021-04-09 11:09:54 +0200 | [diff] [blame^] | 732 | #endif /* PSA_CRYPTO_DRIVER_TEST && MBEDTLS_PSA_CRYPTO_CONFIG */ |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 733 | |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 734 | #endif /* MBEDTLS_PSA_CRYPTO_C */ |