23 #if defined(MBEDTLS_PSA_ITS_FILE_C)
38 #if !defined(PSA_ITS_STORAGE_PREFIX)
39 #define PSA_ITS_STORAGE_PREFIX ""
42 #define PSA_ITS_STORAGE_FILENAME_PATTERN "%08x%08x"
43 #define PSA_ITS_STORAGE_SUFFIX ".psa_its"
44 #define PSA_ITS_STORAGE_FILENAME_LENGTH \
45 (sizeof(PSA_ITS_STORAGE_PREFIX) - 1 + \
47 sizeof(PSA_ITS_STORAGE_SUFFIX) - 1 + \
49 #define PSA_ITS_STORAGE_TEMP \
50 PSA_ITS_STORAGE_PREFIX "tempfile" PSA_ITS_STORAGE_SUFFIX
53 #define PSA_ITS_MAX_SIZE 0xffffffff
55 #define PSA_ITS_MAGIC_STRING "PSA\0ITS\0"
56 #define PSA_ITS_MAGIC_LENGTH 8
62 #define rename_replace_existing(oldpath, newpath) \
63 (!MoveFileExA(oldpath, newpath, MOVEFILE_REPLACE_EXISTING))
65 #define rename_replace_existing(oldpath, newpath) rename(oldpath, newpath)
81 (
unsigned) (uid >> 32),
82 (
unsigned) (uid & 0xffffffff),
96 *p_stream = fopen(filename,
"rb");
97 if (*p_stream ==
NULL) {
101 n = fread(&header, 1,
sizeof(header), *p_stream);
102 if (
n !=
sizeof(header)) {
111 header.
size[1] << 8 |
112 header.
size[2] << 16 |
113 header.
size[3] << 24);
115 header.
flags[1] << 8 |
116 header.
flags[2] << 16 |
117 header.
flags[3] << 24);
127 if (stream !=
NULL) {
137 size_t *p_data_length)
149 if (data_offset + data_length < data_offset) {
152 #if SIZE_MAX < 0xffffffff
153 if (data_offset + data_length >
SIZE_MAX) {
157 if (data_offset + data_length >
info.size) {
162 #if LONG_MAX < 0xffffffff
163 while (data_offset > LONG_MAX) {
167 data_offset -= LONG_MAX;
173 n = fread(p_data, 1, data_length, stream);
174 if (
n != data_length) {
178 if (p_data_length !=
NULL) {
183 if (stream !=
NULL) {
210 if (stream ==
NULL) {
215 n = fwrite(&header, 1,
sizeof(header), stream);
216 if (
n !=
sizeof(header)) {
219 if (data_length != 0) {
220 n = fwrite(p_data, 1, data_length, stream);
221 if (
n != data_length) {
228 if (stream !=
NULL) {
229 int ret = fclose(stream);
253 stream = fopen(filename,
"rb");
254 if (stream ==
NULL) {
258 if (
remove(filename) != 0) {
#define MBEDTLS_PUT_UINT32_LE(n, data, offset)
Put in memory a 32 bits unsigned integer in little-endian order.
static void DLIST_NAME() remove(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
int32_t psa_status_t
Function return status.
#define PSA_ERROR_DOES_NOT_EXIST
Asking for an item that doesn't exist.
#define PSA_SUCCESS
The action was completed successfully.
#define PSA_ERROR_INVALID_ARGUMENT
The parameters passed to the function are invalid.
#define PSA_ERROR_INSUFFICIENT_STORAGE
There is not enough persistent storage.
#define PSA_ERROR_DATA_CORRUPT
Stored data has been corrupted.
#define PSA_ERROR_STORAGE_FAILURE
There was a storage failure that may have led to data loss.
#define PSA_ERROR_INVALID_HANDLE
The key identifier is not valid.
Interface of trusted storage that crypto is built on.
psa_status_t psa_its_set(psa_storage_uid_t uid, uint32_t data_length, const void *p_data, psa_storage_create_flags_t create_flags)
create a new or modify an existing uid/value pair
uint32_t psa_storage_create_flags_t
Flags used when creating a data entry.
psa_status_t psa_its_get(psa_storage_uid_t uid, uint32_t data_offset, uint32_t data_length, void *p_data, size_t *p_data_length)
Retrieve the value associated with a provided uid.
psa_status_t psa_its_remove(psa_storage_uid_t uid)
Remove the provided key and its associated data from the storage.
psa_status_t psa_its_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info)
Retrieve the metadata about the provided uid.
uint64_t psa_storage_uid_t
A type for UIDs used for identifying data.
static void psa_its_fill_filename(psa_storage_uid_t uid, char *filename)
#define PSA_ITS_STORAGE_SUFFIX
static psa_status_t psa_its_read_file(psa_storage_uid_t uid, struct psa_storage_info_t *p_info, FILE **p_stream)
#define PSA_ITS_STORAGE_FILENAME_PATTERN
#define PSA_ITS_STORAGE_PREFIX
#define PSA_ITS_MAGIC_STRING
#define PSA_ITS_STORAGE_TEMP
#define rename_replace_existing(oldpath, newpath)
#define PSA_ITS_STORAGE_FILENAME_LENGTH
#define PSA_ITS_MAGIC_LENGTH
A container for metadata associated with a specific uid.
psa_storage_create_flags_t flags
The flags set when the uid was created.
uint32_t size
The size of the data associated with a uid.