diff options
author | Paul Selkirk <paul@psgd.org> | 2020-02-18 19:36:58 -0500 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2020-02-18 20:23:51 -0500 |
commit | eda207f0a3d571a774039d772bff40131ff218d6 (patch) | |
tree | 311f689d48e6ca7d2335df0245d946d02e697d88 /modexp.c | |
parent | ddbbfa19b7c4503b44ebe5fa6437cfa11e3b1c5f (diff) |
timing tests for RSA signingmodexpng
Diffstat (limited to 'modexp.c')
-rw-r--r-- | modexp.c | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -11,8 +11,9 @@ * enough that this module is no longer needed, it will go away. * * Authors: Rob Austein - * Copyright (c) 2015-2017, NORDUnet A/S - * All rights reserved. + * Copyright (c) 2015-2017, NORDUnet A/S All rights reserved. + * Copyright: 2020, The Commons Conservancy Cryptech Project + * SPDX-License-Identifier: BSD-3-Clause * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -24,9 +25,9 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * - Neither the name of the NORDUnet nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * - Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -47,6 +48,13 @@ #include "hal.h" #include "hal_internal.h" +#ifdef DO_TIMING +#include "stm-dwt.h" +#else +#define DWT_start(x) HAL_OK +#define DWT_stop(x) HAL_OK +#endif + /* * Whether we want to use the new ModExpNG core. */ @@ -267,7 +275,7 @@ static inline hal_error_t setup_calc(const int precalc, hal_modexp_arg_t *a) if ((precalc && (err = get_buffer(a->core, MODEXPA7_ADDR_MODULUS_COEFF_OUT, a->coeff, a->coeff_len)) != HAL_OK) || (precalc && - (err = get_buffer(a->core, MODEXPA7_ADDR_MONTGOMERY_FACTOR_OUT, a->mont, a->mont_len)) != HAL_OK) || + (err = get_buffer(a->core, MODEXPA7_ADDR_MONTGOMERY_FACTOR_OUT, a->mont, a->mont_len)) != HAL_OK) || (err = set_buffer(a->core, MODEXPA7_ADDR_MODULUS_COEFF_IN, a->coeff, a->coeff_len)) != HAL_OK || (err = set_buffer(a->core, MODEXPA7_ADDR_MONTGOMERY_FACTOR_IN, a->mont, a->mont_len)) != HAL_OK || (err = set_register(a->core, MODEXPA7_ADDR_MODE, mode)) != HAL_OK || @@ -305,9 +313,11 @@ hal_error_t hal_modexp(const int precalc, hal_modexp_arg_t *a) if ((!free_core || (err = hal_core_alloc(MODEXPA7_NAME, &a->core, NULL)) == HAL_OK) && + (err = DWT_start(DWT_precalc_n)) == HAL_OK && (err = setup_precalc(precalc, a)) == HAL_OK && (!precalc || (err = hal_io_wait_ready(a->core)) == HAL_OK) && + (err = DWT_stop(DWT_precalc_n)) == HAL_OK && (err = setup_calc(precalc, a)) == HAL_OK && (err = hal_io_wait_valid(a->core)) == HAL_OK && (err = extract_result(a)) == HAL_OK) @@ -342,10 +352,12 @@ hal_error_t hal_modexp2(const int precalc, hal_modexp_arg_t *a1, hal_modexp_arg_ if ((!free_core || (err = hal_core_alloc2(MODEXPA7_NAME, &a1->core, NULL, MODEXPA7_NAME, &a2->core, NULL)) == HAL_OK) && + (err = DWT_start(DWT_precalc_pq)) == HAL_OK && (err = setup_precalc(precalc, a1)) == HAL_OK && (err = setup_precalc(precalc, a2)) == HAL_OK && (!precalc || (err = hal_io_wait_ready2(a1->core, a2->core)) == HAL_OK) && + (err = DWT_stop(DWT_precalc_pq)) == HAL_OK && (err = setup_calc(precalc, a1)) == HAL_OK && (err = setup_calc(precalc, a2)) == HAL_OK && (err = hal_io_wait_valid2(a1->core, a2->core)) == HAL_OK && |