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 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 23 | #include "mbedtls/build_info.h" |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 24 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 25 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 26 | #include <psa/crypto_driver_common.h> |
| 27 | |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 28 | #define PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT 0 |
| 29 | #define PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT 1 |
Steven Cooreman | 437fcfc | 2021-02-22 12:44:15 +0100 | [diff] [blame] | 30 | |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 31 | typedef struct { |
| 32 | /* If non-null, on success, copy this to the output. */ |
| 33 | void *forced_output; |
| 34 | size_t forced_output_length; |
| 35 | /* If not PSA_SUCCESS, return this error code instead of processing the |
| 36 | * function call. */ |
| 37 | psa_status_t forced_status; |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 38 | /* Count the amount of times one of the key management driver functions |
| 39 | * is called. */ |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 40 | unsigned long hits; |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 41 | } mbedtls_test_driver_key_management_hooks_t; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 42 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 43 | #define MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_SUCCESS, 0 } |
| 44 | static inline mbedtls_test_driver_key_management_hooks_t |
| 45 | mbedtls_test_driver_key_management_hooks_init( void ) |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 46 | { |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 47 | const mbedtls_test_driver_key_management_hooks_t |
| 48 | v = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT; |
Steven Cooreman | 831c695 | 2020-09-07 12:58:16 +0200 | [diff] [blame] | 49 | return( v ); |
| 50 | } |
| 51 | |
Archana | 4d7ae1d | 2021-07-07 02:50:22 +0530 | [diff] [blame] | 52 | /* |
| 53 | * In order to convert the plain text keys to Opaque, the size of the key is |
Archana | 449608b | 2021-09-08 15:36:05 +0530 | [diff] [blame^] | 54 | * padded up by PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE in addition to |
| 55 | * xor mangling the key. The pad prefix needs to be accounted for while |
| 56 | * sizing for the key. |
Archana | 4d7ae1d | 2021-07-07 02:50:22 +0530 | [diff] [blame] | 57 | */ |
| 58 | #define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX 0xBEEFED00U |
Archana | 449608b | 2021-09-08 15:36:05 +0530 | [diff] [blame^] | 59 | #define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE sizeof( \ |
| 60 | PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX ) |
Archana | 4d7ae1d | 2021-07-07 02:50:22 +0530 | [diff] [blame] | 61 | |
| 62 | size_t mbedtls_test_opaque_size_function( |
| 63 | const psa_key_type_t key_type, |
| 64 | const size_t key_bits ); |
| 65 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 66 | extern mbedtls_test_driver_key_management_hooks_t |
| 67 | mbedtls_test_driver_key_management_hooks; |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 68 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 69 | psa_status_t mbedtls_test_transparent_generate_key( |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 70 | const psa_key_attributes_t *attributes, |
| 71 | uint8_t *key, size_t key_size, size_t *key_length ); |
| 72 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 73 | psa_status_t mbedtls_test_opaque_generate_key( |
Steven Cooreman | 2a1664c | 2020-07-20 15:33:08 +0200 | [diff] [blame] | 74 | const psa_key_attributes_t *attributes, |
| 75 | uint8_t *key, size_t key_size, size_t *key_length ); |
| 76 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 77 | psa_status_t mbedtls_test_opaque_export_key( |
Ronald Cron | 6722798 | 2020-11-26 15:16:05 +0100 | [diff] [blame] | 78 | const psa_key_attributes_t *attributes, |
| 79 | const uint8_t *key, size_t key_length, |
| 80 | uint8_t *data, size_t data_size, size_t *data_length ); |
| 81 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 82 | psa_status_t mbedtls_test_transparent_export_public_key( |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 83 | const psa_key_attributes_t *attributes, |
| 84 | const uint8_t *key, size_t key_length, |
| 85 | uint8_t *data, size_t data_size, size_t *data_length ); |
| 86 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 87 | psa_status_t mbedtls_test_opaque_export_public_key( |
Steven Cooreman | b9b8442 | 2020-10-14 14:39:20 +0200 | [diff] [blame] | 88 | const psa_key_attributes_t *attributes, |
| 89 | const uint8_t *key, size_t key_length, |
| 90 | uint8_t *data, size_t data_size, size_t *data_length ); |
Steven Cooreman | 0452476 | 2020-10-13 17:43:44 +0200 | [diff] [blame] | 91 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 92 | psa_status_t mbedtls_test_transparent_import_key( |
Ronald Cron | 8328287 | 2020-11-22 14:02:39 +0100 | [diff] [blame] | 93 | const psa_key_attributes_t *attributes, |
| 94 | const uint8_t *data, |
| 95 | size_t data_length, |
| 96 | uint8_t *key_buffer, |
| 97 | size_t key_buffer_size, |
| 98 | size_t *key_buffer_length, |
| 99 | size_t *bits); |
| 100 | |
Archana | 4d7ae1d | 2021-07-07 02:50:22 +0530 | [diff] [blame] | 101 | psa_status_t mbedtls_test_opaque_import_key( |
| 102 | const psa_key_attributes_t *attributes, |
| 103 | const uint8_t *data, |
| 104 | size_t data_length, |
| 105 | uint8_t *key_buffer, |
| 106 | size_t key_buffer_size, |
| 107 | size_t *key_buffer_length, |
| 108 | size_t *bits); |
| 109 | |
Ronald Cron | 7f13fa2 | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 110 | psa_status_t mbedtls_test_opaque_get_builtin_key( |
Steven Cooreman | f9a55ff | 2021-02-19 18:04:59 +0100 | [diff] [blame] | 111 | psa_drv_slot_number_t slot_number, |
| 112 | psa_key_attributes_t *attributes, |
| 113 | uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length ); |
| 114 | |
Archana | 8a18036 | 2021-07-05 02:18:48 +0530 | [diff] [blame] | 115 | psa_status_t mbedtls_test_opaque_copy_key( |
| 116 | psa_key_attributes_t *attributes, |
| 117 | const uint8_t *source_key, |
| 118 | size_t source_key_size, |
| 119 | uint8_t *target_key_buffer, |
Archana | 449608b | 2021-09-08 15:36:05 +0530 | [diff] [blame^] | 120 | size_t target_key_buffer_size, |
| 121 | size_t *target_key_buffer_length); |
Archana | 8a18036 | 2021-07-05 02:18:48 +0530 | [diff] [blame] | 122 | |
| 123 | |
Steven Cooreman | f1720ea | 2020-07-24 18:41:58 +0200 | [diff] [blame] | 124 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
Steven Cooreman | c4813a6 | 2020-10-23 11:45:43 +0200 | [diff] [blame] | 125 | #endif /* PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H */ |