diff options
Diffstat (limited to 'modexp.c')
-rw-r--r-- | modexp.c | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -49,23 +49,41 @@ #include "hal_internal.h" /* - * Whether we want to use the new ModExpNG core. + * Enable use of the ModExpNG core, if present. */ -static int use_modexpng = 0; +static enum { + unknown = -1, + modexpa7_core = 0, + modexpng_core = 1 +} which_core = unknown; -hal_error_t hal_modexp_use_modexpng(const int onoff) +static inline hal_error_t init_modexp_core(void) { - if (onoff && (hal_core_find(MODEXPNG_NAME, NULL) == NULL)) + if (which_core != unknown) + return HAL_OK; + else if (hal_core_find(MODEXPNG_NAME, NULL) != NULL) + return (which_core = modexpng_core), HAL_OK; + else if (hal_core_find(MODEXPA7_NAME, NULL) != NULL) + return (which_core = modexpa7_core), HAL_OK; + else return HAL_ERROR_CORE_NOT_FOUND; +} - use_modexpng = onoff; - return HAL_OK; +hal_error_t hal_modexp_use_modexpng(const int onoff) +{ + if (onoff && hal_core_find(MODEXPNG_NAME, NULL) != NULL) + return (which_core = modexpng_core), HAL_OK; + else if (!onoff && hal_core_find(MODEXPA7_NAME, NULL) != NULL) + return (which_core = modexpa7_core), HAL_OK; + else + return HAL_ERROR_CORE_NOT_FOUND; } int hal_modexp_using_modexpng(void) { - return use_modexpng; + return (init_modexp_core() == HAL_OK && + which_core == modexpng_core); } /* |