Skip to content

Commit 4de1a70

Browse files
feat(core): add secure session opening function with IDs
Signed-off-by: Benjamin Grolleau <benjamin.grolleau@outlook.com>
1 parent 942bfc6 commit 4de1a70

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

services/stsafea/stsafea_sessions.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,54 @@ stse_ReturnCode_t stsafea_open_host_session(stse_Handler_t *pSTSE, stse_session_
9696
return (STSE_OK);
9797
}
9898

99+
stse_ReturnCode_t stsafea_open_host_session_from_idx(stse_Handler_t *pSTSE, stse_session_t *pSession, PLAT_UI32 Host_MAC_key_idx, PLAT_UI32 Host_cypher_key_idx) {
100+
stse_ReturnCode_t ret;
101+
102+
if (pSTSE == NULL) {
103+
return STSE_CORE_HANDLER_NOT_INITIALISED;
104+
}
105+
106+
if (pSession == NULL) {
107+
return STSE_CORE_SESSION_ERROR;
108+
}
109+
110+
if (pSTSE->device_type == STSAFE_A120) {
111+
stsafea_host_key_slot_v2_t host_key_slot;
112+
113+
ret = stsafea_query_host_key_v2(pSTSE, &host_key_slot);
114+
if (ret != STSE_OK) {
115+
return ret;
116+
}
117+
118+
if (host_key_slot.key_presence_flag == 0) {
119+
return STSE_SERVICE_SESSION_ERROR;
120+
}
121+
pSession->context.host.key_type = (stse_aes_key_type_t)host_key_slot.key_type;
122+
pSession->context.host.MAC_counter = ARRAY_4B_SWAP_TO_UI32(host_key_slot.cmac_sequence_counter);
123+
} else {
124+
stsafea_host_key_slot_t host_key_slot;
125+
126+
ret = stsafea_query_host_key(pSTSE, &host_key_slot);
127+
if (ret != STSE_OK) {
128+
return ret;
129+
}
130+
131+
if (host_key_slot.key_presence_flag == 0) {
132+
return STSE_SERVICE_SESSION_ERROR;
133+
}
134+
pSession->context.host.key_type = STSE_AES_128_KT;
135+
pSession->context.host.MAC_counter = ARRAY_3B_SWAP_TO_UI32(host_key_slot.cmac_sequence_counter);
136+
}
137+
138+
pSession->type = STSE_HOST_SESSION;
139+
pSession->context.host.Host_MAC_key_idx = Host_MAC_key_idx;
140+
pSession->context.host.Host_cypher_key_idx = Host_cypher_key_idx;
141+
pSession->context.host.pSTSE = pSTSE;
142+
pSTSE->pActive_host_session = pSession;
143+
144+
return (STSE_OK);
145+
}
146+
99147
void stsafea_close_host_session(stse_session_t *pSession) {
100148

101149
if (pSession == NULL) {

services/stsafea/stsafea_sessions.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ stse_ReturnCode_t stsafea_open_host_session(stse_Handler_t *pSTSE,
3838
PLAT_UI8 *pHost_MAC_key,
3939
PLAT_UI8 *pHost_cypher_key);
4040

41+
/*!
42+
* \brief This Core function Create a session context and associate it to STSAFE handler based on provided key index
43+
* \details In some configuration, the session keys are already stored in the platform secure storage. This function
44+
* allows to open a session based on the key index in the platform secure storage without providing the key value in input.
45+
* \param[in] *pSession \ref stse_session_t Pointer to session
46+
* \param[in] Host_MAC_key_idx Index of the MAC key in the platform secure storage
47+
* \param[in] Host_cypher_key_idx Index of the cypher key in the platform secure storage
48+
* \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise
49+
* \details \include{doc} stsafe_erase_context.dox
50+
*/
51+
stse_ReturnCode_t stsafea_open_host_session_from_idx(stse_Handler_t *pSTSE,
52+
stse_session_t *pSession,
53+
PLAT_UI32 Host_MAC_key_idx,
54+
PLAT_UI32 Host_cypher_key_idx);
55+
4156
/*!
4257
* \brief This Core function Close an existing host session context
4358
* \param[in] *pSession \ref stse_session_t Pointer to session

0 commit comments

Comments
 (0)