2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
|
* \file timing.h
|
2009-01-04 17:27:10 +01:00
|
|
|
*
|
2017-10-10 19:46:45 +02:00
|
|
|
* \brief Portable interface to timeouts and to the CPU cycle counter
|
2018-01-05 16:33:17 +01:00
|
|
|
*/
|
|
|
|
|
/*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2023-11-02 20:47:20 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
2015-04-08 12:49:31 +02:00
|
|
|
#ifndef MBEDTLS_TIMING_H
|
|
|
|
|
#define MBEDTLS_TIMING_H
|
2021-05-19 19:44:07 +02:00
|
|
|
#include "mbedtls/private_access.h"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2021-05-27 11:25:03 +02:00
|
|
|
#include "mbedtls/build_info.h"
|
2014-02-06 15:11:55 +01:00
|
|
|
|
2015-05-12 20:17:06 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2013-06-27 14:29:21 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-04-01 14:59:58 +02:00
|
|
|
#if !defined(MBEDTLS_TIMING_ALT)
|
|
|
|
|
// Regular implementation
|
|
|
|
|
//
|
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
|
* \brief timer structure
|
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
struct mbedtls_timing_hr_time {
|
2023-03-31 12:40:24 +02:00
|
|
|
uint64_t MBEDTLS_PRIVATE(opaque)[4];
|
2009-01-03 22:22:43 +01:00
|
|
|
};
|
|
|
|
|
|
2015-05-12 20:17:06 +02:00
|
|
|
/**
|
|
|
|
|
* \brief Context for mbedtls_timing_set/get_delay()
|
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct mbedtls_timing_delay_context {
|
2021-06-07 11:28:24 +02:00
|
|
|
struct mbedtls_timing_hr_time MBEDTLS_PRIVATE(timer);
|
2021-05-19 19:44:07 +02:00
|
|
|
uint32_t MBEDTLS_PRIVATE(int_ms);
|
|
|
|
|
uint32_t MBEDTLS_PRIVATE(fin_ms);
|
2015-05-12 20:17:06 +02:00
|
|
|
} mbedtls_timing_delay_context;
|
|
|
|
|
|
2018-04-01 14:59:58 +02:00
|
|
|
#else /* MBEDTLS_TIMING_ALT */
|
|
|
|
|
#include "timing_alt.h"
|
|
|
|
|
#endif /* MBEDTLS_TIMING_ALT */
|
|
|
|
|
|
2021-06-16 11:22:53 +02:00
|
|
|
/* Internal use */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned long mbedtls_timing_get_timer(struct mbedtls_timing_hr_time *val, int reset);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2015-05-12 20:17:06 +02:00
|
|
|
/**
|
|
|
|
|
* \brief Set a pair of delays to watch
|
|
|
|
|
* (See \c mbedtls_timing_get_delay().)
|
|
|
|
|
*
|
2017-10-10 19:46:45 +02:00
|
|
|
* \param data Pointer to timing data.
|
2015-09-25 04:27:22 +02:00
|
|
|
* Must point to a valid \c mbedtls_timing_delay_context struct.
|
2015-05-12 20:17:06 +02:00
|
|
|
* \param int_ms First (intermediate) delay in milliseconds.
|
2017-10-10 19:46:45 +02:00
|
|
|
* The effect if int_ms > fin_ms is unspecified.
|
2015-05-12 20:17:06 +02:00
|
|
|
* \param fin_ms Second (final) delay in milliseconds.
|
|
|
|
|
* Pass 0 to cancel the current delay.
|
2017-10-10 19:46:45 +02:00
|
|
|
*
|
|
|
|
|
* \note To set a single delay, either use \c mbedtls_timing_set_timer
|
|
|
|
|
* directly or use this function with int_ms == fin_ms.
|
2015-05-12 20:17:06 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms);
|
2015-05-12 20:17:06 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Get the status of delays
|
|
|
|
|
* (Memory helper: number of delays passed.)
|
|
|
|
|
*
|
|
|
|
|
* \param data Pointer to timing data
|
2015-09-25 04:27:22 +02:00
|
|
|
* Must point to a valid \c mbedtls_timing_delay_context struct.
|
2015-05-12 20:17:06 +02:00
|
|
|
*
|
2017-10-10 19:46:45 +02:00
|
|
|
* \return -1 if cancelled (fin_ms = 0),
|
2015-05-12 20:17:06 +02:00
|
|
|
* 0 if none of the delays are passed,
|
|
|
|
|
* 1 if only the intermediate delay is passed,
|
|
|
|
|
* 2 if the final delay is passed.
|
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_timing_get_delay(void *data);
|
2015-05-12 20:17:06 +02:00
|
|
|
|
2022-03-09 16:34:37 +01:00
|
|
|
/**
|
|
|
|
|
* \brief Get the final timing delay
|
|
|
|
|
*
|
|
|
|
|
* \param data Pointer to timing data
|
|
|
|
|
* Must point to a valid \c mbedtls_timing_delay_context struct.
|
|
|
|
|
*
|
|
|
|
|
* \return Final timing delay in milliseconds.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t mbedtls_timing_get_final_delay(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_timing_delay_context *data);
|
2022-03-09 16:34:37 +01:00
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* timing.h */
|