mbed TLS v2.16.6
platform_util.h
Go to the documentation of this file.
1 
7 /*
8  * Copyright (C) 2018, Arm Limited, All Rights Reserved
9  * SPDX-License-Identifier: GPL-2.0
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * This file is part of Mbed TLS (https://tls.mbed.org)
26  */
27 #ifndef MBEDTLS_PLATFORM_UTIL_H
28 #define MBEDTLS_PLATFORM_UTIL_H
29 
30 #if !defined(MBEDTLS_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include MBEDTLS_CONFIG_FILE
34 #endif
35 
36 #include <stddef.h>
37 #if defined(MBEDTLS_HAVE_TIME_DATE)
38 #include "platform_time.h"
39 #include <time.h>
40 #endif /* MBEDTLS_HAVE_TIME_DATE */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #if defined(MBEDTLS_CHECK_PARAMS)
47 
48 #if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
49 /* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
50  * (which is what our config.h suggests). */
51 #include <assert.h>
52 #endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
53 
54 #if defined(MBEDTLS_PARAM_FAILED)
55 
60 #define MBEDTLS_PARAM_FAILED_ALT
61 
62 #elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
63 #define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
64 #define MBEDTLS_PARAM_FAILED_ALT
65 
66 #else /* MBEDTLS_PARAM_FAILED */
67 #define MBEDTLS_PARAM_FAILED( cond ) \
68  mbedtls_param_failed( #cond, __FILE__, __LINE__ )
69 
85 void mbedtls_param_failed( const char *failure_condition,
86  const char *file,
87  int line );
88 #endif /* MBEDTLS_PARAM_FAILED */
89 
90 /* Internal macro meant to be called only from within the library. */
91 #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
92  do { \
93  if( !(cond) ) \
94  { \
95  MBEDTLS_PARAM_FAILED( cond ); \
96  return( ret ); \
97  } \
98  } while( 0 )
99 
100 /* Internal macro meant to be called only from within the library. */
101 #define MBEDTLS_INTERNAL_VALIDATE( cond ) \
102  do { \
103  if( !(cond) ) \
104  { \
105  MBEDTLS_PARAM_FAILED( cond ); \
106  return; \
107  } \
108  } while( 0 )
109 
110 #else /* MBEDTLS_CHECK_PARAMS */
111 
112 /* Internal macros meant to be called only from within the library. */
113 #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
114 #define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
115 
116 #endif /* MBEDTLS_CHECK_PARAMS */
117 
118 /* Internal helper macros for deprecating API constants. */
119 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
120 #if defined(MBEDTLS_DEPRECATED_WARNING)
121 /* Deliberately don't (yet) export MBEDTLS_DEPRECATED here
122  * to avoid conflict with other headers which define and use
123  * it, too. We might want to move all these definitions here at
124  * some point for uniformity. */
125 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
126 MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_string_constant_t;
127 #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \
128  ( (mbedtls_deprecated_string_constant_t) ( VAL ) )
129 MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
130 #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) \
131  ( (mbedtls_deprecated_numeric_constant_t) ( VAL ) )
132 #undef MBEDTLS_DEPRECATED
133 #else /* MBEDTLS_DEPRECATED_WARNING */
134 #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL
135 #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) VAL
136 #endif /* MBEDTLS_DEPRECATED_WARNING */
137 #endif /* MBEDTLS_DEPRECATED_REMOVED */
138 
161 void mbedtls_platform_zeroize( void *buf, size_t len );
162 
163 #if defined(MBEDTLS_HAVE_TIME_DATE)
164 
190 struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
191  struct tm *tm_buf );
192 #endif /* MBEDTLS_HAVE_TIME_DATE */
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 #endif /* MBEDTLS_PLATFORM_UTIL_H */
#define MBEDTLS_DEPRECATED
Definition: aes.h:627
Configuration options (set of defines)
void mbedtls_platform_zeroize(void *buf, size_t len)
Securely zeroize a buffer.
time_t mbedtls_time_t
Definition: platform_time.h:55
struct tm * mbedtls_platform_gmtime_r(const mbedtls_time_t *tt, struct tm *tm_buf)
Platform-specific implementation of gmtime_r()
mbed TLS Platform time abstraction