Skip to content

Commit 3157d55

Browse files
committed
[crypto] PSA API: Introduce example native ITS implementation
1 parent 4066eb8 commit 3157d55

File tree

6 files changed

+980
-0
lines changed

6 files changed

+980
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2020, The OpenThread Authors.
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
# 1. Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
# 2. Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# 3. Neither the name of the copyright holder nor the
12+
# names of its contributors may be used to endorse or promote products
13+
# derived from this software without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
# POSSIBILITY OF SUCH DAMAGE.
26+
#
27+
28+
29+
config("openthread-native-its-file") {
30+
include_dirs = [
31+
"include",
32+
]
33+
}
34+
35+
static_library("openthread-native-its-file") {
36+
sources = [
37+
"src/file/its_file.c"
38+
]
39+
40+
configs += [
41+
":openthread-native-its-config",
42+
]
43+
44+
defines = [ "OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE=1" ]
45+
}
46+
47+
static_library("openthread-native-its-file") {
48+
sources = [
49+
"src/ram/its_ram.c"
50+
]
51+
52+
configs += [
53+
":openthread-native-its-config",
54+
]
55+
56+
defines = [ "OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_RAM=1" ]
57+
}
58+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# Copyright (c) 2024, The OpenThread Authors.
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# 1. Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# 2. Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# 3. Neither the name of the copyright holder nor the
13+
# names of its contributors may be used to endorse or promote products
14+
# derived from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
# POSSIBILITY OF SUCH DAMAGE.
27+
#
28+
29+
add_library(openthread-native-its-file STATIC)
30+
target_sources(openthread-native-its-file PRIVATE
31+
src/file/its_file.c
32+
)
33+
target_include_directories(openthread-native-its-file PUBLIC
34+
"${CMAKE_CURRENT_SOURCE_DIR}/include"
35+
${OT_PUBLIC_INCLUDES}
36+
$<TARGET_PROPERTY:ot-config,INTERFACE_INCLUDE_DIRECTORIES>
37+
)
38+
target_compile_definitions(openthread-native-its-file
39+
PRIVATE
40+
$<TARGET_PROPERTY:ot-config,INTERFACE_COMPILE_DEFINITIONS>
41+
PUBLIC
42+
OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE=1
43+
)
44+
45+
add_library(openthread-native-its-ram STATIC)
46+
target_sources(openthread-native-its-ram PRIVATE
47+
src/ram/its_ram.c
48+
)
49+
target_include_directories(openthread-native-its-ram PUBLIC
50+
"${CMAKE_CURRENT_SOURCE_DIR}/include"
51+
${OT_PUBLIC_INCLUDES}
52+
$<TARGET_PROPERTY:ot-config,INTERFACE_INCLUDE_DIRECTORIES>
53+
)
54+
target_compile_definitions(openthread-native-its-ram
55+
PRIVATE
56+
$<TARGET_PROPERTY:ot-config,INTERFACE_COMPILE_DEFINITIONS>
57+
PUBLIC
58+
OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_RAM=1
59+
)
60+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2024, The OpenThread Authors.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* 3. Neither the name of the copyright holder nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#ifndef PSA_ERROR_H__
30+
#define PSA_ERROR_H__
31+
32+
#include <stdint.h>
33+
34+
typedef int32_t psa_status_t;
35+
36+
#define PSA_SUCCESS ((psa_status_t)0)
37+
#define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132)
38+
#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133)
39+
#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)
40+
#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135)
41+
#define PSA_ERROR_ALREADY_EXISTS ((psa_status_t)-139)
42+
#define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140)
43+
#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)
44+
#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146)
45+
#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
46+
#define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152)
47+
48+
#endif /* PSA_ERROR_H__ */
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) 2024, The OpenThread Authors.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* 3. Neither the name of the copyright holder nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#ifndef PSA_INTERNAL_TRUSTED_STORAGE_H__
30+
#define PSA_INTERNAL_TRUSTED_STORAGE_H__
31+
32+
#include <stdint.h>
33+
34+
#ifdef __cplusplus
35+
extern "C" {
36+
#endif
37+
38+
#include "psa/error.h"
39+
40+
/** \brief Flags used when creating a data entry
41+
*/
42+
typedef uint32_t psa_storage_create_flags_t;
43+
44+
/** \brief A type for UIDs used for identifying data
45+
*/
46+
typedef uint64_t psa_storage_uid_t;
47+
48+
#define PSA_STORAGE_FLAG_NONE 0 /**< No flags to pass */
49+
#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`*/
50+
51+
/**
52+
* \brief A container for metadata associated with a specific uid
53+
*/
54+
struct psa_storage_info_t {
55+
uint32_t size; /**< The size of the data associated with a uid **/
56+
psa_storage_create_flags_t flags; /**< The flags set when the uid was created **/
57+
};
58+
59+
/** Flag indicating that \ref psa_storage_create and \ref psa_storage_set_extended are supported */
60+
#define PSA_STORAGE_SUPPORT_SET_EXTENDED (1 << 0)
61+
62+
#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 */
63+
#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 */
64+
65+
/**
66+
* \brief Create a new or modify an existing uid/value pair
67+
*
68+
* \param[in] aUid The identifier for the data
69+
* \param[in] aDataLength The size in bytes of the data in `p_data`
70+
* \param[in] aData A buffer containing the data
71+
* \param[in] aCreateFlags The flags that the data will be stored with
72+
*
73+
* \return A status indicating the success/failure of the operation
74+
*
75+
* \retval #PSA_SUCCESS The operation completed successfully
76+
* \retval #PSA_ERROR_NOT_PERMITTED The operation failed because the provided `uid` value was already created with PSA_STORAGE_FLAG_WRITE_ONCE
77+
* \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
78+
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE The operation failed because there was insufficient space on the storage medium
79+
* \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
80+
* \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`)
81+
* is invalid, for example is `NULL` or references memory the caller cannot access
82+
*/
83+
psa_status_t psa_its_set(psa_storage_uid_t aUid,
84+
uint32_t aDataLength,
85+
const void *aData,
86+
psa_storage_create_flags_t aCreateFlags);
87+
88+
/**
89+
* \brief Retrieve the value associated with a provided uid
90+
*
91+
* \param[in] aUid The uid value
92+
* \param[in] aDataOffset The starting offset of the data requested
93+
* \param[in] aDataLength The amount of data requested (and the minimum allocated size of the `p_data` buffer)
94+
* \param[out] aData The buffer where the data will be placed upon successful completion
95+
* \param[out] aDataLengthOut The amount of data returned in the p_data buffer
96+
*
97+
*
98+
* \return A status indicating the success/failure of the operation
99+
*
100+
* \retval #PSA_SUCCESS The operation completed successfully
101+
* \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided `uid` value was not found in the storage
102+
* \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
103+
* \retval #PSA_ERROR_DATA_CORRUPT The operation failed because stored data has been corrupted
104+
* \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`, `p_data_length`)
105+
* is invalid. For example is `NULL` or references memory the caller cannot access.
106+
* In addition, this can also happen if an invalid offset was provided.
107+
*/
108+
psa_status_t psa_its_get(psa_storage_uid_t aUid,
109+
uint32_t aDataOffset,
110+
uint32_t aDataLength,
111+
void *aData,
112+
size_t *aDataLengthOut);
113+
114+
/**
115+
* \brief Retrieve the metadata about the provided uid
116+
*
117+
* \param[in] aUid The uid value
118+
* \param[out] aInfo A pointer to the `psa_storage_info_t` struct that will be populated with the metadata
119+
*
120+
* \return A status indicating the success/failure of the operation
121+
*
122+
* \retval #PSA_SUCCESS The operation completed successfully
123+
* \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage
124+
* \retval #PSA_ERROR_DATA_CORRUPT The operation failed because stored data has been corrupted
125+
* \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_info`)
126+
* is invalid, for example is `NULL` or references memory the caller cannot access
127+
*/
128+
psa_status_t psa_its_get_info(psa_storage_uid_t aUid,
129+
struct psa_storage_info_t *aInfo);
130+
131+
/**
132+
* \brief Remove the provided key and its associated data from the storage
133+
*
134+
* \param[in] aUid The uid value
135+
*
136+
* \return A status indicating the success/failure of the operation
137+
*
138+
* \retval #PSA_SUCCESS The operation completed successfully
139+
* \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided key value was not found in the storage
140+
* \retval #PSA_ERROR_NOT_PERMITTED The operation failed because the provided key value was created with PSA_STORAGE_FLAG_WRITE_ONCE
141+
* \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
142+
*/
143+
psa_status_t psa_its_remove(psa_storage_uid_t aUid);
144+
145+
#ifdef __cplusplus
146+
}
147+
#endif
148+
149+
#endif /* PSA_INTERNAL_TRUSTED_STORAGE_H__ */

0 commit comments

Comments
 (0)