Digi XBee(R) ANSI C Host Library
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
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License"); you may
12  * not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * This file is part of Mbed TLS (https://tls.mbed.org)
24  */
25 #ifndef MBEDTLS_PLATFORM_UTIL_H
26 #define MBEDTLS_PLATFORM_UTIL_H
27 
28 #if !defined(MBEDTLS_CONFIG_FILE)
29 #include "mbedtls/config.h"
30 #else
31 #include MBEDTLS_CONFIG_FILE
32 #endif
33 
34 #include <stddef.h>
35 #if defined(MBEDTLS_HAVE_TIME_DATE)
36 #include "mbedtls/platform_time.h"
37 #include <time.h>
38 #endif /* MBEDTLS_HAVE_TIME_DATE */
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #if defined(MBEDTLS_CHECK_PARAMS)
45 
46 #if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
47 /* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
48  * (which is what our config.h suggests). */
49 #include <assert.h>
50 #endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
51 
52 #if defined(MBEDTLS_PARAM_FAILED)
53 
58 #define MBEDTLS_PARAM_FAILED_ALT
59 
60 #elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
61 #define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
62 #define MBEDTLS_PARAM_FAILED_ALT
63 
64 #else /* MBEDTLS_PARAM_FAILED */
65 #define MBEDTLS_PARAM_FAILED( cond ) \
66  mbedtls_param_failed( #cond, __FILE__, __LINE__ )
67 
83 void mbedtls_param_failed( const char *failure_condition,
84  const char *file,
85  int line );
86 #endif /* MBEDTLS_PARAM_FAILED */
87 
88 /* Internal macro meant to be called only from within the library. */
89 #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
90  do { \
91  if( !(cond) ) \
92  { \
93  MBEDTLS_PARAM_FAILED( cond ); \
94  return( ret ); \
95  } \
96  } while( 0 )
97 
98 /* Internal macro meant to be called only from within the library. */
99 #define MBEDTLS_INTERNAL_VALIDATE( cond ) \
100  do { \
101  if( !(cond) ) \
102  { \
103  MBEDTLS_PARAM_FAILED( cond ); \
104  return; \
105  } \
106  } while( 0 )
107 
108 #else /* MBEDTLS_CHECK_PARAMS */
109 
110 /* Internal macros meant to be called only from within the library. */
111 #define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
112 #define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
113 
114 #endif /* MBEDTLS_CHECK_PARAMS */
115 
116 /* Internal helper macros for deprecating API constants. */
117 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
118 #if defined(MBEDTLS_DEPRECATED_WARNING)
119 /* Deliberately don't (yet) export MBEDTLS_DEPRECATED here
120  * to avoid conflict with other headers which define and use
121  * it, too. We might want to move all these definitions here at
122  * some point for uniformity. */
123 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
124 MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_string_constant_t;
125 #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \
126  ( (mbedtls_deprecated_string_constant_t) ( VAL ) )
127 MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
128 #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) \
129  ( (mbedtls_deprecated_numeric_constant_t) ( VAL ) )
130 #undef MBEDTLS_DEPRECATED
131 #else /* MBEDTLS_DEPRECATED_WARNING */
132 #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL
133 #define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) VAL
134 #endif /* MBEDTLS_DEPRECATED_WARNING */
135 #endif /* MBEDTLS_DEPRECATED_REMOVED */
136 
159 void mbedtls_platform_zeroize( void *buf, size_t len );
160 
161 #if defined(MBEDTLS_HAVE_TIME_DATE)
162 
188 struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
189  struct tm *tm_buf );
190 #endif /* MBEDTLS_HAVE_TIME_DATE */
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* MBEDTLS_PLATFORM_UTIL_H */
void mbedtls_platform_zeroize(void *buf, size_t len)
Securely zeroize a buffer.
Definition: mbedtls_util.c:75