1 /* 2 * Copyright (c) 2017-2021, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __PS_UTILS_H__ 9 #define __PS_UTILS_H__ 10 11 #include <stdint.h> 12 13 #include "psa/error.h" 14 #include "psa/protected_storage.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #define PS_INVALID_FID 0 21 #define PS_DEFAULT_EMPTY_BUFF_VAL 0 22 23 /** 24 * \brief Macro to check, at compilation time, if data fits in data buffer 25 * 26 * \param[in] err_msg Error message which will be displayed in first 27 * instance if the error is triggered 28 * \param[in] data_size Data size to check if it fits 29 * \param[in] data_buf_size Size of the data buffer 30 * 31 * \return Triggers a compilation error if data_size is bigger than 32 * data_buf_size. The compilation error should be 33 * "... error: 'err_msg' declared as an array with a negative size" 34 */ 35 #define PS_UTILS_BOUND_CHECK(err_msg, data_size, data_buf_size) \ 36 typedef char err_msg[(data_size <= data_buf_size)*2 - 1] 37 38 /** 39 * \brief Evaluates to the minimum of the two parameters. 40 */ 41 #define PS_UTILS_MIN(x, y) (((x) < (y)) ? (x) : (y)) 42 43 /** 44 * \brief Checks if a subset region is fully contained within a superset region. 45 * 46 * \param[in] superset_size Size of superset region 47 * \param[in] subset_offset Offset of start of subset region from start of 48 * superset region 49 * \param[in] subset_size Size of subset region 50 * 51 * \return Returns error code as specified in \ref psa_status_t 52 * 53 * \retval PSA_SUCCESS The subset is contained within the 54 * superset 55 * \retval PSA_ERROR_INVALID_ARGUMENT The subset offset is greater than the 56 * size of the superset or when 57 * the subset offset is valid, but the 58 * subset offset + size is greater than the 59 * size of the superset 60 */ 61 psa_status_t ps_utils_check_contained_in(uint32_t superset_size, 62 uint32_t subset_offset, 63 uint32_t subset_size); 64 65 #ifdef __cplusplus 66 } 67 #endif 68 69 #endif /* __PS_UTILS_H__ */ 70