|
| 1 | +/** |
| 2 | + * \file psa/crypto_accel_driver.h |
| 3 | + * \brief PSA cryptography accelerator driver module |
| 4 | + * |
| 5 | + * This header declares types and function signatures for cryptography |
| 6 | + * drivers that access key material directly. This is meant for |
| 7 | + * on-chip cryptography accelerators. |
| 8 | + * |
| 9 | + * This file is part of the PSA Crypto Driver Model, containing functions for |
| 10 | + * driver developers to implement to enable hardware to be called in a |
| 11 | + * standardized way by a PSA Cryptographic API implementation. The functions |
| 12 | + * comprising the driver model, which driver authors implement, are not |
| 13 | + * intended to be called by application developers. |
| 14 | + */ |
| 15 | + |
| 16 | +/* |
| 17 | + * Copyright The Mbed TLS Contributors |
| 18 | + * SPDX-License-Identifier: Apache-2.0 |
| 19 | + * |
| 20 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | + * not use this file except in compliance with the License. |
| 22 | + * You may obtain a copy of the License at |
| 23 | + * |
| 24 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | + * |
| 26 | + * Unless required by applicable law or agreed to in writing, software |
| 27 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | + * See the License for the specific language governing permissions and |
| 30 | + * limitations under the License. |
| 31 | + */ |
| 32 | +#ifndef PSA_CRYPTO_ACCEL_DRIVER_H |
| 33 | + #define PSA_CRYPTO_ACCEL_DRIVER_H |
| 34 | + |
| 35 | + #include "crypto_driver_common.h" |
| 36 | + #include <stdbool.h> |
| 37 | + |
| 38 | + #ifdef __cplusplus |
| 39 | +extern "C" { |
| 40 | + #endif |
| 41 | + |
| 42 | +/** Import vendor defined key data into a slot. |
| 43 | + * |
| 44 | + * `slot->type` must have been set previously. |
| 45 | + * This function assumes that the slot does not contain any key material yet. |
| 46 | + * On failure, the slot content is unchanged. |
| 47 | + * |
| 48 | + * Persistent storage is not affected. |
| 49 | + * |
| 50 | + * \param[in,out] slot The key slot to import data into. |
| 51 | + * Its `type` field must have previously been set to |
| 52 | + * the desired key type. |
| 53 | + * It must not contain any key material yet. |
| 54 | + * \param[in] data Buffer containing the key material to parse and import. |
| 55 | + * \param data_length Size of \p data in bytes. |
| 56 | + * \param write_to_persistent_memory Specify if the imported key needs to be written to persistent memory. |
| 57 | + * |
| 58 | + * \retval PSA_SUCCESS |
| 59 | + * \retval PSA_ERROR_INVALID_ARGUMENT |
| 60 | + * \retval PSA_ERROR_NOT_SUPPORTED |
| 61 | + * \retval PSA_ERROR_INSUFFICIENT_MEMORY |
| 62 | + * \retval Implementation dependent |
| 63 | + */ |
| 64 | +psa_status_t psa_import_key_into_slot_vendor(const psa_key_attributes_t * attributes, |
| 65 | + psa_key_slot_t * slot, |
| 66 | + const uint8_t * data, |
| 67 | + size_t data_length, |
| 68 | + mbedtls_svc_key_id_t * key, |
| 69 | + bool write_to_persistent_memory); |
| 70 | + |
| 71 | +/** |
| 72 | + * \brief Generate a vendor defined key or key pair. |
| 73 | + * |
| 74 | + * \note This function has to be defined by the vendor if MBEDTLS_PSA_CRYPTO_ACCEL_DRV_C |
| 75 | + * is defined. Do not use this function directly; |
| 76 | + * to generate a key, use psa_generate_key() instead. |
| 77 | + * |
| 78 | + * \param[in] slot |
| 79 | + * \param[in] bits |
| 80 | + * \param[in] params |
| 81 | + * \param[in] params_data_length |
| 82 | + * |
| 83 | + * |
| 84 | + * \retval #PSA_SUCCESS |
| 85 | + * Success. |
| 86 | + * If the key is persistent, the key material and the key's metadata |
| 87 | + * have been saved to persistent storage. |
| 88 | + * |
| 89 | + * \retval #PSA_ERROR_NOT_SUPPORTED |
| 90 | + * \retval Implementation dependent. |
| 91 | + */ |
| 92 | +psa_status_t psa_generate_key_vendor (psa_key_slot_t * slot, |
| 93 | + size_t bits, |
| 94 | + const psa_key_production_parameters_t *params, |
| 95 | + size_t params_data_length); |
| 96 | + |
| 97 | +/** |
| 98 | + * \brief Generate symmetric key of vendor defined format. |
| 99 | + * |
| 100 | + * \warning This function **can** fail! Callers MUST check the return status |
| 101 | + * and MUST NOT use the content of the output buffer if the return |
| 102 | + * status is not #PSA_SUCCESS. |
| 103 | + * |
| 104 | + * \note This function has to be defined by the vendor if MBEDTLS_PSA_CRYPTO_ACCEL_DRV_C |
| 105 | + * is defined. |
| 106 | + * A weakly linked version is provided by default and returns |
| 107 | + * PSA_ERROR_NOT_SUPPORTED. Do not use this function directly; |
| 108 | + * to generate a key, use psa_generate_key() instead. |
| 109 | + * |
| 110 | + * \param[in] type Type of symmetric key to be generated. |
| 111 | + * \param[out] output Output buffer for the generated data. |
| 112 | + * \param[out] output_size Number of bytes to generate and output. |
| 113 | + * |
| 114 | + * \retval #PSA_SUCCESS |
| 115 | + * \retval #PSA_ERROR_NOT_SUPPORTED |
| 116 | + * \retval Implementation dependent |
| 117 | + */ |
| 118 | +psa_status_t psa_generate_symmetric_vendor(psa_key_type_t type, size_t bits, uint8_t * output, size_t output_size); |
| 119 | + |
| 120 | +/** Finalize the creation of a vendor defined key once its key material has been set. |
| 121 | + * |
| 122 | + * This entails writing the key to persistent storage. |
| 123 | + * |
| 124 | + * This function is to be called only by psa_finish_key_creation(). |
| 125 | + * |
| 126 | + * \param[in,out] slot Pointer to the slot with key material. |
| 127 | + * |
| 128 | + * \retval #PSA_SUCCESS |
| 129 | + * The key was successfully created. The handle is now valid. |
| 130 | + * \return If this function fails, the key slot is an invalid state. |
| 131 | + */ |
| 132 | +psa_status_t psa_finish_key_creation_vendor(psa_key_slot_t * slot); |
| 133 | + |
| 134 | +/**@}*/ |
| 135 | + |
| 136 | + #ifdef __cplusplus |
| 137 | +} |
| 138 | + #endif |
| 139 | + |
| 140 | +#endif /* PSA_CRYPTO_ACCEL_DRIVER_H */ |
0 commit comments