Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 1 | /* |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 2 | * Test driver for generating and verifying keys. |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 3 | */ |
Steven Cooreman | 2c7b2f8 | 2020-09-02 13:43:46 +0200 | [diff] [blame] | 4 | /* Copyright The Mbed TLS Contributors |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 20 | #ifndef PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H |
| 21 | #define PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 22 | |
| 23 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 24 | #include "mbedtls/config.h" |
| 25 | #else |
| 26 | #include MBEDTLS_CONFIG_FILE |
| 27 | #endif |
| 28 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 29 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 30 | #include <psa/crypto_driver_common.h> |
| 31 | |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 32 | #if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS) |
| 33 | #define PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT 0 |
| 34 | #define PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT 1 |
Steven Cooreman | 437fcfc | 2021-02-22 12:44:15 +0100 | [diff] [blame^] | 35 | |
| 36 | extern const uint8_t test_driver_aes_key[16]; |
| 37 | extern const uint8_t test_driver_ecdsa_key[32]; |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 38 | #endif |
| 39 | |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 40 | typedef struct { |
| 41 | /* If non-null, on success, copy this to the output. */ |
| 42 | void *forced_output; |
| 43 | size_t forced_output_length; |
| 44 | /* If not PSA_SUCCESS, return this error code instead of processing the |
| 45 | * function call. */ |
| 46 | psa_status_t forced_status; |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 47 | /* Count the amount of times one of the key management driver functions |
| 48 | * is called. */ |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 49 | unsigned long hits; |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 50 | } test_driver_key_management_hooks_t; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 51 | |
Ronald Cron | 84a3fa1 | 2020-12-01 09:35:17 +0100 | [diff] [blame] | 52 | #define TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 } |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 53 | static inline test_driver_key_management_hooks_t test_driver_key_management_hooks_init( void ) |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 54 | { |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 55 | const test_driver_key_management_hooks_t v = TEST_DRIVER_KEY_MANAGEMENT_INIT; |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 56 | return( v ); |
| 57 | } |
| 58 | |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 59 | extern test_driver_key_management_hooks_t test_driver_key_management_hooks; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 60 | |
| 61 | psa_status_t test_transparent_generate_key( |
| 62 | const psa_key_attributes_t *attributes, |
| 63 | uint8_t *key, size_t key_size, size_t *key_length ); |
| 64 | |
| 65 | psa_status_t test_opaque_generate_key( |
| 66 | const psa_key_attributes_t *attributes, |
| 67 | uint8_t *key, size_t key_size, size_t *key_length ); |
| 68 | |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 69 | psa_status_t test_opaque_export_key( |
| 70 | const psa_key_attributes_t *attributes, |
| 71 | const uint8_t *key, size_t key_length, |
| 72 | uint8_t *data, size_t data_size, size_t *data_length ); |
| 73 | |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 74 | psa_status_t test_transparent_export_public_key( |
| 75 | const psa_key_attributes_t *attributes, |
| 76 | const uint8_t *key, size_t key_length, |
| 77 | uint8_t *data, size_t data_size, size_t *data_length ); |
| 78 | |
| 79 | psa_status_t test_opaque_export_public_key( |
| 80 | const psa_key_attributes_t *attributes, |
| 81 | const uint8_t *key, size_t key_length, |
| 82 | uint8_t *data, size_t data_size, size_t *data_length ); |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 83 | |
Ronald Cron | 8328287 | 2020-11-22 14:02:39 +0100 | [diff] [blame] | 84 | psa_status_t test_transparent_import_key( |
| 85 | const psa_key_attributes_t *attributes, |
| 86 | const uint8_t *data, |
| 87 | size_t data_length, |
| 88 | uint8_t *key_buffer, |
| 89 | size_t key_buffer_size, |
| 90 | size_t *key_buffer_length, |
| 91 | size_t *bits); |
| 92 | |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 93 | psa_status_t test_opaque_get_builtin_key( |
| 94 | psa_drv_slot_number_t slot_number, |
| 95 | psa_key_attributes_t *attributes, |
| 96 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ); |
| 97 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 98 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 99 | #endif /* PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H */ |