Jan Korycan / WNCInterface

Dependencies:   WncControllerK64F

Fork of WNCInterface by Jan Korycan

Committer:
JMF
Date:
Tue Nov 01 14:22:56 2016 +0000
Revision:
12:0071cb144c7a
Adding mbedtls files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 12:0071cb144c7a 1 /**
JMF 12:0071cb144c7a 2 * \file timing.h
JMF 12:0071cb144c7a 3 *
JMF 12:0071cb144c7a 4 * \brief Portable interface to the CPU cycle counter
JMF 12:0071cb144c7a 5 *
JMF 12:0071cb144c7a 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
JMF 12:0071cb144c7a 7 * SPDX-License-Identifier: Apache-2.0
JMF 12:0071cb144c7a 8 *
JMF 12:0071cb144c7a 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
JMF 12:0071cb144c7a 10 * not use this file except in compliance with the License.
JMF 12:0071cb144c7a 11 * You may obtain a copy of the License at
JMF 12:0071cb144c7a 12 *
JMF 12:0071cb144c7a 13 * http://www.apache.org/licenses/LICENSE-2.0
JMF 12:0071cb144c7a 14 *
JMF 12:0071cb144c7a 15 * Unless required by applicable law or agreed to in writing, software
JMF 12:0071cb144c7a 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
JMF 12:0071cb144c7a 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 12:0071cb144c7a 18 * See the License for the specific language governing permissions and
JMF 12:0071cb144c7a 19 * limitations under the License.
JMF 12:0071cb144c7a 20 *
JMF 12:0071cb144c7a 21 * This file is part of mbed TLS (https://tls.mbed.org)
JMF 12:0071cb144c7a 22 */
JMF 12:0071cb144c7a 23 #ifndef MBEDTLS_TIMING_H
JMF 12:0071cb144c7a 24 #define MBEDTLS_TIMING_H
JMF 12:0071cb144c7a 25
JMF 12:0071cb144c7a 26 #if !defined(MBEDTLS_CONFIG_FILE)
JMF 12:0071cb144c7a 27 #include "config.h"
JMF 12:0071cb144c7a 28 #else
JMF 12:0071cb144c7a 29 #include MBEDTLS_CONFIG_FILE
JMF 12:0071cb144c7a 30 #endif
JMF 12:0071cb144c7a 31
JMF 12:0071cb144c7a 32 #if !defined(MBEDTLS_TIMING_ALT)
JMF 12:0071cb144c7a 33 // Regular implementation
JMF 12:0071cb144c7a 34 //
JMF 12:0071cb144c7a 35
JMF 12:0071cb144c7a 36 #include <stdint.h>
JMF 12:0071cb144c7a 37
JMF 12:0071cb144c7a 38 #ifdef __cplusplus
JMF 12:0071cb144c7a 39 extern "C" {
JMF 12:0071cb144c7a 40 #endif
JMF 12:0071cb144c7a 41
JMF 12:0071cb144c7a 42 /**
JMF 12:0071cb144c7a 43 * \brief timer structure
JMF 12:0071cb144c7a 44 */
JMF 12:0071cb144c7a 45 struct mbedtls_timing_hr_time
JMF 12:0071cb144c7a 46 {
JMF 12:0071cb144c7a 47 unsigned char opaque[32];
JMF 12:0071cb144c7a 48 };
JMF 12:0071cb144c7a 49
JMF 12:0071cb144c7a 50 /**
JMF 12:0071cb144c7a 51 * \brief Context for mbedtls_timing_set/get_delay()
JMF 12:0071cb144c7a 52 */
JMF 12:0071cb144c7a 53 typedef struct
JMF 12:0071cb144c7a 54 {
JMF 12:0071cb144c7a 55 struct mbedtls_timing_hr_time timer;
JMF 12:0071cb144c7a 56 uint32_t int_ms;
JMF 12:0071cb144c7a 57 uint32_t fin_ms;
JMF 12:0071cb144c7a 58 } mbedtls_timing_delay_context;
JMF 12:0071cb144c7a 59
JMF 12:0071cb144c7a 60 extern volatile int mbedtls_timing_alarmed;
JMF 12:0071cb144c7a 61
JMF 12:0071cb144c7a 62 /**
JMF 12:0071cb144c7a 63 * \brief Return the CPU cycle counter value
JMF 12:0071cb144c7a 64 *
JMF 12:0071cb144c7a 65 * \warning This is only a best effort! Do not rely on this!
JMF 12:0071cb144c7a 66 * In particular, it is known to be unreliable on virtual
JMF 12:0071cb144c7a 67 * machines.
JMF 12:0071cb144c7a 68 */
JMF 12:0071cb144c7a 69 unsigned long mbedtls_timing_hardclock( void );
JMF 12:0071cb144c7a 70
JMF 12:0071cb144c7a 71 /**
JMF 12:0071cb144c7a 72 * \brief Return the elapsed time in milliseconds
JMF 12:0071cb144c7a 73 *
JMF 12:0071cb144c7a 74 * \param val points to a timer structure
JMF 12:0071cb144c7a 75 * \param reset if set to 1, the timer is restarted
JMF 12:0071cb144c7a 76 */
JMF 12:0071cb144c7a 77 unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset );
JMF 12:0071cb144c7a 78
JMF 12:0071cb144c7a 79 /**
JMF 12:0071cb144c7a 80 * \brief Setup an alarm clock
JMF 12:0071cb144c7a 81 *
JMF 12:0071cb144c7a 82 * \param seconds delay before the "mbedtls_timing_alarmed" flag is set
JMF 12:0071cb144c7a 83 *
JMF 12:0071cb144c7a 84 * \warning Only one alarm at a time is supported. In a threaded
JMF 12:0071cb144c7a 85 * context, this means one for the whole process, not one per
JMF 12:0071cb144c7a 86 * thread.
JMF 12:0071cb144c7a 87 */
JMF 12:0071cb144c7a 88 void mbedtls_set_alarm( int seconds );
JMF 12:0071cb144c7a 89
JMF 12:0071cb144c7a 90 /**
JMF 12:0071cb144c7a 91 * \brief Set a pair of delays to watch
JMF 12:0071cb144c7a 92 * (See \c mbedtls_timing_get_delay().)
JMF 12:0071cb144c7a 93 *
JMF 12:0071cb144c7a 94 * \param data Pointer to timing data
JMF 12:0071cb144c7a 95 * Must point to a valid \c mbedtls_timing_delay_context struct.
JMF 12:0071cb144c7a 96 * \param int_ms First (intermediate) delay in milliseconds.
JMF 12:0071cb144c7a 97 * \param fin_ms Second (final) delay in milliseconds.
JMF 12:0071cb144c7a 98 * Pass 0 to cancel the current delay.
JMF 12:0071cb144c7a 99 */
JMF 12:0071cb144c7a 100 void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms );
JMF 12:0071cb144c7a 101
JMF 12:0071cb144c7a 102 /**
JMF 12:0071cb144c7a 103 * \brief Get the status of delays
JMF 12:0071cb144c7a 104 * (Memory helper: number of delays passed.)
JMF 12:0071cb144c7a 105 *
JMF 12:0071cb144c7a 106 * \param data Pointer to timing data
JMF 12:0071cb144c7a 107 * Must point to a valid \c mbedtls_timing_delay_context struct.
JMF 12:0071cb144c7a 108 *
JMF 12:0071cb144c7a 109 * \return -1 if cancelled (fin_ms = 0)
JMF 12:0071cb144c7a 110 * 0 if none of the delays are passed,
JMF 12:0071cb144c7a 111 * 1 if only the intermediate delay is passed,
JMF 12:0071cb144c7a 112 * 2 if the final delay is passed.
JMF 12:0071cb144c7a 113 */
JMF 12:0071cb144c7a 114 int mbedtls_timing_get_delay( void *data );
JMF 12:0071cb144c7a 115
JMF 12:0071cb144c7a 116 #ifdef __cplusplus
JMF 12:0071cb144c7a 117 }
JMF 12:0071cb144c7a 118 #endif
JMF 12:0071cb144c7a 119
JMF 12:0071cb144c7a 120 #else /* MBEDTLS_TIMING_ALT */
JMF 12:0071cb144c7a 121 #include "timing_alt.h"
JMF 12:0071cb144c7a 122 #endif /* MBEDTLS_TIMING_ALT */
JMF 12:0071cb144c7a 123
JMF 12:0071cb144c7a 124 #ifdef __cplusplus
JMF 12:0071cb144c7a 125 extern "C" {
JMF 12:0071cb144c7a 126 #endif
JMF 12:0071cb144c7a 127
JMF 12:0071cb144c7a 128 #if defined(MBEDTLS_SELF_TEST)
JMF 12:0071cb144c7a 129 /**
JMF 12:0071cb144c7a 130 * \brief Checkup routine
JMF 12:0071cb144c7a 131 *
JMF 12:0071cb144c7a 132 * \return 0 if successful, or 1 if a test failed
JMF 12:0071cb144c7a 133 */
JMF 12:0071cb144c7a 134 int mbedtls_timing_self_test( int verbose );
JMF 12:0071cb144c7a 135 #endif
JMF 12:0071cb144c7a 136
JMF 12:0071cb144c7a 137 #ifdef __cplusplus
JMF 12:0071cb144c7a 138 }
JMF 12:0071cb144c7a 139 #endif
JMF 12:0071cb144c7a 140
JMF 12:0071cb144c7a 141 #endif /* timing.h */