Gilles Peskine | 5f54497 | 2019-02-24 11:26:36 +0100 | [diff] [blame^] | 1 | /* Copyright (C) 2019, ARM Limited, All Rights Reserved |
| 2 | * SPDX-License-Identifier: Apache-2.0 |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | * not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | /** @file |
| 17 | @brief This file describes the PSA Internal Trusted Storage API |
| 18 | */ |
| 19 | |
| 20 | #ifndef __PSA_INTERNAL_TRUSTED_STORAGE_H__ |
| 21 | #define __PSA_INTERNAL_TRUSTED_STORAGE_H__ |
| 22 | |
| 23 | #include <stddef.h> |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | #include "psa/error.h" |
| 27 | #include "psa/storage_common.h" |
| 28 | |
| 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
| 31 | #endif |
| 32 | #define PSA_ITS_API_VERSION_MAJOR 1 /**< The major version number of the PSA ITS API. It will be incremented on significant updates that may include breaking changes */ |
| 33 | #define PSA_ITS_API_VERSION_MINOR 1 /**< The minor version number of the PSA ITS API. It will be incremented in small updates that are unlikely to include breaking changes */ |
| 34 | |
| 35 | /** |
| 36 | * \brief create a new or modify an existing uid/value pair |
| 37 | * |
| 38 | * \param[in] uid the identifier for the data |
| 39 | * \param[in] data_length The size in bytes of the data in `p_data` |
| 40 | * \param[in] p_data A buffer containing the data |
| 41 | * \param[in] create_flags The flags that the data will be stored with |
| 42 | * |
| 43 | * \return A status indicating the success/failure of the operation |
| 44 | |
| 45 | * \retval PSA_SUCCESS The operation completed successfully |
| 46 | * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided `uid` value was already created with PSA_STORAGE_WRITE_ONCE_FLAG |
| 47 | * \retval PSA_ERROR_NOT_SUPPORTED The operation failed because one or more of the flags provided in `create_flags` is not supported or is not valid |
| 48 | * \retval PSA_ERROR_INSUFFICIENT_STORAGE The operation failed because there was insufficient space on the storage medium |
| 49 | * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) |
| 50 | * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`) |
| 51 | * is invalid, for example is `NULL` or references memory the caller cannot access |
| 52 | */ |
| 53 | psa_status_t psa_its_set(psa_storage_uid_t uid, |
| 54 | uint32_t data_length, |
| 55 | const void *p_data, |
| 56 | psa_storage_create_flags_t create_flags); |
| 57 | |
| 58 | /** |
| 59 | * \brief Retrieve the value associated with a provided uid |
| 60 | * |
| 61 | * \param[in] uid The uid value |
| 62 | * \param[in] data_offset The starting offset of the data requested |
| 63 | * \param[in] data_length the amount of data requested (and the minimum allocated size of the `p_data` buffer) |
| 64 | * \param[out] p_data The buffer where the data will be placed upon successful completion |
| 65 | |
| 66 | * |
| 67 | * \return A status indicating the success/failure of the operation |
| 68 | * |
| 69 | * \retval PSA_SUCCESS The operation completed successfully |
| 70 | * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided `uid` value was not found in the storage |
| 71 | * \retval PSA_ERROR_INVALID_SIZE The operation failed because the data associated with provided uid is larger than `data_size` |
| 72 | * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) |
| 73 | * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`, `p_data_length`) |
| 74 | * is invalid. For example is `NULL` or references memory the caller cannot access. |
| 75 | * In addition, this can also happen if an invalid offset was provided. |
| 76 | */ |
| 77 | psa_status_t psa_its_get(psa_storage_uid_t uid, |
| 78 | uint32_t data_offset, |
| 79 | uint32_t data_length, |
| 80 | void *p_data); |
| 81 | |
| 82 | /** |
| 83 | * \brief Retrieve the metadata about the provided uid |
| 84 | * |
| 85 | * \param[in] uid The uid value |
| 86 | * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata |
| 87 | * |
| 88 | * \return A status indicating the success/failure of the operation |
| 89 | * |
| 90 | * \retval PSA_SUCCESS The operation completed successfully |
| 91 | * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage |
| 92 | * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) |
| 93 | * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_info`) |
| 94 | * is invalid, for example is `NULL` or references memory the caller cannot access |
| 95 | */ |
| 96 | psa_status_t psa_its_get_info(psa_storage_uid_t uid, |
| 97 | struct psa_storage_info_t *p_info); |
| 98 | |
| 99 | /** |
| 100 | * \brief Remove the provided key and its associated data from the storage |
| 101 | * |
| 102 | * \param[in] uid The uid value |
| 103 | * |
| 104 | * \return A status indicating the success/failure of the operation |
| 105 | * |
| 106 | * \retval PSA_SUCCESS The operation completed successfully |
| 107 | * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided key value was not found in the storage |
| 108 | * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided key value was created with PSA_STORAGE_WRITE_ONCE_FLAG |
| 109 | * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) |
| 110 | */ |
| 111 | psa_status_t psa_its_remove(psa_storage_uid_t uid); |
| 112 | |
| 113 | #ifdef __cplusplus |
| 114 | } |
| 115 | #endif |
| 116 | |
| 117 | #endif // __PSA_INTERNAL_TRUSTED_STORAGE_H__ |