diff options
author | Paul Selkirk <paul@psgd.org> | 2016-08-10 17:48:40 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2016-08-10 17:49:02 -0400 |
commit | f5a63c380d9091b002949624001b2b1426454b56 (patch) | |
tree | 341e4c50b139559abf8cd230c4e2463fe48a8b05 /modexp.c | |
parent | 9960e43c1a6b7f83b4a345acedbda56fbeaaae0c (diff) | |
parent | 30f8e4e85b6a337291b09d55d8edc15e422b6341 (diff) |
Merge branch 'resource_management'
Diffstat (limited to 'modexp.c')
-rw-r--r-- | modexp.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -138,12 +138,14 @@ static hal_error_t set_buffer(const hal_core_t *core, * Run one modexp operation. */ -hal_error_t hal_modexp(const hal_core_t *core, +hal_error_t hal_modexp(hal_core_t *core, const uint8_t * const msg, const size_t msg_len, /* Message */ const uint8_t * const exp, const size_t exp_len, /* Exponent */ const uint8_t * const mod, const size_t mod_len, /* Modulus */ uint8_t *result, const size_t result_len) { + hal_error_t err; + /* * All pointers must be set, neither message nor exponent may be * longer than modulus, result buffer must not be shorter than @@ -160,6 +162,22 @@ hal_error_t hal_modexp(const hal_core_t *core, ((msg_len | exp_len | mod_len) & 3) != 0) return HAL_ERROR_BAD_ARGUMENTS; + if (((err = hal_core_alloc(MODEXPS6_NAME, &core)) == HAL_ERROR_CORE_NOT_FOUND) && + ((err = hal_core_alloc(MODEXPA7_NAME, &core)) != HAL_OK)) + return err; + +#undef check +#define check(_expr_) \ + do { \ + hal_error_t _err = (_expr_); \ + if (_err != HAL_OK && debug) \ + printf("%s failed: %s\n", #_expr_, hal_error_string(_err)); \ + if (_err != HAL_OK) { \ + hal_core_free(core); \ + return _err; \ + } \ + } while (0) + /* * We probably ought to take the mode (fast vs constant-time) as an * argument, but for the moment we just guess that really short |