blob: 44d51982a4eaddc9976015a11174329601900e77 [file] [log] [blame]
Gilles Peskine601bd532019-02-24 11:34:28 +01001/** \file psa_crypto_its.h
2 * \brief Interface of trusted storage that crypto is built on.
3 */
Gilles Peskine5f544972019-02-24 11:26:36 +01004/* Copyright (C) 2019, ARM Limited, All Rights Reserved
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
Gilles Peskine5f544972019-02-24 11:26:36 +010019
Gilles Peskine601bd532019-02-24 11:34:28 +010020#ifndef PSA_CRYPTO_ITS_H
21#define PSA_CRYPTO_ITS_H
Gilles Peskine5f544972019-02-24 11:26:36 +010022
23#include <stddef.h>
24#include <stdint.h>
25
Gilles Peskine601bd532019-02-24 11:34:28 +010026#include <psa/crypto_types.h>
27#include <psa/crypto_values.h>
Gilles Peskine5f544972019-02-24 11:26:36 +010028
29#ifdef __cplusplus
30extern "C" {
31#endif
Gilles Peskine601bd532019-02-24 11:34:28 +010032
33/** \brief Flags used when creating a data entry
34 */
35typedef uint32_t psa_storage_create_flags_t;
36
37/** \brief A type for UIDs used for identifying data
38 */
39typedef uint64_t psa_storage_uid_t;
40
41#define PSA_STORAGE_FLAG_NONE 0 /**< No flags to pass */
42#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`*/
43
44/**
45 * \brief A container for metadata associated with a specific uid
46 */
47struct psa_storage_info_t
48{
49 uint32_t size; /**< The size of the data associated with a uid **/
50 psa_storage_create_flags_t flags; /**< The flags set when the uid was created **/
51};
52
53/** Flag indicating that \ref psa_storage_create and \ref psa_storage_set_extended are supported */
54#define PSA_STORAGE_SUPPORT_SET_EXTENDED (1 << 0)
55
56/** \brief PSA storage specific error codes
57 */
58#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
59#define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152)
60
Gilles Peskine5f544972019-02-24 11:26:36 +010061#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 */
62#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 */
63
64/**
65 * \brief create a new or modify an existing uid/value pair
66 *
67 * \param[in] uid the identifier for the data
68 * \param[in] data_length The size in bytes of the data in `p_data`
69 * \param[in] p_data A buffer containing the data
70 * \param[in] create_flags The flags that the data will be stored with
Gilles Peskine601bd532019-02-24 11:34:28 +010071 *
Gilles Peskine5f544972019-02-24 11:26:36 +010072 * \return A status indicating the success/failure of the operation
Gilles Peskine601bd532019-02-24 11:34:28 +010073 *
Gilles Peskine5f544972019-02-24 11:26:36 +010074 * \retval PSA_SUCCESS The operation completed successfully
75 * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided `uid` value was already created with PSA_STORAGE_WRITE_ONCE_FLAG
76 * \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
77 * \retval PSA_ERROR_INSUFFICIENT_STORAGE The operation failed because there was insufficient space on the storage medium
78 * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
79 * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`)
80 * is invalid, for example is `NULL` or references memory the caller cannot access
81 */
82psa_status_t psa_its_set(psa_storage_uid_t uid,
83 uint32_t data_length,
84 const void *p_data,
85 psa_storage_create_flags_t create_flags);
86
87/**
88 * \brief Retrieve the value associated with a provided uid
89 *
90 * \param[in] uid The uid value
91 * \param[in] data_offset The starting offset of the data requested
92 * \param[in] data_length the amount of data requested (and the minimum allocated size of the `p_data` buffer)
93 * \param[out] p_data The buffer where the data will be placed upon successful completion
Gilles Peskine601bd532019-02-24 11:34:28 +010094 *
95 *
Gilles Peskine5f544972019-02-24 11:26:36 +010096 * \return A status indicating the success/failure of the operation
97 *
98 * \retval PSA_SUCCESS The operation completed successfully
99 * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided `uid` value was not found in the storage
100 * \retval PSA_ERROR_INVALID_SIZE The operation failed because the data associated with provided uid is larger than `data_size`
101 * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
102 * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`, `p_data_length`)
103 * is invalid. For example is `NULL` or references memory the caller cannot access.
104 * In addition, this can also happen if an invalid offset was provided.
105 */
106psa_status_t psa_its_get(psa_storage_uid_t uid,
107 uint32_t data_offset,
108 uint32_t data_length,
109 void *p_data);
110
111/**
112 * \brief Retrieve the metadata about the provided uid
Gilles Peskine601bd532019-02-24 11:34:28 +0100113 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100114 * \param[in] uid The uid value
115 * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata
Gilles Peskine601bd532019-02-24 11:34:28 +0100116 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100117 * \return A status indicating the success/failure of the operation
Gilles Peskine601bd532019-02-24 11:34:28 +0100118 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100119 * \retval PSA_SUCCESS The operation completed successfully
120 * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage
121 * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
122 * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_info`)
123 * is invalid, for example is `NULL` or references memory the caller cannot access
124 */
125psa_status_t psa_its_get_info(psa_storage_uid_t uid,
126 struct psa_storage_info_t *p_info);
127
128/**
129 * \brief Remove the provided key and its associated data from the storage
Gilles Peskine601bd532019-02-24 11:34:28 +0100130 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100131 * \param[in] uid The uid value
Gilles Peskine601bd532019-02-24 11:34:28 +0100132 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100133 * \return A status indicating the success/failure of the operation
Gilles Peskine601bd532019-02-24 11:34:28 +0100134 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100135 * \retval PSA_SUCCESS The operation completed successfully
136 * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided key value was not found in the storage
137 * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided key value was created with PSA_STORAGE_WRITE_ONCE_FLAG
138 * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
139 */
140psa_status_t psa_its_remove(psa_storage_uid_t uid);
141
Gilles Peskine601bd532019-02-24 11:34:28 +0100142#endif /* PSA_CRYPTO_ITS_H */