diff options
author | Paul Selkirk <paul@psgd.org> | 2020-03-10 19:18:33 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2020-03-10 19:18:33 -0400 |
commit | 040341007cf4492fdc8aa2d3f198dd22c2288ced (patch) | |
tree | 307da7c8c2406eedac2895f13a982f41e821fb63 /modexp.c | |
parent | c1ef4b322756753251d5ff4125d819a156dd16e7 (diff) |
auto-detect cores
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); } /* |