blob: 47896b8726dca68bb662a5a05a10c9c30576f54c [file] [log] [blame]
Darryl Greendb2b8db2018-06-15 13:06:04 +01001/**
2 * \file psa_crypto_storage_backend.h
3 *
4 * \brief PSA cryptography module: Mbed TLS key storage backend
5 */
6/*
7 * Copyright (C) 2018, ARM Limited, All Rights Reserved
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 * This file is part of mbed TLS (https://tls.mbed.org)
23 */
24
25#ifndef PSA_CRYPTO_STORAGE_BACKEND_H
26#define PSA_CRYPTO_STORAGE_BACKEND_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/* Include the Mbed TLS configuration file, the way Mbed TLS does it
33 * in each of its header files. */
34#if defined(MBEDTLS_CONFIG_FILE)
35#include MBEDTLS_CONFIG_FILE
36#else
37#include "mbedtls/config.h"
38#endif
39
40#include "psa/crypto.h"
41#include "psa_crypto_storage.h"
42#include <stdint.h>
43
44/**
45 * \brief Load persistent data for the given key slot number.
46 *
47 * This function reads data from a storage backend and returns the data in a
48 * buffer.
49 *
Gilles Peskine8d4919b2018-12-03 16:48:09 +010050 * \param key Persistent identifier of the key to be loaded. This
51 * should be an occupied storage location.
52 * \param[out] data Buffer where the data is to be written.
53 * \param data_size Size of the \c data buffer in bytes.
Darryl Greendb2b8db2018-06-15 13:06:04 +010054 *
55 * \retval PSA_SUCCESS
56 * \retval PSA_ERROR_STORAGE_FAILURE
Gilles Peskine8d4919b2018-12-03 16:48:09 +010057 * \retval PSA_ERROR_EMPTY_SLOT
Darryl Greendb2b8db2018-06-15 13:06:04 +010058 */
Gilles Peskine8d4919b2018-12-03 16:48:09 +010059psa_status_t psa_crypto_storage_load( const psa_key_id_t key, uint8_t *data,
Darryl Greendb2b8db2018-06-15 13:06:04 +010060 size_t data_size );
61
62/**
63 * \brief Store persistent data for the given key slot number.
64 *
65 * This function stores the given data buffer to a persistent storage.
66 *
Gilles Peskine8d4919b2018-12-03 16:48:09 +010067 * \param key Persistent identifier of the key to be stored. This
68 * should be an unoccupied storage location.
Darryl Greendb2b8db2018-06-15 13:06:04 +010069 * \param[in] data Buffer containing the data to be stored.
70 * \param data_length The number of bytes
71 * that make up the data.
72 *
73 * \retval PSA_SUCCESS
74 * \retval PSA_ERROR_INSUFFICIENT_STORAGE
75 * \retval PSA_ERROR_STORAGE_FAILURE
Gilles Peskine8d4919b2018-12-03 16:48:09 +010076 * \retval PSA_ERROR_OCCUPIED_SLOT
Darryl Greendb2b8db2018-06-15 13:06:04 +010077 */
Gilles Peskine8d4919b2018-12-03 16:48:09 +010078psa_status_t psa_crypto_storage_store( const psa_key_id_t key,
Darryl Greendb2b8db2018-06-15 13:06:04 +010079 const uint8_t *data,
80 size_t data_length );
81
82/**
83 * \brief Checks if persistent data is stored for the given key slot number
84 *
85 * This function checks if any key data or metadata exists for the key slot in
86 * the persistent storage.
87 *
Gilles Peskine8d4919b2018-12-03 16:48:09 +010088 * \param key Persistent identifier to check.
Darryl Greendb2b8db2018-06-15 13:06:04 +010089 *
90 * \retval 0
91 * No persistent data present for slot number
92 * \retval 1
93 * Persistent data present for slot number
94 */
Gilles Peskine8d4919b2018-12-03 16:48:09 +010095int psa_is_key_present_in_storage( const psa_key_id_t key );
Darryl Greendb2b8db2018-06-15 13:06:04 +010096
97/**
98 * \brief Get data length for given key slot number.
99 *
Gilles Peskine8d4919b2018-12-03 16:48:09 +0100100 * \param key Persistent identifier whose stored data length
101 * is to be obtained.
102 * \param[out] data_length The number of bytes that make up the data.
Darryl Greendb2b8db2018-06-15 13:06:04 +0100103 *
104 * \retval PSA_SUCCESS
105 * \retval PSA_ERROR_STORAGE_FAILURE
106 */
Gilles Peskine8d4919b2018-12-03 16:48:09 +0100107psa_status_t psa_crypto_storage_get_data_length( const psa_key_id_t key,
Darryl Greendb2b8db2018-06-15 13:06:04 +0100108 size_t *data_length );
109
110
111#ifdef __cplusplus
112}
113#endif
114
115#endif /* PSA_CRYPTO_STORAGE_H */