Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * PSA ECP 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 | #ifndef PSA_CRYPTO_ECP_H |
| 22 | #define PSA_CRYPTO_ECP_H |
| 23 | |
| 24 | #include <psa/crypto.h> |
| 25 | #include <mbedtls/ecp.h> |
| 26 | |
| 27 | /** Load the contents of a key buffer into an internal ECP representation |
| 28 | * |
| 29 | * \param[in] type The type of key contained in \p data. |
| 30 | * \param[in] data The buffer from which to load the representation. |
| 31 | * \param[in] data_length The size in bytes of \p data. |
| 32 | * \param[out] p_ecp Returns a pointer to an ECP context on success. |
| 33 | * The caller is responsible for freeing both the |
| 34 | * contents of the context and the context itself |
| 35 | * when done. |
| 36 | */ |
| 37 | psa_status_t mbedtls_psa_ecp_load_representation( psa_key_type_t type, |
Gilles Peskine | 2fa6b5f | 2021-01-27 15:44:45 +0100 | [diff] [blame^] | 38 | size_t curve_bits, |
Ronald Cron | 00b7bfc | 2020-11-25 15:25:26 +0100 | [diff] [blame] | 39 | const uint8_t *data, |
| 40 | size_t data_length, |
| 41 | mbedtls_ecp_keypair **p_ecp ); |
Ronald Cron | e5ca3d8 | 2020-11-26 16:36:16 +0100 | [diff] [blame] | 42 | |
Ronald Cron | d6ec303 | 2020-11-27 18:54:57 +0100 | [diff] [blame] | 43 | /** Import an ECP key in binary format. |
| 44 | * |
| 45 | * \note The signature of this function is that of a PSA driver |
| 46 | * import_key entry point. This function behaves as an import_key |
| 47 | * entry point as defined in the PSA driver interface specification for |
| 48 | * transparent drivers. |
| 49 | * |
| 50 | * \param[in] attributes The attributes for the key to import. |
| 51 | * \param[in] data The buffer containing the key data in import |
| 52 | * format. |
| 53 | * \param[in] data_length Size of the \p data buffer in bytes. |
| 54 | * \param[out] key_buffer The buffer containing the key data in output |
| 55 | * format. |
| 56 | * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes. This |
| 57 | * size is greater or equal to \p data_length. |
| 58 | * \param[out] key_buffer_length The length of the data written in \p |
| 59 | * key_buffer in bytes. |
| 60 | * \param[out] bits The key size in number of bits. |
| 61 | * |
| 62 | * \retval #PSA_SUCCESS The ECP key was imported successfully. |
| 63 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 64 | * The key data is not correctly formatted. |
| 65 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 66 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 67 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 68 | */ |
| 69 | psa_status_t mbedtls_psa_ecp_import_key( |
| 70 | const psa_key_attributes_t *attributes, |
| 71 | const uint8_t *data, size_t data_length, |
| 72 | uint8_t *key_buffer, size_t key_buffer_size, |
| 73 | size_t *key_buffer_length, size_t *bits ); |
| 74 | |
Ronald Cron | e5ca3d8 | 2020-11-26 16:36:16 +0100 | [diff] [blame] | 75 | /** Export an ECP key to export representation |
| 76 | * |
| 77 | * \param[in] type The type of key (public/private) to export |
| 78 | * \param[in] ecp The internal ECP representation from which to export |
| 79 | * \param[out] data The buffer to export to |
| 80 | * \param[in] data_size The length of the buffer to export to |
| 81 | * \param[out] data_length The amount of bytes written to \p data |
| 82 | */ |
| 83 | psa_status_t mbedtls_psa_ecp_export_key( psa_key_type_t type, |
| 84 | mbedtls_ecp_keypair *ecp, |
| 85 | uint8_t *data, |
| 86 | size_t data_size, |
| 87 | size_t *data_length ); |
| 88 | |
| 89 | /** Export an ECP public key or the public part of an ECP key pair in binary |
| 90 | * format. |
| 91 | * |
| 92 | * \note The signature of this function is that of a PSA driver |
| 93 | * export_public_key entry point. This function behaves as an |
| 94 | * export_public_key entry point as defined in the PSA driver interface |
| 95 | * specification. |
| 96 | * |
| 97 | * \param[in] attributes The attributes for the key to export. |
| 98 | * \param[in] key_buffer Material or context of the key to export. |
| 99 | * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes. |
| 100 | * \param[out] data Buffer where the key data is to be written. |
| 101 | * \param[in] data_size Size of the \p data buffer in bytes. |
| 102 | * \param[out] data_length On success, the number of bytes written in |
| 103 | * \p data |
| 104 | * |
| 105 | * \retval #PSA_SUCCESS The ECP public key was exported successfully. |
| 106 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 107 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 108 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 109 | * \retval #PSA_ERROR_CORRUPTION_DETECTED |
| 110 | * \retval #PSA_ERROR_STORAGE_FAILURE |
| 111 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 112 | */ |
| 113 | psa_status_t mbedtls_psa_ecp_export_public_key( |
| 114 | const psa_key_attributes_t *attributes, |
| 115 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 116 | uint8_t *data, size_t data_size, size_t *data_length ); |
| 117 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 118 | /* |
| 119 | * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY. |
| 120 | */ |
| 121 | |
| 122 | #if defined(PSA_CRYPTO_DRIVER_TEST) |
Ronald Cron | 784fb32 | 2020-11-30 13:55:05 +0100 | [diff] [blame] | 123 | psa_status_t mbedtls_transparent_test_driver_ecp_import_key( |
| 124 | const psa_key_attributes_t *attributes, |
| 125 | const uint8_t *data, size_t data_length, |
| 126 | uint8_t *key_buffer, size_t key_buffer_size, |
| 127 | size_t *key_buffer_length, size_t *bits ); |
| 128 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 129 | psa_status_t mbedtls_transparent_test_driver_ecp_export_public_key( |
| 130 | const psa_key_attributes_t *attributes, |
| 131 | const uint8_t *key_buffer, size_t key_buffer_size, |
| 132 | uint8_t *data, size_t data_size, size_t *data_length ); |
Ronald Cron | 784fb32 | 2020-11-30 13:55:05 +0100 | [diff] [blame] | 133 | |
Ronald Cron | f1057d3 | 2020-11-26 19:19:10 +0100 | [diff] [blame] | 134 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 135 | |
Ronald Cron | e5ca3d8 | 2020-11-26 16:36:16 +0100 | [diff] [blame] | 136 | #endif /* PSA_CRYPTO_ECP_H */ |