aboutsummaryrefslogtreecommitdiff
path: root/modexp.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2018-01-04 13:15:30 -0500
committerPaul Selkirk <paul@psgd.org>2018-01-04 13:46:44 -0500
commit894181009ad3002d84d2ce6ea74bbd5aea068999 (patch)
tree0c46b96872195194051b6afd03fd6fbc2fe89af1 /modexp.c
parentbc167c214e97ed35f39d088a7dee3f1a9511340e (diff)
Add hal_core_alloc2() to fix a dining philosophers problem in hal_modexp2().
Uncoordinated attempts to allocate two modexpa7 cores leads to deadlock if multiple clients try to do concurrent RSA signing operations. The simplest solution (back off and retry) could theoretically lead to resource starvation, but we haven't seen it in actual testing.
Diffstat (limited to 'modexp.c')
-rw-r--r--modexp.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/modexp.c b/modexp.c
index 7973258..37f5e0e 100644
--- a/modexp.c
+++ b/modexp.c
@@ -11,7 +11,7 @@
* enough that this module is no longer needed, it will go away.
*
* Authors: Rob Austein
- * Copyright (c) 2015, NORDUnet A/S
+ * Copyright (c) 2015-2017, NORDUnet A/S
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,7 +62,7 @@ void hal_modexp_set_debug(const int onoff)
* Get value of an ordinary register.
*/
-static hal_error_t inline get_register(const hal_core_t *core,
+static inline hal_error_t get_register(const hal_core_t *core,
const hal_addr_t addr,
uint32_t *value)
{
@@ -84,7 +84,7 @@ static hal_error_t inline get_register(const hal_core_t *core,
* Set value of an ordinary register.
*/
-static hal_error_t inline set_register(const hal_core_t *core,
+static inline hal_error_t set_register(const hal_core_t *core,
const hal_addr_t addr,
const uint32_t value)
{
@@ -307,8 +307,8 @@ hal_error_t hal_modexp2(const int precalc, hal_modexp_arg_t *a1, hal_modexp_arg_
(err = check_args(a2)) != HAL_OK)
return err;
- if ((err = hal_core_alloc(MODEXPA7_NAME, &a1->core)) == HAL_OK &&
- (err = hal_core_alloc(MODEXPA7_NAME, &a2->core)) == HAL_OK &&
+ if ((err = hal_core_alloc2(MODEXPA7_NAME, &a1->core,
+ MODEXPA7_NAME, &a2->core)) == HAL_OK &&
(err = setup_precalc(precalc, a1)) == HAL_OK &&
(err = setup_precalc(precalc, a2)) == HAL_OK &&
(!precalc ||