Fix up ITS header files for internal use in crypto

Merge storage_common.h and internal_trusted_storage.h into a single
file for convenience.

Remove #include of <psa/error.h> which crypto doesn't have yet and
include <psa/crypto_types.h> and <psa/crypto_values.h> instead.

Drop __cplusplus support which we don't need.

Tweak style (whitespace, line breaks, comment formatting) to satisfy
check-names.sh and check-files.sh.
This commit is contained in:
Gilles Peskine 2019-02-24 11:34:28 +01:00
parent 5f54497cf3
commit 601bd53b80
3 changed files with 48 additions and 80 deletions

View file

@ -1,3 +1,6 @@
/** \file psa_crypto_its.h
* \brief Interface of trusted storage that crypto is built on.
*/
/* Copyright (C) 2019, ARM Limited, All Rights Reserved /* Copyright (C) 2019, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
* *
@ -13,22 +16,48 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/** @file
@brief This file describes the PSA Internal Trusted Storage API
*/
#ifndef __PSA_INTERNAL_TRUSTED_STORAGE_H__ #ifndef PSA_CRYPTO_ITS_H
#define __PSA_INTERNAL_TRUSTED_STORAGE_H__ #define PSA_CRYPTO_ITS_H
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "psa/error.h" #include <psa/crypto_types.h>
#include "psa/storage_common.h" #include <psa/crypto_values.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** \brief Flags used when creating a data entry
*/
typedef uint32_t psa_storage_create_flags_t;
/** \brief A type for UIDs used for identifying data
*/
typedef uint64_t psa_storage_uid_t;
#define PSA_STORAGE_FLAG_NONE 0 /**< No flags to pass */
#define PSA_STORAGE_FLAG_WRITE_ONCE (1 << 0) /**< The data associated with the uid will not be able to be modified or deleted. Intended to be used to set bits in `psa_storage_create_flags_t`*/
/**
* \brief A container for metadata associated with a specific uid
*/
struct psa_storage_info_t
{
uint32_t size; /**< The size of the data associated with a uid **/
psa_storage_create_flags_t flags; /**< The flags set when the uid was created **/
};
/** Flag indicating that \ref psa_storage_create and \ref psa_storage_set_extended are supported */
#define PSA_STORAGE_SUPPORT_SET_EXTENDED (1 << 0)
/** \brief PSA storage specific error codes
*/
#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
#define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152)
#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 */ #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 */
#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 */ #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 */
@ -39,9 +68,9 @@ extern "C" {
* \param[in] data_length The size in bytes of the data in `p_data` * \param[in] data_length The size in bytes of the data in `p_data`
* \param[in] p_data A buffer containing the data * \param[in] p_data A buffer containing the data
* \param[in] create_flags The flags that the data will be stored with * \param[in] create_flags The flags that the data will be stored with
* *
* \return A status indicating the success/failure of the operation * \return A status indicating the success/failure of the operation
*
* \retval PSA_SUCCESS The operation completed successfully * \retval PSA_SUCCESS The operation completed successfully
* \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided `uid` value was already created with PSA_STORAGE_WRITE_ONCE_FLAG * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided `uid` value was already created with PSA_STORAGE_WRITE_ONCE_FLAG
* \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 * \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
@ -62,8 +91,8 @@ psa_status_t psa_its_set(psa_storage_uid_t uid,
* \param[in] data_offset The starting offset of the data requested * \param[in] data_offset The starting offset of the data requested
* \param[in] data_length the amount of data requested (and the minimum allocated size of the `p_data` buffer) * \param[in] data_length the amount of data requested (and the minimum allocated size of the `p_data` buffer)
* \param[out] p_data The buffer where the data will be placed upon successful completion * \param[out] p_data The buffer where the data will be placed upon successful completion
*
* *
* \return A status indicating the success/failure of the operation * \return A status indicating the success/failure of the operation
* *
* \retval PSA_SUCCESS The operation completed successfully * \retval PSA_SUCCESS The operation completed successfully
@ -81,12 +110,12 @@ psa_status_t psa_its_get(psa_storage_uid_t uid,
/** /**
* \brief Retrieve the metadata about the provided uid * \brief Retrieve the metadata about the provided uid
* *
* \param[in] uid The uid value * \param[in] uid The uid value
* \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata
* *
* \return A status indicating the success/failure of the operation * \return A status indicating the success/failure of the operation
* *
* \retval PSA_SUCCESS The operation completed successfully * \retval PSA_SUCCESS The operation completed successfully
* \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage
* \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
@ -98,11 +127,11 @@ psa_status_t psa_its_get_info(psa_storage_uid_t uid,
/** /**
* \brief Remove the provided key and its associated data from the storage * \brief Remove the provided key and its associated data from the storage
* *
* \param[in] uid The uid value * \param[in] uid The uid value
* *
* \return A status indicating the success/failure of the operation * \return A status indicating the success/failure of the operation
* *
* \retval PSA_SUCCESS The operation completed successfully * \retval PSA_SUCCESS The operation completed successfully
* \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided key value was not found in the storage * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided key value was not found in the storage
* \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided key value was created with PSA_STORAGE_WRITE_ONCE_FLAG * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided key value was created with PSA_STORAGE_WRITE_ONCE_FLAG
@ -110,8 +139,4 @@ psa_status_t psa_its_get_info(psa_storage_uid_t uid,
*/ */
psa_status_t psa_its_remove(psa_storage_uid_t uid); psa_status_t psa_its_remove(psa_storage_uid_t uid);
#ifdef __cplusplus #endif /* PSA_CRYPTO_ITS_H */
}
#endif
#endif // __PSA_INTERNAL_TRUSTED_STORAGE_H__

View file

@ -1,58 +0,0 @@
/* Copyright (C) 2019, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @file
@brief This file includes common definitions for PSA storage
*/
#ifndef __PSA_STORAGE_COMMON_H__
#define __PSA_STORAGE_COMMON_H__
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \brief Flags used when creating a data entry
*/
typedef uint32_t psa_storage_create_flags_t;
/** \brief A type for UIDs used for identifying data
*/
typedef uint64_t psa_storage_uid_t;
#define PSA_STORAGE_FLAG_NONE 0 /**< No flags to pass */
#define PSA_STORAGE_FLAG_WRITE_ONCE (1 << 0) /**< The data associated with the uid will not be able to be modified or deleted. Intended to be used to set bits in `psa_storage_create_flags_t`*/
/**
* \brief A container for metadata associated with a specific uid
*/
struct psa_storage_info_t {
uint32_t size; /**< The size of the data associated with a uid **/
psa_storage_create_flags_t flags; /**< The flags set when the uid was created **/
};
/** Flag indicating that \ref psa_storage_create and \ref psa_storage_set_extended are supported */
#define PSA_STORAGE_SUPPORT_SET_EXTENDED (1 << 0)
/** \brief PSA storage specific error codes
*/
#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
#define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152)
#endif // __PSA_STORAGE_COMMON_H__

View file

@ -238,6 +238,7 @@
<ClInclude Include="..\..\include\psa\crypto_values.h" /> <ClInclude Include="..\..\include\psa\crypto_values.h" />
<ClInclude Include="..\..\library/psa_crypto_core.h" /> <ClInclude Include="..\..\library/psa_crypto_core.h" />
<ClInclude Include="..\..\library/psa_crypto_invasive.h" /> <ClInclude Include="..\..\library/psa_crypto_invasive.h" />
<ClInclude Include="..\..\library/psa_crypto_its.h" />
<ClInclude Include="..\..\library/psa_crypto_service_integration.h" /> <ClInclude Include="..\..\library/psa_crypto_service_integration.h" />
<ClInclude Include="..\..\library/psa_crypto_slot_management.h" /> <ClInclude Include="..\..\library/psa_crypto_slot_management.h" />
<ClInclude Include="..\..\library/psa_crypto_storage.h" /> <ClInclude Include="..\..\library/psa_crypto_storage.h" />