blob: d05c3c77a2a035d8777df2e9891854a866ffc76a [file] [log] [blame]
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -05001/**
2 * \file platform_util.h
3 *
4 * \brief Common and shared functions used by multiple modules in the Mbed TLS
5 * library.
6 */
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
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +010028#if !defined(MBEDTLS_CONFIG_FILE)
GuHaijun983acb72018-12-28 11:11:10 +080029#include "config.h"
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +010030#else
31#include MBEDTLS_CONFIG_FILE
32#endif
Arto Kinnunenee9bfca2019-09-06 16:59:00 +030033#include <stdint.h>
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -050034#include <stddef.h>
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +010035#if defined(MBEDTLS_HAVE_TIME_DATE)
GuHaijun983acb72018-12-28 11:11:10 +080036#include "platform_time.h"
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +010037#include <time.h>
38#endif /* MBEDTLS_HAVE_TIME_DATE */
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -050039
40#ifdef __cplusplus
41extern "C" {
42#endif
43
Manuel Pégourié-Gonnard9b8ea892018-12-11 10:56:56 +010044#if defined(MBEDTLS_CHECK_PARAMS)
Manuel Pégourié-Gonnarda2b0e272018-12-10 15:23:58 +010045
Gilles Peskine30346f62019-06-13 16:44:19 +020046#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
Manuel Pégourié-Gonnarda2b0e272018-12-10 15:23:58 +010052#if defined(MBEDTLS_PARAM_FAILED)
53/** An alternative definition of MBEDTLS_PARAM_FAILED has been set in config.h.
54 *
55 * This flag can be used to check whether it is safe to assume that
56 * MBEDTLS_PARAM_FAILED() will expand to a call to mbedtls_param_failed().
57 */
58#define MBEDTLS_PARAM_FAILED_ALT
Gilles Peskine30346f62019-06-13 16:44:19 +020059
60#elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
61#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
62#define MBEDTLS_PARAM_FAILED_ALT
63
Manuel Pégourié-Gonnard9b8ea892018-12-11 10:56:56 +010064#else /* MBEDTLS_PARAM_FAILED */
Manuel Pégourié-Gonnard8e661bf2018-12-10 12:41:46 +010065#define MBEDTLS_PARAM_FAILED( cond ) \
Manuel Pégourié-Gonnardab588522018-12-10 16:04:46 +010066 mbedtls_param_failed( #cond, __FILE__, __LINE__ )
Simon Butcherb4868032018-12-06 17:36:34 +000067
68/**
69 * \brief User supplied callback function for parameter validation failure.
Manuel Pégourié-Gonnard35acb092018-12-11 12:26:49 +010070 * See #MBEDTLS_CHECK_PARAMS for context.
Simon Butcherb4868032018-12-06 17:36:34 +000071 *
Manuel Pégourié-Gonnardab588522018-12-10 16:04:46 +010072 * This function will be called unless an alternative treatement
Manuel Pégourié-Gonnard35acb092018-12-11 12:26:49 +010073 * is defined through the #MBEDTLS_PARAM_FAILED macro.
Simon Butcherb4868032018-12-06 17:36:34 +000074 *
75 * This function can return, and the operation will be aborted, or
76 * alternatively, through use of setjmp()/longjmp() can resume
77 * execution in the application code.
Manuel Pégourié-Gonnardab588522018-12-10 16:04:46 +010078 *
79 * \param failure_condition The assertion that didn't hold.
80 * \param file The file where the assertion failed.
81 * \param line The line in the file where the assertion failed.
Simon Butcherb4868032018-12-06 17:36:34 +000082 */
Manuel Pégourié-Gonnardab588522018-12-10 16:04:46 +010083void mbedtls_param_failed( const char *failure_condition,
84 const char *file,
Manuel Pégourié-Gonnard3ef6a6d2018-12-10 14:31:45 +010085 int line );
Manuel Pégourié-Gonnarda2b0e272018-12-10 15:23:58 +010086#endif /* MBEDTLS_PARAM_FAILED */
Manuel Pégourié-Gonnard0e9cddb2018-12-10 16:37:51 +010087
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 { \
Manuel Pégourié-Gonnard0e17cc92018-12-11 09:26:54 +010093 MBEDTLS_PARAM_FAILED( cond ); \
Manuel Pégourié-Gonnard0e9cddb2018-12-10 16:37:51 +010094 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 { \
Manuel Pégourié-Gonnard0e17cc92018-12-11 09:26:54 +0100103 MBEDTLS_PARAM_FAILED( cond ); \
Manuel Pégourié-Gonnard0e9cddb2018-12-10 16:37:51 +0100104 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
Manuel Pégourié-Gonnarda2b0e272018-12-10 15:23:58 +0100114#endif /* MBEDTLS_CHECK_PARAMS */
Simon Butcherb4868032018-12-06 17:36:34 +0000115
Hanno Becker7bcf2b52019-07-26 09:02:40 +0100116#if defined(__GNUC__) || defined(__arm__)
117#define MBEDTLS_ALWAYS_INLINE __attribute__((always_inline))
118#else
119#define MBEDTLS_ALWAYS_INLINE
120#endif
121
Hanno Becker6d0816a2018-12-17 11:30:27 +0000122/* Internal helper macros for deprecating API constants. */
123#if !defined(MBEDTLS_DEPRECATED_REMOVED)
124#if defined(MBEDTLS_DEPRECATED_WARNING)
Hanno Becker9dbefa12018-12-17 22:49:13 +0000125/* Deliberately don't (yet) export MBEDTLS_DEPRECATED here
126 * to avoid conflict with other headers which define and use
127 * it, too. We might want to move all these definitions here at
128 * some point for uniformity. */
129#define MBEDTLS_DEPRECATED __attribute__((deprecated))
130MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_string_constant_t;
Hanno Becker6d0816a2018-12-17 11:30:27 +0000131#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \
132 ( (mbedtls_deprecated_string_constant_t) ( VAL ) )
Hanno Becker9dbefa12018-12-17 22:49:13 +0000133MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
Hanno Becker6d0816a2018-12-17 11:30:27 +0000134#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) \
135 ( (mbedtls_deprecated_numeric_constant_t) ( VAL ) )
Hanno Becker9dbefa12018-12-17 22:49:13 +0000136#undef MBEDTLS_DEPRECATED
Hanno Becker6d0816a2018-12-17 11:30:27 +0000137#else /* MBEDTLS_DEPRECATED_WARNING */
138#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL
139#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) VAL
140#endif /* MBEDTLS_DEPRECATED_WARNING */
141#endif /* MBEDTLS_DEPRECATED_REMOVED */
142
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -0500143/**
144 * \brief Securely zeroize a buffer
145 *
Andres Amaya Garcia56e06db2018-04-24 08:37:52 -0500146 * The function is meant to wipe the data contained in a buffer so
147 * that it can no longer be recovered even if the program memory
148 * is later compromised. Call this function on sensitive data
149 * stored on the stack before returning from a function, and on
150 * sensitive data stored on the heap before freeing the heap
151 * object.
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -0500152 *
Andres Amaya Garcia56e06db2018-04-24 08:37:52 -0500153 * It is extremely difficult to guarantee that calls to
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -0500154 * mbedtls_platform_zeroize() are not removed by aggressive
155 * compiler optimizations in a portable way. For this reason, Mbed
156 * TLS provides the configuration option
157 * MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure
158 * mbedtls_platform_zeroize() to use a suitable implementation for
159 * their platform and needs
Andres Amaya Garcia56e06db2018-04-24 08:37:52 -0500160 *
161 * \param buf Buffer to be zeroized
162 * \param len Length of the buffer in bytes
163 *
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -0500164 */
165void mbedtls_platform_zeroize( void *buf, size_t len );
166
Jarno Lamsa7d281552019-10-01 15:56:17 +0300167/**
168 * \brief Secure memset
169 *
Jarno Lamsac4315e62019-10-04 15:42:39 +0300170 * This is a constant-time version of memset(). If
171 * MBEDTLS_ENTROPY_HARDWARE_ALT is defined, the buffer is
172 * initialised with random data and the order is also
173 * randomised using the hardware RNG in order to further harden
174 * against side-channel attacks.
Jarno Lamsa7d281552019-10-01 15:56:17 +0300175 *
176 * \param ptr Buffer to be set.
177 * \param value Value to be used when setting the buffer.
178 * \param num The length of the buffer in bytes.
Jarno Lamsa0ff71092019-10-02 08:18:29 +0300179 *
Manuel Pégourié-Gonnard51f65e42019-10-02 16:01:14 +0200180 * \return The value of \p ptr.
Jarno Lamsa7d281552019-10-01 15:56:17 +0300181 */
Manuel Pégourié-Gonnard51f65e42019-10-02 16:01:14 +0200182void *mbedtls_platform_memset( void *ptr, int value, size_t num );
Jarno Lamsa07363252019-09-27 16:20:11 +0300183
Jarno Lamsa7d281552019-10-01 15:56:17 +0300184/**
185 * \brief Secure memcpy
186 *
Jarno Lamsac4315e62019-10-04 15:42:39 +0300187 * This is a constant-time version of memcpy(). If
188 * MBEDTLS_ENTROPY_HARDWARE_ALT is defined, the buffer is
189 * initialised with random data and the order is also
190 * randomised using the hardware RNG in order to further harden
191 * against side-channel attacks.
Jarno Lamsa7d281552019-10-01 15:56:17 +0300192 *
193 * \param dst Destination buffer where the data is being copied to.
194 * \param src Source buffer where the data is being copied from.
195 * \param num The length of the buffers in bytes.
196 *
Manuel Pégourié-Gonnard51f65e42019-10-02 16:01:14 +0200197 * \return The value of \p dst.
Jarno Lamsa7d281552019-10-01 15:56:17 +0300198 */
Manuel Pégourié-Gonnard51f65e42019-10-02 16:01:14 +0200199void *mbedtls_platform_memcpy( void *dst, const void *src, size_t num );
Jarno Lamsa07363252019-09-27 16:20:11 +0300200
Jarno Lamsa7d281552019-10-01 15:56:17 +0300201/**
Piotr Nowicki5d5841f2020-06-05 16:33:24 +0200202 * \brief Secure memmove
203 *
204 * This is a constant-time version of memmove(). It is based on
205 * the double use of the mbedtls_platform_memcpy() function secured
206 * against side-channel attacks.
207 *
208 * \param dst Destination buffer where the data is being moved to.
209 * \param src Source buffer where the data is being moved from.
210 * \param num The length of the buffers in bytes.
211 *
212 * \return 0 if the operation was successful or -1 if memory allocation
213 * failed.
214 */
215int mbedtls_platform_memmove( void *dst, const void *src, size_t num );
216
217/**
Jarno Lamsa7d281552019-10-01 15:56:17 +0300218 * \brief Secure memcmp
219 *
Jarno Lamsac4315e62019-10-04 15:42:39 +0300220 * This is a constant-time version of memcmp(). If
221 * MBEDTLS_ENTROPY_HARDWARE_ALT is defined, the order is also
222 * randomised using the hardware RNG in order to further harden
223 * against side-channel attacks.
Jarno Lamsa7d281552019-10-01 15:56:17 +0300224 *
225 * \param buf1 First buffer to compare.
226 * \param buf2 Second buffer to compare against.
227 * \param num The length of the buffers in bytes.
228 *
Jarno Lamsac4315e62019-10-04 15:42:39 +0300229 * \return 0 if the buffers were equal or an unspecified non-zero value
230 * otherwise.
Jarno Lamsa7d281552019-10-01 15:56:17 +0300231 */
Jarno Lamsa07363252019-09-27 16:20:11 +0300232int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num );
233
Jarno Lamsa7d281552019-10-01 15:56:17 +0300234/**
Jarno Lamsa39a9d402019-10-03 13:36:06 +0300235 * \brief RNG-function for getting a random in given range.
Jarno Lamsa7d281552019-10-01 15:56:17 +0300236 *
237 * This function is meant to provide a global RNG to be used
238 * throughout Mbed TLS for hardening the library. It is used
239 * for generating a random delay, random data or random offset
240 * for utility functions. It is not meant to be a
241 * cryptographically secure RNG, but provide an RNG for utility
242 * functions.
243 *
Jarno Lamsa39a9d402019-10-03 13:36:06 +0300244 * \note Currently the function is dependent of hardware providing an
245 * rng with MBEDTLS_ENTROPY_HARDWARE_ALT. By default, 0 is
246 * returned.
247 *
248 * \note If the given range is [0, 0), 0 is returned.
249 *
Jarno Lamsaf5ebe2a2019-10-02 08:23:11 +0300250 * \param num Max-value for the generated random number, exclusive.
251 * The generated number will be on range [0, num).
Jarno Lamsa77a0e072019-10-02 08:39:32 +0300252 *
Jarno Lamsaf5ebe2a2019-10-02 08:23:11 +0300253 * \return The generated random number.
Jarno Lamsaa1e50542019-10-02 12:44:36 +0300254 */
Jarno Lamsaf65e9de2019-10-01 16:09:35 +0300255uint32_t mbedtls_platform_random_in_range( size_t num );
Jarno Lamsa07363252019-09-27 16:20:11 +0300256
Manuel Pégourié-Gonnard72a8c9e2019-11-08 10:21:00 +0100257/**
Arto Kinnunen4c63b982019-12-02 15:01:41 +0200258 * \brief Random delay function.
259 *
Arto Kinnunen9a506e72019-12-09 10:54:03 +0200260 * Function implements a random delay by incrementing a local
261 * variable randomized number of times (busy-looping).
262 *
263 * Duration of the delay is random as number of variable increments
264 * is randomized.
Arto Kinnunen4c63b982019-12-02 15:01:41 +0200265 *
266 * \note Currently the function is dependent of hardware providing an
267 * rng with MBEDTLS_ENTROPY_HARDWARE_ALT.
Arto Kinnunen4c63b982019-12-02 15:01:41 +0200268 */
Arto Kinnunenac6d2262020-01-09 10:11:20 +0200269void mbedtls_platform_random_delay( void );
Arto Kinnunen4c63b982019-12-02 15:01:41 +0200270
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +0100271#if defined(MBEDTLS_HAVE_TIME_DATE)
272/**
Hanno Beckerc52ef402018-09-05 16:28:59 +0100273 * \brief Platform-specific implementation of gmtime_r()
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +0100274 *
Hanno Beckerc52ef402018-09-05 16:28:59 +0100275 * The function is a thread-safe abstraction that behaves
Hanno Becker03b2bd42018-09-06 09:08:55 +0100276 * similarly to the gmtime_r() function from Unix/POSIX.
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +0100277 *
Hanno Becker6a739782018-09-05 15:06:19 +0100278 * Mbed TLS will try to identify the underlying platform and
Hanno Beckerc52ef402018-09-05 16:28:59 +0100279 * make use of an appropriate underlying implementation (e.g.
Hanno Becker6a739782018-09-05 15:06:19 +0100280 * gmtime_r() for POSIX and gmtime_s() for Windows). If this is
281 * not possible, then gmtime() will be used. In this case, calls
282 * from the library to gmtime() will be guarded by the mutex
283 * mbedtls_threading_gmtime_mutex if MBEDTLS_THREADING_C is
284 * enabled. It is recommended that calls from outside the library
285 * are also guarded by this mutex.
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +0100286 *
Hanno Becker6a739782018-09-05 15:06:19 +0100287 * If MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, then Mbed TLS will
288 * unconditionally use the alternative implementation for
289 * mbedtls_platform_gmtime_r() supplied by the user at compile time.
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +0100290 *
Hanno Becker272675f2018-09-05 14:03:02 +0100291 * \param tt Pointer to an object containing time (in seconds) since the
Hanno Becker48a816f2018-09-05 15:22:22 +0100292 * epoch to be converted
Hanno Becker272675f2018-09-05 14:03:02 +0100293 * \param tm_buf Pointer to an object where the results will be stored
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +0100294 *
295 * \return Pointer to an object of type struct tm on success, otherwise
296 * NULL
297 */
Hanno Becker6a739782018-09-05 15:06:19 +0100298struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
299 struct tm *tm_buf );
Andres Amaya Garcia1abb3682018-08-16 21:42:09 +0100300#endif /* MBEDTLS_HAVE_TIME_DATE */
301
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300302/**
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300303 * \brief Convert a 32-bit number to the big endian format and write it to
304 * the given buffer.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300305 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300306 * \param buf Address where the converted number is written.
307 * \param num A number that needs to be converted to the big endian format.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300308 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300309 * \return Address to the end of buffer where the converted number is
310 * written.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300311 */
Arto Kinnunenee9bfca2019-09-06 16:59:00 +0300312unsigned char* mbedtls_platform_put_uint32_be( unsigned char *buf,
Arto Kinnunen4f4849a2019-09-09 10:21:18 +0300313 size_t num );
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300314
315/**
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300316 * \brief Convert a 24-bit number to the big endian format and write it to
317 * the given buffer.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300318 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300319 * \param buf Address where the converted number is written.
320 * \param num A number that needs to be converted to the big endian format.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300321 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300322 * \return Address to the end of buffer where the converted number is
323 * written.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300324 */
Arto Kinnunenee9bfca2019-09-06 16:59:00 +0300325unsigned char* mbedtls_platform_put_uint24_be( unsigned char *buf,
Arto Kinnunen4f4849a2019-09-09 10:21:18 +0300326 size_t num );
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300327
328/**
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300329 * \brief Convert a 16-bit number to the big endian format and write it to
330 * the given buffer.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300331 *
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300332 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300333 * \param buf Address where the converted number is written.
334 * \param num A number that needs to be converted to the big endian format.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300335 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300336 * \return Address to the end of buffer where the converted number is
337 * written.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300338 */
Arto Kinnunenee9bfca2019-09-06 16:59:00 +0300339unsigned char* mbedtls_platform_put_uint16_be( unsigned char *buf,
Arto Kinnunen4f4849a2019-09-09 10:21:18 +0300340 size_t num );
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300341
342/**
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300343 * \brief Convert a 32-bit number from the big endian format.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300344 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300345 * The function reads a 32-bit number from the given buffer in the
346 * big endian format and returns it to the caller.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300347 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300348 * \param buf Buffer where the 32-bit number locates.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300349 *
350 * \return Converted number.
351 */
Arto Kinnunen4f4849a2019-09-09 10:21:18 +0300352size_t mbedtls_platform_get_uint32_be( const unsigned char *buf );
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300353
354/**
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300355 * \brief Convert a 24-bit number from the big endian format.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300356 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300357 * The function reads a 14-bit number from the given buffer in the
358 * big endian format and returns it to the caller.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300359 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300360 * \param buf Buffer where the 24-bit number locates.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300361 *
362 * \return Converted number.
363 */
Arto Kinnunen4f4849a2019-09-09 10:21:18 +0300364size_t mbedtls_platform_get_uint24_be( const unsigned char *buf );
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300365
366/**
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300367 * \brief Convert a 16-bit number from the big endian format.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300368 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300369 * The function reads a 16-bit number from the given buffer in the
370 * big endian format and returns it to the caller.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300371 *
Arto Kinnunen9b3b1942019-09-09 17:02:35 +0300372 * \param buf Buffer where the 16-bit number locates.
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300373 *
374 * \return Converted number.
375 */
Arto Kinnunen4f4849a2019-09-09 10:21:18 +0300376size_t mbedtls_platform_get_uint16_be( const unsigned char *buf );
Arto Kinnunen0b62ce82019-09-04 14:04:57 +0300377
Andres Amaya Garcia904e1ef2018-04-17 09:16:30 -0500378#ifdef __cplusplus
379}
380#endif
381
382#endif /* MBEDTLS_PLATFORM_UTIL_H */