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 | #define PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT 0 |
| 33 | #define PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT 1 |
Steven Cooreman | 437fcfc | 2021-02-22 12:44:15 +0100 | [diff] [blame] | 34 | |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 35 | typedef struct { |
| 36 | /* If non-null, on success, copy this to the output. */ |
| 37 | void *forced_output; |
| 38 | size_t forced_output_length; |
| 39 | /* If not PSA_SUCCESS, return this error code instead of processing the |
| 40 | * function call. */ |
| 41 | psa_status_t forced_status; |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 42 | /* Count the amount of times one of the key management driver functions |
| 43 | * is called. */ |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 44 | unsigned long hits; |
Andrzej Kurek | 28a7c06 | 2022-02-04 09:04:20 -0500 | [diff] [blame] | 45 | /* Location of the last key management driver called to import a key. */ |
| 46 | psa_key_location_t location; |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 47 | } mbedtls_test_driver_key_management_hooks_t; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 48 | |
Andrzej Kurek | 981a0ce | 2022-02-03 09:42:47 -0500 | [diff] [blame] | 49 | /* The location is initialized to the invalid value 0x800000. Invalid in the |
| 50 | * sense that no PSA specification will assign a meaning to this location |
| 51 | * (stated first in version 1.0.1 of the specification) and that it is not |
| 52 | * used as a location of an opaque test drivers. */ |
Andrzej Kurek | 96c8f9e | 2022-02-04 07:12:30 -0500 | [diff] [blame] | 53 | #define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0, 0x800000 } |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 54 | static inline mbedtls_test_driver_key_management_hooks_t |
| 55 | mbedtls_test_driver_key_management_hooks_init( void ) |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 56 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 57 | const mbedtls_test_driver_key_management_hooks_t |
| 58 | v = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT; |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 59 | return( v ); |
| 60 | } |
| 61 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 62 | extern mbedtls_test_driver_key_management_hooks_t |
| 63 | mbedtls_test_driver_key_management_hooks; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 64 | |
Ronald Cron | 088d5d0 | 2021-04-10 16:57:30 +0200 | [diff] [blame] | 65 | psa_status_t mbedtls_test_transparent_init( void ); |
| 66 | void mbedtls_test_transparent_free( void ); |
| 67 | psa_status_t mbedtls_test_opaque_init( void ); |
| 68 | void mbedtls_test_opaque_free( void ); |
| 69 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 70 | psa_status_t mbedtls_test_transparent_generate_key( |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 71 | const psa_key_attributes_t *attributes, |
| 72 | uint8_t *key, size_t key_size, size_t *key_length ); |
| 73 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 74 | psa_status_t mbedtls_test_opaque_generate_key( |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 75 | const psa_key_attributes_t *attributes, |
| 76 | uint8_t *key, size_t key_size, size_t *key_length ); |
| 77 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 78 | psa_status_t mbedtls_test_opaque_export_key( |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 79 | const psa_key_attributes_t *attributes, |
| 80 | const uint8_t *key, size_t key_length, |
| 81 | uint8_t *data, size_t data_size, size_t *data_length ); |
| 82 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 83 | psa_status_t mbedtls_test_transparent_export_public_key( |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 84 | const psa_key_attributes_t *attributes, |
| 85 | const uint8_t *key, size_t key_length, |
| 86 | uint8_t *data, size_t data_size, size_t *data_length ); |
| 87 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 88 | psa_status_t mbedtls_test_opaque_export_public_key( |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 89 | const psa_key_attributes_t *attributes, |
| 90 | const uint8_t *key, size_t key_length, |
| 91 | uint8_t *data, size_t data_size, size_t *data_length ); |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 92 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 93 | psa_status_t mbedtls_test_transparent_import_key( |
Ronald Cron | 8328287 | 2020-11-22 14:02:39 +0100 | [diff] [blame] | 94 | const psa_key_attributes_t *attributes, |
| 95 | const uint8_t *data, |
| 96 | size_t data_length, |
| 97 | uint8_t *key_buffer, |
| 98 | size_t key_buffer_size, |
| 99 | size_t *key_buffer_length, |
| 100 | size_t *bits); |
| 101 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 102 | psa_status_t mbedtls_test_opaque_get_builtin_key( |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 103 | psa_drv_slot_number_t slot_number, |
| 104 | psa_key_attributes_t *attributes, |
| 105 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ); |
| 106 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 107 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 108 | #endif /* PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H */ |