mbed TLS Build

Dependents:   Slave-prot-prod

Committer:
williequesada
Date:
Tue Jun 04 16:03:38 2019 +0000
Revision:
1:1a219dea6cb5
Parent:
0:cdf462088d13
compartir a Pablo

Who changed what in which revision?

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