mbed TLS v2.16.7
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: Apache-2.0 OR GPL-2.0-or-later
10  *
11  * This file is provided under the Apache License 2.0, or the
12  * GNU General Public License v2.0 or later.
13  *
14  * **********
15  * Apache License 2.0:
16  *
17  * Licensed under the Apache License, Version 2.0 (the "License"); you may
18  * not use this file except in compliance with the License.
19  * You may obtain a copy of the License at
20  *
21  * http://www.apache.org/licenses/LICENSE-2.0
22  *
23  * Unless required by applicable law or agreed to in writing, software
24  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  * See the License for the specific language governing permissions and
27  * limitations under the License.
28  *
29  * **********
30  *
31  * **********
32  * GNU General Public License v2.0 or later:
33  *
34  * This program is free software; you can redistribute it and/or modify
35  * it under the terms of the GNU General Public License as published by
36  * the Free Software Foundation; either version 2 of the License, or
37  * (at your option) any later version.
38  *
39  * This program is distributed in the hope that it will be useful,
40  * but WITHOUT ANY WARRANTY; without even the implied warranty of
41  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42  * GNU General Public License for more details.
43  *
44  * You should have received a copy of the GNU General Public License along
45  * with this program; if not, write to the Free Software Foundation, Inc.,
46  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
47  *
48  * **********
49  *
50  * This file is part of Mbed TLS (https://tls.mbed.org)
51  */
52 #ifndef MBEDTLS_PLATFORM_UTIL_H
53 #define MBEDTLS_PLATFORM_UTIL_H
54 
55 #if !defined(MBEDTLS_CONFIG_FILE)
56 #include "config.h"
57 #else
58 #include MBEDTLS_CONFIG_FILE
59 #endif
60 
61 #include <stddef.h>
62 #if defined(MBEDTLS_HAVE_TIME_DATE)
63 #include "platform_time.h"
64 #include <time.h>
65 #endif /* MBEDTLS_HAVE_TIME_DATE */
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 #if defined(MBEDTLS_CHECK_PARAMS)
72 
73 #if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
74 /* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
75  * (which is what our config.h suggests). */
76 #include <assert.h>
77 #endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
78 
79 #if defined(MBEDTLS_PARAM_FAILED)
80 
85 #define MBEDTLS_PARAM_FAILED_ALT
86 
87 #elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
88 #define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
89 #define MBEDTLS_PARAM_FAILED_ALT
90 
91 #else /* MBEDTLS_PARAM_FAILED */
92 #define MBEDTLS_PARAM_FAILED( cond ) \
93  mbedtls_param_failed( #cond, __FILE__, __LINE__ )
94 
110 void mbedtls_param_failed( const char *failure_condition,
111  const char *file,
112  int line );
113 #endif /* MBEDTLS_PARAM_FAILED */
114 
115 /* Internal macro meant to be called only from within the library. */
116 #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
117  do { \
118  if( !(cond) ) \
119  { \
120  MBEDTLS_PARAM_FAILED( cond ); \
121  return( ret ); \
122  } \
123  } while( 0 )
124 
125 /* Internal macro meant to be called only from within the library. */
126 #define MBEDTLS_INTERNAL_VALIDATE( cond ) \
127  do { \
128  if( !(cond) ) \
129  { \
130  MBEDTLS_PARAM_FAILED( cond ); \
131  return; \
132  } \
133  } while( 0 )
134 
135 #else /* MBEDTLS_CHECK_PARAMS */
136 
137 /* Internal macros meant to be called only from within the library. */
138 #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
139 #define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
140 
141 #endif /* MBEDTLS_CHECK_PARAMS */
142 
143 /* Internal helper macros for deprecating API constants. */
144 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
145 #if defined(MBEDTLS_DEPRECATED_WARNING)
146 /* Deliberately don't (yet) export MBEDTLS_DEPRECATED here
147  * to avoid conflict with other headers which define and use
148  * it, too. We might want to move all these definitions here at
149  * some point for uniformity. */
150 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
151 MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_string_constant_t;
152 #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \
153  ( (mbedtls_deprecated_string_constant_t) ( VAL ) )
154 MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
155 #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) \
156  ( (mbedtls_deprecated_numeric_constant_t) ( VAL ) )
157 #undef MBEDTLS_DEPRECATED
158 #else /* MBEDTLS_DEPRECATED_WARNING */
159 #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL
160 #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) VAL
161 #endif /* MBEDTLS_DEPRECATED_WARNING */
162 #endif /* MBEDTLS_DEPRECATED_REMOVED */
163 
186 void mbedtls_platform_zeroize( void *buf, size_t len );
187 
188 #if defined(MBEDTLS_HAVE_TIME_DATE)
189 
216  struct tm *tm_buf );
217 #endif /* MBEDTLS_HAVE_TIME_DATE */
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 #endif /* MBEDTLS_PLATFORM_UTIL_H */
mbedtls_platform_gmtime_r
struct tm * mbedtls_platform_gmtime_r(const mbedtls_time_t *tt, struct tm *tm_buf)
Platform-specific implementation of gmtime_r()
mbedtls_time_t
time_t mbedtls_time_t
Definition: platform_time.h:80
platform_time.h
mbed TLS Platform time abstraction
mbedtls_platform_zeroize
void mbedtls_platform_zeroize(void *buf, size_t len)
Securely zeroize a buffer.
config.h
Configuration options (set of defines)
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: aes.h:653