mbedtls ported to mbed-classic
Fork of mbedtls by
Embed:
(wiki syntax)
Show/hide line numbers
timing.h
Go to the documentation of this file.
00001 /** 00002 * \file timing.h 00003 * 00004 * \brief Portable interface to the CPU cycle counter 00005 * 00006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 * 00021 * This file is part of mbed TLS (https://tls.mbed.org) 00022 */ 00023 #ifndef MBEDTLS_TIMING_H 00024 #define MBEDTLS_TIMING_H 00025 00026 #if !defined(MBEDTLS_CONFIG_FILE) 00027 #include "config.h" 00028 #else 00029 #include MBEDTLS_CONFIG_FILE 00030 #endif 00031 00032 #if !defined(MBEDTLS_TIMING_ALT) 00033 // Regular implementation 00034 // 00035 00036 #include <stdint.h> 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 /** 00043 * \brief timer structure 00044 */ 00045 struct mbedtls_timing_hr_time 00046 { 00047 unsigned char opaque[32]; 00048 }; 00049 00050 /** 00051 * \brief Context for mbedtls_timing_set/get_delay() 00052 */ 00053 typedef struct 00054 { 00055 struct mbedtls_timing_hr_time timer; 00056 uint32_t int_ms; 00057 uint32_t fin_ms; 00058 } mbedtls_timing_delay_context; 00059 00060 extern volatile int mbedtls_timing_alarmed; 00061 00062 /** 00063 * \brief Return the CPU cycle counter value 00064 * 00065 * \warning This is only a best effort! Do not rely on this! 00066 * In particular, it is known to be unreliable on virtual 00067 * machines. 00068 */ 00069 unsigned long mbedtls_timing_hardclock( void ); 00070 00071 /** 00072 * \brief Return the elapsed time in milliseconds 00073 * 00074 * \param val points to a timer structure 00075 * \param reset if set to 1, the timer is restarted 00076 */ 00077 unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset ); 00078 00079 /** 00080 * \brief Setup an alarm clock 00081 * 00082 * \param seconds delay before the "mbedtls_timing_alarmed" flag is set 00083 * 00084 * \warning Only one alarm at a time is supported. In a threaded 00085 * context, this means one for the whole process, not one per 00086 * thread. 00087 */ 00088 void mbedtls_set_alarm( int seconds ); 00089 00090 /** 00091 * \brief Set a pair of delays to watch 00092 * (See \c mbedtls_timing_get_delay().) 00093 * 00094 * \param data Pointer to timing data 00095 * Must point to a valid \c mbedtls_timing_delay_context struct. 00096 * \param int_ms First (intermediate) delay in milliseconds. 00097 * \param fin_ms Second (final) delay in milliseconds. 00098 * Pass 0 to cancel the current delay. 00099 */ 00100 void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms ); 00101 00102 /** 00103 * \brief Get the status of delays 00104 * (Memory helper: number of delays passed.) 00105 * 00106 * \param data Pointer to timing data 00107 * Must point to a valid \c mbedtls_timing_delay_context struct. 00108 * 00109 * \return -1 if cancelled (fin_ms = 0) 00110 * 0 if none of the delays are passed, 00111 * 1 if only the intermediate delay is passed, 00112 * 2 if the final delay is passed. 00113 */ 00114 int mbedtls_timing_get_delay( void *data ); 00115 00116 #ifdef __cplusplus 00117 } 00118 #endif 00119 00120 #else /* MBEDTLS_TIMING_ALT */ 00121 #include "timing_alt.h" 00122 #endif /* MBEDTLS_TIMING_ALT */ 00123 00124 #ifdef __cplusplus 00125 extern "C" { 00126 #endif 00127 00128 #if defined(MBEDTLS_SELF_TEST) 00129 /** 00130 * \brief Checkup routine 00131 * 00132 * \return 0 if successful, or 1 if a test failed 00133 */ 00134 int mbedtls_timing_self_test( int verbose ); 00135 #endif 00136 00137 #ifdef __cplusplus 00138 } 00139 #endif 00140 00141 #endif /* timing.h */
Generated on Tue Jul 12 2022 12:52:49 by 1.7.2