Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 1 | /* |
Steven Cooreman | 56250fd | 2020-09-04 13:07:15 +0200 | [diff] [blame] | 2 | * Test driver for signature functions. |
| 3 | * Currently supports signing and verifying precalculated hashes, using |
| 4 | * only deterministic ECDSA on curves secp256r1, secp384r1 and secp521r1. |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 5 | */ |
Steven Cooreman | 2c7b2f8 | 2020-09-02 13:43:46 +0200 | [diff] [blame] | 6 | /* Copyright The Mbed TLS Contributors |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 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. |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 23 | #include "mbedtls/config.h" |
| 24 | #else |
| 25 | #include MBEDTLS_CONFIG_FILE |
| 26 | #endif |
| 27 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 28 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 29 | #include "psa/crypto.h" |
Steven Cooreman | 15f58d2 | 2020-09-04 13:05:23 +0200 | [diff] [blame] | 30 | #include "psa_crypto_core.h" |
Ronald Cron | b5399a8 | 2020-12-10 09:35:33 +0100 | [diff] [blame] | 31 | #include "psa_crypto_ecp.h" |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 32 | #include "psa_crypto_hash.h" |
Ronald Cron | d2fb854 | 2020-12-09 15:18:01 +0100 | [diff] [blame] | 33 | #include "psa_crypto_rsa.h" |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 34 | #include "mbedtls/ecp.h" |
| 35 | |
Ronald Cron | d54303d | 2021-04-10 15:12:00 +0200 | [diff] [blame] | 36 | #include "test/drivers/hash.h" |
Steven Cooreman | 0d7c64d | 2020-09-07 16:17:55 +0200 | [diff] [blame] | 37 | #include "test/drivers/signature.h" |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 38 | #include "test/drivers/hash.h" |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 39 | |
| 40 | #include "mbedtls/md.h" |
| 41 | #include "mbedtls/ecdsa.h" |
| 42 | |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 43 | #include "test/random.h" |
| 44 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 45 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 46 | #include "libtestdriver1/library/psa_crypto_ecp.h" |
| 47 | #include "libtestdriver1/library/psa_crypto_hash.h" |
| 48 | #include "libtestdriver1/library/psa_crypto_rsa.h" |
| 49 | #endif |
| 50 | |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 51 | #include <string.h> |
| 52 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 53 | mbedtls_test_driver_signature_hooks_t |
| 54 | mbedtls_test_driver_signature_sign_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT; |
| 55 | mbedtls_test_driver_signature_hooks_t |
| 56 | mbedtls_test_driver_signature_verify_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT; |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 57 | |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 58 | psa_status_t sign_hash( |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 59 | const psa_key_attributes_t *attributes, |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 60 | const uint8_t *key_buffer, |
| 61 | size_t key_buffer_size, |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 62 | psa_algorithm_t alg, |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 63 | const uint8_t *hash, |
| 64 | size_t hash_length, |
| 65 | uint8_t *signature, |
| 66 | size_t signature_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 67 | size_t *signature_length) |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 68 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 69 | if (attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR) { |
| 70 | if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || |
| 71 | PSA_ALG_IS_RSA_PSS(alg)) { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 72 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 73 | (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ |
| 74 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)) |
| 75 | return libtestdriver1_mbedtls_psa_rsa_sign_hash( |
| 76 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 77 | key_buffer, key_buffer_size, |
| 78 | alg, hash, hash_length, |
| 79 | signature, signature_size, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 80 | #elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 81 | defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) |
| 82 | return mbedtls_psa_rsa_sign_hash( |
| 83 | attributes, |
| 84 | key_buffer, key_buffer_size, |
| 85 | alg, hash, hash_length, |
| 86 | signature, signature_size, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 87 | #endif |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 88 | } else { |
| 89 | return PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | b5399a8 | 2020-12-10 09:35:33 +0100 | [diff] [blame] | 90 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 91 | } else if (PSA_KEY_TYPE_IS_ECC(attributes->core.type)) { |
| 92 | if (PSA_ALG_IS_ECDSA(alg)) { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 93 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 94 | (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \ |
| 95 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) |
| 96 | return libtestdriver1_mbedtls_psa_ecdsa_sign_hash( |
| 97 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 98 | key_buffer, key_buffer_size, |
| 99 | alg, hash, hash_length, |
| 100 | signature, signature_size, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 101 | #elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 102 | defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) |
| 103 | return mbedtls_psa_ecdsa_sign_hash( |
| 104 | attributes, |
| 105 | key_buffer, key_buffer_size, |
| 106 | alg, hash, hash_length, |
| 107 | signature, signature_size, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 108 | #endif |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 109 | } else { |
| 110 | return PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | 4bcccc6 | 2021-04-09 15:32:03 +0200 | [diff] [blame] | 111 | } |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 112 | } |
Ronald Cron | 4bcccc6 | 2021-04-09 15:32:03 +0200 | [diff] [blame] | 113 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 114 | (void) attributes; |
| 115 | (void) key_buffer; |
| 116 | (void) key_buffer_size; |
| 117 | (void) alg; |
| 118 | (void) hash; |
| 119 | (void) hash_length; |
| 120 | (void) signature; |
| 121 | (void) signature_size; |
| 122 | (void) signature_length; |
| 123 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 124 | } |
| 125 | |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 126 | psa_status_t verify_hash( |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 127 | const psa_key_attributes_t *attributes, |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 128 | const uint8_t *key_buffer, |
| 129 | size_t key_buffer_size, |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 130 | psa_algorithm_t alg, |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 131 | const uint8_t *hash, |
| 132 | size_t hash_length, |
| 133 | const uint8_t *signature, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 134 | size_t signature_length) |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 135 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 136 | if (PSA_KEY_TYPE_IS_RSA(attributes->core.type)) { |
| 137 | if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || |
| 138 | PSA_ALG_IS_RSA_PSS(alg)) { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 139 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 140 | (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ |
| 141 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)) |
| 142 | return libtestdriver1_mbedtls_psa_rsa_verify_hash( |
| 143 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 144 | key_buffer, key_buffer_size, |
| 145 | alg, hash, hash_length, |
| 146 | signature, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 147 | #elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 148 | defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) |
| 149 | return mbedtls_psa_rsa_verify_hash( |
| 150 | attributes, |
| 151 | key_buffer, key_buffer_size, |
| 152 | alg, hash, hash_length, |
| 153 | signature, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 154 | #endif |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 155 | } else { |
| 156 | return PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | b5399a8 | 2020-12-10 09:35:33 +0100 | [diff] [blame] | 157 | } |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 158 | } else if (PSA_KEY_TYPE_IS_ECC(attributes->core.type)) { |
| 159 | if (PSA_ALG_IS_ECDSA(alg)) { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 160 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 161 | (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \ |
| 162 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)) |
| 163 | return libtestdriver1_mbedtls_psa_ecdsa_verify_hash( |
| 164 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 165 | key_buffer, key_buffer_size, |
| 166 | alg, hash, hash_length, |
| 167 | signature, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 168 | #elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 169 | defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) |
| 170 | return mbedtls_psa_ecdsa_verify_hash( |
| 171 | attributes, |
| 172 | key_buffer, key_buffer_size, |
| 173 | alg, hash, hash_length, |
| 174 | signature, signature_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 175 | #endif |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 176 | } else { |
| 177 | return PSA_ERROR_INVALID_ARGUMENT; |
Ronald Cron | 4bcccc6 | 2021-04-09 15:32:03 +0200 | [diff] [blame] | 178 | } |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 179 | } |
Ronald Cron | 4bcccc6 | 2021-04-09 15:32:03 +0200 | [diff] [blame] | 180 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 181 | (void) attributes; |
| 182 | (void) key_buffer; |
| 183 | (void) key_buffer_size; |
| 184 | (void) alg; |
| 185 | (void) hash; |
| 186 | (void) hash_length; |
| 187 | (void) signature; |
| 188 | (void) signature_length; |
| 189 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 190 | } |
| 191 | |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 192 | psa_status_t mbedtls_test_transparent_signature_sign_message( |
| 193 | const psa_key_attributes_t *attributes, |
| 194 | const uint8_t *key_buffer, |
| 195 | size_t key_buffer_size, |
| 196 | psa_algorithm_t alg, |
| 197 | const uint8_t *input, |
| 198 | size_t input_length, |
| 199 | uint8_t *signature, |
| 200 | size_t signature_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 201 | size_t *signature_length) |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 202 | { |
| 203 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 204 | size_t hash_length; |
| 205 | uint8_t hash[PSA_HASH_MAX_SIZE]; |
| 206 | |
| 207 | ++mbedtls_test_driver_signature_sign_hooks.hits; |
| 208 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 209 | if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) { |
| 210 | return mbedtls_test_driver_signature_sign_hooks.forced_status; |
| 211 | } |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 212 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 213 | if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) { |
| 214 | if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) { |
| 215 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 216 | } |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 217 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 218 | memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output, |
| 219 | mbedtls_test_driver_signature_sign_hooks.forced_output_length); |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 220 | *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length; |
| 221 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 222 | return PSA_SUCCESS; |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 225 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 226 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH) |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 227 | status = libtestdriver1_mbedtls_psa_hash_compute( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 228 | PSA_ALG_SIGN_GET_HASH(alg), input, input_length, |
| 229 | hash, sizeof(hash), &hash_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 230 | #elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 231 | status = mbedtls_psa_hash_compute( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 232 | PSA_ALG_SIGN_GET_HASH(alg), input, input_length, |
| 233 | hash, sizeof(hash), &hash_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 234 | #else |
| 235 | (void) input; |
| 236 | (void) input_length; |
| 237 | status = PSA_ERROR_NOT_SUPPORTED; |
| 238 | #endif |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 239 | if (status != PSA_SUCCESS) { |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 240 | return status; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 241 | } |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 242 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 243 | return sign_hash(attributes, key_buffer, key_buffer_size, |
| 244 | alg, hash, hash_length, |
| 245 | signature, signature_size, signature_length); |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | psa_status_t mbedtls_test_opaque_signature_sign_message( |
| 249 | const psa_key_attributes_t *attributes, |
| 250 | const uint8_t *key, |
| 251 | size_t key_length, |
| 252 | psa_algorithm_t alg, |
| 253 | const uint8_t *input, |
| 254 | size_t input_length, |
| 255 | uint8_t *signature, |
| 256 | size_t signature_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 257 | size_t *signature_length) |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 258 | { |
| 259 | (void) attributes; |
| 260 | (void) key; |
| 261 | (void) key_length; |
| 262 | (void) alg; |
| 263 | (void) input; |
| 264 | (void) input_length; |
| 265 | (void) signature; |
| 266 | (void) signature_size; |
| 267 | (void) signature_length; |
| 268 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 269 | return PSA_ERROR_NOT_SUPPORTED; |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | psa_status_t mbedtls_test_transparent_signature_verify_message( |
| 273 | const psa_key_attributes_t *attributes, |
| 274 | const uint8_t *key_buffer, |
| 275 | size_t key_buffer_size, |
| 276 | psa_algorithm_t alg, |
| 277 | const uint8_t *input, |
| 278 | size_t input_length, |
| 279 | const uint8_t *signature, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 280 | size_t signature_length) |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 281 | { |
| 282 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
| 283 | size_t hash_length; |
| 284 | uint8_t hash[PSA_HASH_MAX_SIZE]; |
| 285 | |
| 286 | ++mbedtls_test_driver_signature_verify_hooks.hits; |
| 287 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 288 | if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) { |
| 289 | return mbedtls_test_driver_signature_verify_hooks.forced_status; |
| 290 | } |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 291 | |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 292 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 293 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH) |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 294 | status = libtestdriver1_mbedtls_psa_hash_compute( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 295 | PSA_ALG_SIGN_GET_HASH(alg), input, input_length, |
| 296 | hash, sizeof(hash), &hash_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 297 | #elif defined(MBEDTLS_PSA_BUILTIN_HASH) |
| 298 | status = mbedtls_psa_hash_compute( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 299 | PSA_ALG_SIGN_GET_HASH(alg), input, input_length, |
| 300 | hash, sizeof(hash), &hash_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 301 | #else |
| 302 | (void) input; |
| 303 | (void) input_length; |
| 304 | status = PSA_ERROR_NOT_SUPPORTED; |
| 305 | #endif |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 306 | if (status != PSA_SUCCESS) { |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 307 | return status; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 308 | } |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 309 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 310 | return verify_hash(attributes, key_buffer, key_buffer_size, |
| 311 | alg, hash, hash_length, |
| 312 | signature, signature_length); |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | psa_status_t mbedtls_test_opaque_signature_verify_message( |
| 316 | const psa_key_attributes_t *attributes, |
| 317 | const uint8_t *key, |
| 318 | size_t key_length, |
| 319 | psa_algorithm_t alg, |
| 320 | const uint8_t *input, |
| 321 | size_t input_length, |
| 322 | const uint8_t *signature, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 323 | size_t signature_length) |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 324 | { |
| 325 | (void) attributes; |
| 326 | (void) key; |
| 327 | (void) key_length; |
| 328 | (void) alg; |
| 329 | (void) input; |
| 330 | (void) input_length; |
| 331 | (void) signature; |
| 332 | (void) signature_length; |
| 333 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 334 | return PSA_ERROR_NOT_SUPPORTED; |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | psa_status_t mbedtls_test_transparent_signature_sign_hash( |
| 338 | const psa_key_attributes_t *attributes, |
| 339 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 340 | psa_algorithm_t alg, |
| 341 | const uint8_t *hash, size_t hash_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 342 | uint8_t *signature, size_t signature_size, size_t *signature_length) |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 343 | { |
| 344 | ++mbedtls_test_driver_signature_sign_hooks.hits; |
| 345 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 346 | if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) { |
| 347 | return mbedtls_test_driver_signature_sign_hooks.forced_status; |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 350 | if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) { |
| 351 | if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) { |
| 352 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 353 | } |
| 354 | memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output, |
| 355 | mbedtls_test_driver_signature_sign_hooks.forced_output_length); |
| 356 | *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length; |
| 357 | return PSA_SUCCESS; |
| 358 | } |
| 359 | |
| 360 | return sign_hash(attributes, key_buffer, key_buffer_size, |
| 361 | alg, hash, hash_length, |
| 362 | signature, signature_size, signature_length); |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | psa_status_t mbedtls_test_opaque_signature_sign_hash( |
| 366 | const psa_key_attributes_t *attributes, |
| 367 | const uint8_t *key, size_t key_length, |
| 368 | psa_algorithm_t alg, |
| 369 | const uint8_t *hash, size_t hash_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 370 | uint8_t *signature, size_t signature_size, size_t *signature_length) |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 371 | { |
| 372 | (void) attributes; |
| 373 | (void) key; |
| 374 | (void) key_length; |
| 375 | (void) alg; |
| 376 | (void) hash; |
| 377 | (void) hash_length; |
| 378 | (void) signature; |
| 379 | (void) signature_size; |
| 380 | (void) signature_length; |
| 381 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 382 | return PSA_ERROR_NOT_SUPPORTED; |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | psa_status_t mbedtls_test_transparent_signature_verify_hash( |
| 386 | const psa_key_attributes_t *attributes, |
| 387 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 388 | psa_algorithm_t alg, |
| 389 | const uint8_t *hash, size_t hash_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 390 | const uint8_t *signature, size_t signature_length) |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 391 | { |
| 392 | ++mbedtls_test_driver_signature_verify_hooks.hits; |
| 393 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 394 | if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) { |
| 395 | return mbedtls_test_driver_signature_verify_hooks.forced_status; |
| 396 | } |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 397 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 398 | return verify_hash(attributes, key_buffer, key_buffer_size, |
| 399 | alg, hash, hash_length, |
| 400 | signature, signature_length); |
gabor-mezei-arm | c53f4f6 | 2021-04-22 11:32:19 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 403 | psa_status_t mbedtls_test_opaque_signature_verify_hash( |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 404 | const psa_key_attributes_t *attributes, |
| 405 | const uint8_t *key, size_t key_length, |
| 406 | psa_algorithm_t alg, |
| 407 | const uint8_t *hash, size_t hash_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 408 | const uint8_t *signature, size_t signature_length) |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 409 | { |
| 410 | (void) attributes; |
| 411 | (void) key; |
| 412 | (void) key_length; |
| 413 | (void) alg; |
| 414 | (void) hash; |
| 415 | (void) hash_length; |
| 416 | (void) signature; |
| 417 | (void) signature_length; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame^] | 418 | return PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 55ae217 | 2020-07-17 19:46:15 +0200 | [diff] [blame] | 419 | } |
| 420 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 421 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |