Skip to content

Commit fbd959e

Browse files
Oren CohenMichael Schwarcz
authored andcommitted
Add PSA-crypto partition & IPC code
1 parent 6822ba9 commit fbd959e

File tree

15 files changed

+3408
-15
lines changed

15 files changed

+3408
-15
lines changed

TESTS/psa/prot_internal_storage/COMPONENT_SPE/psa_setup.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
#include "handles_manager.h"
2727
#include "cmsis.h"
2828
#include "psa_test_its_reset_partition.h"
29+
#include "psa_psa_f_partition.h"
2930
#include "psa_its_partition.h"
3031

3132

32-
spm_partition_t g_partitions[2] = {
33+
spm_partition_t g_partitions[3] = {
3334
{
3435
.partition_id = TEST_ITS_RESET_ID,
3536
.thread_id = 0,
@@ -41,6 +42,17 @@ spm_partition_t g_partitions[2] = {
4142
.extern_sids_count = TEST_ITS_RESET_EXT_ROT_SRV_COUNT,
4243
.irq_mapper = NULL,
4344
},
45+
{
46+
.partition_id = PSA_F_ID,
47+
.thread_id = 0,
48+
.flags_rot_srv = PSA_F_WAIT_ANY_SID_MSK,
49+
.flags_interrupts = 0,
50+
.rot_services = NULL,
51+
.rot_services_count = PSA_F_ROT_SRV_COUNT,
52+
.extern_sids = NULL,
53+
.extern_sids_count = PSA_F_EXT_ROT_SRV_COUNT,
54+
.irq_mapper = NULL,
55+
},
4456
{
4557
.partition_id = ITS_ID,
4658
.thread_id = 0,
@@ -63,6 +75,7 @@ const uint32_t mem_region_count = 0;
6375

6476
// forward declaration of partition initializers
6577
void test_its_reset_init(spm_partition_t *partition);
78+
void psa_f_init(spm_partition_t *partition);
6679
void its_init(spm_partition_t *partition);
6780

6881
uint32_t init_partitions(spm_partition_t **partitions)
@@ -72,9 +85,10 @@ uint32_t init_partitions(spm_partition_t **partitions)
7285
}
7386

7487
test_its_reset_init(&(g_partitions[0]));
75-
its_init(&(g_partitions[1]));
88+
psa_f_init(&(g_partitions[1]));
89+
its_init(&(g_partitions[2]));
7690

7791
*partitions = g_partitions;
78-
return 2;
92+
return 3;
7993
}
8094

TESTS/psa/spm_client/COMPONENT_SPE/psa_setup.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
#include "handles_manager.h"
2727
#include "cmsis.h"
2828
#include "psa_client_tests_part1_partition.h"
29+
#include "psa_psa_f_partition.h"
2930
#include "psa_its_partition.h"
3031

3132

32-
spm_partition_t g_partitions[2] = {
33+
spm_partition_t g_partitions[3] = {
3334
{
3435
.partition_id = CLIENT_TESTS_PART1_ID,
3536
.thread_id = 0,
@@ -41,6 +42,17 @@ spm_partition_t g_partitions[2] = {
4142
.extern_sids_count = CLIENT_TESTS_PART1_EXT_ROT_SRV_COUNT,
4243
.irq_mapper = NULL,
4344
},
45+
{
46+
.partition_id = PSA_F_ID,
47+
.thread_id = 0,
48+
.flags_rot_srv = PSA_F_WAIT_ANY_SID_MSK,
49+
.flags_interrupts = 0,
50+
.rot_services = NULL,
51+
.rot_services_count = PSA_F_ROT_SRV_COUNT,
52+
.extern_sids = NULL,
53+
.extern_sids_count = PSA_F_EXT_ROT_SRV_COUNT,
54+
.irq_mapper = NULL,
55+
},
4456
{
4557
.partition_id = ITS_ID,
4658
.thread_id = 0,
@@ -63,6 +75,7 @@ const uint32_t mem_region_count = 0;
6375

6476
// forward declaration of partition initializers
6577
void client_tests_part1_init(spm_partition_t *partition);
78+
void psa_f_init(spm_partition_t *partition);
6679
void its_init(spm_partition_t *partition);
6780

6881
uint32_t init_partitions(spm_partition_t **partitions)
@@ -72,9 +85,10 @@ uint32_t init_partitions(spm_partition_t **partitions)
7285
}
7386

7487
client_tests_part1_init(&(g_partitions[0]));
75-
its_init(&(g_partitions[1]));
88+
psa_f_init(&(g_partitions[1]));
89+
its_init(&(g_partitions[2]));
7690

7791
*partitions = g_partitions;
78-
return 2;
92+
return 3;
7993
}
8094

TESTS/psa/spm_server/COMPONENT_SPE/psa_setup.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
#include "cmsis.h"
2828
#include "psa_server_test_part1_partition.h"
2929
#include "psa_server_test_part2_partition.h"
30+
#include "psa_psa_f_partition.h"
3031
#include "psa_its_partition.h"
3132

3233
extern const uint32_t server_test_part1_external_sids[2];
3334

34-
spm_partition_t g_partitions[3] = {
35+
spm_partition_t g_partitions[4] = {
3536
{
3637
.partition_id = SERVER_TEST_PART1_ID,
3738
.thread_id = 0,
@@ -54,6 +55,17 @@ spm_partition_t g_partitions[3] = {
5455
.extern_sids_count = SERVER_TEST_PART2_EXT_ROT_SRV_COUNT,
5556
.irq_mapper = NULL,
5657
},
58+
{
59+
.partition_id = PSA_F_ID,
60+
.thread_id = 0,
61+
.flags_rot_srv = PSA_F_WAIT_ANY_SID_MSK,
62+
.flags_interrupts = 0,
63+
.rot_services = NULL,
64+
.rot_services_count = PSA_F_ROT_SRV_COUNT,
65+
.extern_sids = NULL,
66+
.extern_sids_count = PSA_F_EXT_ROT_SRV_COUNT,
67+
.irq_mapper = NULL,
68+
},
5769
{
5870
.partition_id = ITS_ID,
5971
.thread_id = 0,
@@ -77,6 +89,7 @@ const uint32_t mem_region_count = 0;
7789
// forward declaration of partition initializers
7890
void server_test_part1_init(spm_partition_t *partition);
7991
void server_test_part2_init(spm_partition_t *partition);
92+
void psa_f_init(spm_partition_t *partition);
8093
void its_init(spm_partition_t *partition);
8194

8295
uint32_t init_partitions(spm_partition_t **partitions)
@@ -87,9 +100,10 @@ uint32_t init_partitions(spm_partition_t **partitions)
87100

88101
server_test_part1_init(&(g_partitions[0]));
89102
server_test_part2_init(&(g_partitions[1]));
90-
its_init(&(g_partitions[2]));
103+
psa_f_init(&(g_partitions[2]));
104+
its_init(&(g_partitions[3]));
91105

92106
*partitions = g_partitions;
93-
return 3;
107+
return 4;
94108
}
95109

TESTS/psa/spm_smoke/COMPONENT_SPE/psa_setup.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
#include "handles_manager.h"
2727
#include "cmsis.h"
2828
#include "psa_smoke_test_part1_partition.h"
29+
#include "psa_psa_f_partition.h"
2930
#include "psa_its_partition.h"
3031

3132

32-
spm_partition_t g_partitions[2] = {
33+
spm_partition_t g_partitions[3] = {
3334
{
3435
.partition_id = SMOKE_TEST_PART1_ID,
3536
.thread_id = 0,
@@ -41,6 +42,17 @@ spm_partition_t g_partitions[2] = {
4142
.extern_sids_count = SMOKE_TEST_PART1_EXT_ROT_SRV_COUNT,
4243
.irq_mapper = NULL,
4344
},
45+
{
46+
.partition_id = PSA_F_ID,
47+
.thread_id = 0,
48+
.flags_rot_srv = PSA_F_WAIT_ANY_SID_MSK,
49+
.flags_interrupts = 0,
50+
.rot_services = NULL,
51+
.rot_services_count = PSA_F_ROT_SRV_COUNT,
52+
.extern_sids = NULL,
53+
.extern_sids_count = PSA_F_EXT_ROT_SRV_COUNT,
54+
.irq_mapper = NULL,
55+
},
4456
{
4557
.partition_id = ITS_ID,
4658
.thread_id = 0,
@@ -63,6 +75,7 @@ const uint32_t mem_region_count = 0;
6375

6476
// forward declaration of partition initializers
6577
void smoke_test_part1_init(spm_partition_t *partition);
78+
void psa_f_init(spm_partition_t *partition);
6679
void its_init(spm_partition_t *partition);
6780

6881
uint32_t init_partitions(spm_partition_t **partitions)
@@ -72,9 +85,10 @@ uint32_t init_partitions(spm_partition_t **partitions)
7285
}
7386

7487
smoke_test_part1_init(&(g_partitions[0]));
75-
its_init(&(g_partitions[1]));
88+
psa_f_init(&(g_partitions[1]));
89+
its_init(&(g_partitions[2]));
7690

7791
*partitions = g_partitions;
78-
return 2;
92+
return 3;
7993
}
8094

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/**
2+
* \file psa/crypto_platform_spe.h
3+
*
4+
* \brief PSA cryptography module: Mbed TLS platfom definitions
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_SPE_PLATFORM_H
26+
#define PSA_CRYPTO_SPE_PLATFORM_H
27+
28+
/* Include the Mbed TLS configuration file, the way Mbed TLS does it
29+
* in each of its header files. */
30+
#if !defined(MBEDTLS_CONFIG_FILE)
31+
#include "../mbedtls/config.h"
32+
#else
33+
#include MBEDTLS_CONFIG_FILE
34+
#endif
35+
36+
/** \defgroup PSA Crypto APIs
37+
* @{
38+
*/
39+
40+
/** \brief psa_s_function_t enum defines for all the available functions in PSA Crypto. */
41+
typedef enum psa_sec_function_s
42+
{
43+
PSA_CRYPTO_INVALID,
44+
PSA_CRYPTO_INIT,
45+
PSA_IMPORT_KEY,
46+
PSA_DESTROY_KEY,
47+
PSA_GET_KEY_INFORMATION,
48+
PSA_EXPORT_KEY,
49+
PSA_EXPORT_PUBLIC_KEY,
50+
PSA_KEY_POLICY_INIT,
51+
PSA_KEY_POLICY_SET_USAGE,
52+
PSA_KEY_POLICY_GET_USAGE,
53+
PSA_KEY_POLICY_GET_ALGORITHM,
54+
PSA_SET_KEY_POLICY,
55+
PSA_GET_KEY_POLICY,
56+
PSA_SET_KEY_LIFETIME,
57+
PSA_GET_KEY_LIFETIME,
58+
PSA_HASH_SETUP,
59+
PSA_HASH_UPDATE,
60+
PSA_HASH_FINISH,
61+
PSA_HASH_VERIFY,
62+
PSA_HASH_ABORT,
63+
PSA_MAC_SIGN_SETUP,
64+
PSA_MAC_VERIFY_SETUP,
65+
PSA_MAC_UPDATE,
66+
PSA_MAC_SIGN_FINISH,
67+
PSA_MAC_VERIFY_FINISH,
68+
PSA_MAC_ABORT,
69+
PSA_CIPHER_ENCRYPT_SETUP,
70+
PSA_CIPHER_DECRYPT_SETUP,
71+
PSA_CIPHER_GENERATE_IV,
72+
PSA_CIPHER_SET_IV,
73+
PSA_CIPHER_UPDATE,
74+
PSA_CIPHER_FINISH,
75+
PSA_CIPHER_ABORT,
76+
PSA_AEAD_ENCRYPT,
77+
PSA_AEAD_DECRYPT,
78+
PSA_ASYMMETRIC_SIGN,
79+
PSA_ASYMMETRIC_VERIFY,
80+
PSA_ASYMMETRIC_ENCRYPT,
81+
PSA_ASYMMETRIC_DECRYPT,
82+
PSA_GENERATE_RANDOM,
83+
PSA_GENERATE_KEY,
84+
PSA_GET_GENERATOR_CAPACITY,
85+
PSA_GENERATOR_READ,
86+
PSA_GENERATOR_IMPORT_KEY,
87+
PSA_GENERATOR_ABORT,
88+
PSA_KEY_DERIVATION
89+
}psa_sec_function_t;
90+
91+
/**@}*/
92+
93+
/** \defgroup PSA Crypto structures for IPC
94+
* @{
95+
*/
96+
97+
/** psa_crypto_ipc_s struct used for some of the
98+
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
99+
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
100+
* pack them together.
101+
*/
102+
103+
typedef struct psa_crypto_ipc_s
104+
{
105+
psa_sec_function_t func;
106+
psa_key_slot_t key;
107+
psa_algorithm_t alg;
108+
} psa_crypto_ipc_t;
109+
110+
/** psa_crypto_derivation_ipc_s struct used for some of the
111+
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
112+
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
113+
* pack them together.
114+
*/
115+
typedef struct psa_crypto_derivation_ipc_s
116+
{
117+
psa_sec_function_t func;
118+
psa_key_slot_t key;
119+
psa_algorithm_t alg;
120+
size_t capacity;
121+
} psa_crypto_derivation_ipc_t;
122+
123+
/** psa_key_mng_ipc_s struct used for some of the
124+
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
125+
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
126+
* pack them together.
127+
*/
128+
129+
typedef struct psa_key_mng_ipc_s
130+
{
131+
psa_key_slot_t key;
132+
psa_key_type_t type;
133+
psa_sec_function_t func;
134+
} psa_key_mng_ipc_t;
135+
136+
/** psa_crypto_ipc_aead_s struct used for AEAD integrated
137+
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t and extra arguments
138+
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
139+
* pack them together.
140+
*/
141+
142+
// Max length supported for nonce is 16 bytes.
143+
#define PSA_MAX_NONCE_SIZE 16
144+
typedef struct psa_crypto_ipc_aead_s
145+
{
146+
psa_sec_function_t func;
147+
psa_key_slot_t key;
148+
psa_algorithm_t alg;
149+
uint16_t nonce_size;
150+
size_t additional_data_length;
151+
size_t input_length;
152+
uint8_t nonce[PSA_MAX_NONCE_SIZE];
153+
} psa_crypto_ipc_aead_t;
154+
155+
/** psa_crypto_ipc_asymmetric_s struct used for asymmetric
156+
* PSA Crypto APIs that need psa_key_slot_t and psa_algorithm_t arguments
157+
* and in order to use the existing infrastructure of the SPM-IPC we provide a struct to
158+
* pack them together.
159+
*/
160+
// Max supported HASH size is 64 bytes - for SHA-512.
161+
#define PSA_HASH_MAX_SIZE 64
162+
typedef struct psa_crypto_ipc_asymmetric_s
163+
{
164+
psa_sec_function_t func;
165+
psa_key_slot_t key;
166+
psa_algorithm_t alg;
167+
size_t input_length;
168+
size_t salt_length;
169+
} psa_crypto_ipc_asymmetric_t;
170+
171+
172+
/**@}*/
173+
174+
#endif /* PSA_CRYPTO_SPE_PLATFORM_H */
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifdef PSA_CRYPTO_SECURE
2+
#include "crypto_struct_spe.h"
3+
#else
4+
#include "crypto_struct_ipc.h"
5+
#endif
6+

0 commit comments

Comments
 (0)