aboutsummaryrefslogtreecommitdiff
path: root/rpc_pkey.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-03-02 20:34:19 -0500
committerRob Austein <sra@hactrn.net>2017-03-02 20:34:19 -0500
commit91bb0444d8830569bfc09900d599c9ae39953f01 (patch)
tree3d4030a905aa3c6865b7fad0943f813a17fc4087 /rpc_pkey.c
parentc2f499e0a301d4ad0f92d58f436d01087ceae1bb (diff)
parenta33470b2f899a94b50304a73721ba6d0d6d447b4 (diff)
Merge branch 'pymux' into hw_ecdsa_p256
Diffstat (limited to 'rpc_pkey.c')
-rw-r--r--rpc_pkey.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/rpc_pkey.c b/rpc_pkey.c
index e2e42c9..ba75f7e 100644
--- a/rpc_pkey.c
+++ b/rpc_pkey.c
@@ -61,6 +61,9 @@ static hal_pkey_slot_t pkey_handle[HAL_STATIC_PKEY_STATE_BLOCKS];
static inline hal_pkey_slot_t *alloc_slot(const hal_key_flags_t flags)
{
+ hal_pkey_slot_t *slot = NULL;
+ hal_critical_section_start();
+
#if HAL_STATIC_PKEY_STATE_BLOCKS > 0
static uint16_t next_glop = 0;
uint32_t glop = ++next_glop << 16;
@@ -71,17 +74,18 @@ static inline hal_pkey_slot_t *alloc_slot(const hal_key_flags_t flags)
if ((flags & HAL_KEY_FLAG_TOKEN) != 0)
glop |= HAL_PKEY_HANDLE_TOKEN_FLAG;
- for (int i = 0; i < sizeof(pkey_handle)/sizeof(*pkey_handle); i++) {
+ for (int i = 0; slot == NULL && i < sizeof(pkey_handle)/sizeof(*pkey_handle); i++) {
if (pkey_handle[i].type != HAL_KEY_TYPE_NONE)
continue;
memset(&pkey_handle[i], 0, sizeof(pkey_handle[i]));
pkey_handle[i].pkey_handle.handle = i | glop;
pkey_handle[i].hint = -1;
- return &pkey_handle[i];
+ slot = &pkey_handle[i];
}
#endif
- return NULL;
+ hal_critical_section_end();
+ return slot;
}
/*
@@ -91,14 +95,18 @@ static inline hal_pkey_slot_t *alloc_slot(const hal_key_flags_t flags)
static inline hal_pkey_slot_t *find_handle(const hal_pkey_handle_t handle)
{
+ hal_pkey_slot_t *slot = NULL;
+ hal_critical_section_start();
+
#if HAL_STATIC_PKEY_STATE_BLOCKS > 0
const int i = (int) (handle.handle & 0xFFFF);
if (i < sizeof(pkey_handle)/sizeof(*pkey_handle) && pkey_handle[i].pkey_handle.handle == handle.handle)
- return &pkey_handle[i];
+ slot = &pkey_handle[i];
#endif
- return NULL;
+ hal_critical_section_end();
+ return slot;
}
/*
@@ -219,7 +227,8 @@ static inline hal_error_t ks_open_from_flags(hal_ks_t **ks, const hal_key_flags_
}
/*
- * Receive key from application, store it with supplied name, return a key handle.
+ * Receive key from application, generate a name (UUID), store it, and
+ * return a key handle and the name.
*/
static hal_error_t pkey_local_load(const hal_client_handle_t client,