2019-09-11 13:39:11 +02:00
|
|
|
/**
|
|
|
|
* \file common.h
|
|
|
|
*
|
|
|
|
* \brief Utility macros for internal use in the library
|
|
|
|
*/
|
|
|
|
/*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2019-09-11 13:39:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MBEDTLS_LIBRARY_COMMON_H
|
|
|
|
#define MBEDTLS_LIBRARY_COMMON_H
|
|
|
|
|
2021-05-27 11:25:03 +02:00
|
|
|
#include "mbedtls/build_info.h"
|
2019-09-11 13:39:11 +02:00
|
|
|
|
2021-07-14 13:31:31 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-09-11 13:39:11 +02:00
|
|
|
/** Helper to define a function as static except when building invasive tests.
|
|
|
|
*
|
|
|
|
* If a function is only used inside its own source file and should be
|
|
|
|
* declared `static` to allow the compiler to optimize for code size,
|
|
|
|
* but that function has unit tests, define it with
|
|
|
|
* ```
|
|
|
|
* MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... }
|
|
|
|
* ```
|
|
|
|
* and declare it in a header in the `library/` directory with
|
|
|
|
* ```
|
|
|
|
* #if defined(MBEDTLS_TEST_HOOKS)
|
|
|
|
* int mbedtls_foo(...);
|
|
|
|
* #endif
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
#if defined(MBEDTLS_TEST_HOOKS)
|
|
|
|
#define MBEDTLS_STATIC_TESTABLE
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_STATIC_TESTABLE static
|
|
|
|
#endif
|
|
|
|
|
2021-07-07 17:29:43 +02:00
|
|
|
#if defined(MBEDTLS_TEST_HOOKS)
|
|
|
|
extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file );
|
|
|
|
#define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST ) \
|
|
|
|
do { \
|
|
|
|
if( ( ! ( TEST ) ) && ( ( *mbedtls_test_hook_test_fail ) != NULL ) ) \
|
|
|
|
{ \
|
|
|
|
( *mbedtls_test_hook_test_fail )( #TEST, __LINE__, __FILE__ ); \
|
|
|
|
} \
|
|
|
|
} while( 0 )
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST )
|
|
|
|
#endif /* defined(MBEDTLS_TEST_HOOKS) */
|
|
|
|
|
2021-05-27 14:39:53 +02:00
|
|
|
/** Allow library to access its structs' private members.
|
2021-05-14 22:20:10 +02:00
|
|
|
*
|
|
|
|
* Although structs defined in header files are publicly available,
|
|
|
|
* their members are private and should not be accessed by the user.
|
|
|
|
*/
|
|
|
|
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
|
|
|
|
2021-06-22 16:51:53 +02:00
|
|
|
/** Byte Reading Macros
|
2021-06-24 10:06:23 +02:00
|
|
|
*
|
2021-07-21 17:35:48 +02:00
|
|
|
* Given a multi-byte integer \p x, MBEDTLS_BYTE_n retrieves the n-th
|
2021-07-21 16:22:47 +02:00
|
|
|
* byte from x, where byte 0 is the least significant byte.
|
2021-06-22 16:51:53 +02:00
|
|
|
*/
|
2021-07-14 13:31:31 +02:00
|
|
|
#define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) )
|
2021-06-24 14:00:03 +02:00
|
|
|
#define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) )
|
|
|
|
#define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) )
|
|
|
|
#define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
|
2021-07-14 13:31:31 +02:00
|
|
|
#define MBEDTLS_BYTE_4( x ) ( (uint8_t) ( ( ( x ) >> 32 ) & 0xff ) )
|
|
|
|
#define MBEDTLS_BYTE_5( x ) ( (uint8_t) ( ( ( x ) >> 40 ) & 0xff ) )
|
|
|
|
#define MBEDTLS_BYTE_6( x ) ( (uint8_t) ( ( ( x ) >> 48 ) & 0xff ) )
|
|
|
|
#define MBEDTLS_BYTE_7( x ) ( (uint8_t) ( ( ( x ) >> 56 ) & 0xff ) )
|
2021-07-08 15:59:52 +02:00
|
|
|
|
2021-07-07 16:16:56 +02:00
|
|
|
/**
|
2021-07-13 13:13:19 +02:00
|
|
|
* Get the unsigned 32 bits integer corresponding to four bytes in
|
2021-07-14 12:53:07 +02:00
|
|
|
* big-endian order (MSB first).
|
2021-07-07 17:56:29 +02:00
|
|
|
*
|
2021-07-14 12:53:07 +02:00
|
|
|
* \param data Base address of the memory to get the four bytes from.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data of the first and most significant
|
2021-07-13 13:13:19 +02:00
|
|
|
* byte of the four bytes to build the 32 bits unsigned
|
2021-07-14 12:53:07 +02:00
|
|
|
* integer from.
|
2021-07-07 17:56:29 +02:00
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_GET_UINT32_BE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_GET_UINT32_BE( data , offset ) \
|
|
|
|
( \
|
|
|
|
( (uint32_t) ( data )[( offset ) ] << 24 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 1] << 16 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 2] << 8 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 3] ) \
|
2021-07-07 17:56:29 +02:00
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2021-07-14 12:53:07 +02:00
|
|
|
* Put in memory a 32 bits unsigned integer in big-endian order.
|
2021-07-07 17:56:29 +02:00
|
|
|
*
|
2021-07-13 13:13:19 +02:00
|
|
|
* \param n 32 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 32
|
2021-07-14 12:53:07 +02:00
|
|
|
* bits unsigned integer in.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data where to put the most significant
|
2021-07-14 12:53:07 +02:00
|
|
|
* byte of the 32 bits unsigned integer \p n.
|
2021-07-07 16:16:56 +02:00
|
|
|
*/
|
2021-06-24 14:00:03 +02:00
|
|
|
#ifndef MBEDTLS_PUT_UINT32_BE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_PUT_UINT32_BE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_3( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_2( n ); \
|
|
|
|
( data )[( offset ) + 2] = MBEDTLS_BYTE_1( n ); \
|
|
|
|
( data )[( offset ) + 3] = MBEDTLS_BYTE_0( n ); \
|
|
|
|
}
|
2021-06-23 12:49:03 +02:00
|
|
|
#endif
|
|
|
|
|
2021-07-07 16:16:56 +02:00
|
|
|
/**
|
2021-07-13 13:13:19 +02:00
|
|
|
* Get the unsigned 32 bits integer corresponding to four bytes in
|
2021-07-14 12:53:07 +02:00
|
|
|
* little-endian order (LSB first).
|
2021-07-07 17:56:29 +02:00
|
|
|
*
|
2021-07-14 12:53:07 +02:00
|
|
|
* \param data Base address of the memory to get the four bytes from.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data of the first and least significant
|
2021-07-13 13:13:19 +02:00
|
|
|
* byte of the four bytes to build the 32 bits unsigned
|
2021-07-14 12:53:07 +02:00
|
|
|
* integer from.
|
2021-06-23 13:16:47 +02:00
|
|
|
*/
|
2021-06-24 14:00:03 +02:00
|
|
|
#ifndef MBEDTLS_GET_UINT32_LE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_GET_UINT32_LE( data, offset ) \
|
|
|
|
( \
|
|
|
|
( (uint32_t) ( data )[( offset ) ] ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 3] << 24 ) \
|
2021-07-07 17:56:29 +02:00
|
|
|
)
|
2021-06-23 13:16:47 +02:00
|
|
|
#endif
|
|
|
|
|
2021-07-07 17:56:29 +02:00
|
|
|
/**
|
2021-07-14 12:53:07 +02:00
|
|
|
* Put in memory a 32 bits unsigned integer in little-endian order.
|
2021-07-07 17:56:29 +02:00
|
|
|
*
|
2021-07-13 13:13:19 +02:00
|
|
|
* \param n 32 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 32
|
2021-07-14 12:53:07 +02:00
|
|
|
* bits unsigned integer in.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data where to put the least significant
|
2021-07-14 12:53:07 +02:00
|
|
|
* byte of the 32 bits unsigned integer \p n.
|
2021-07-07 17:56:29 +02:00
|
|
|
*/
|
2021-06-24 14:00:03 +02:00
|
|
|
#ifndef MBEDTLS_PUT_UINT32_LE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_PUT_UINT32_LE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
|
|
|
|
( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \
|
|
|
|
( data )[( offset ) + 3] = MBEDTLS_BYTE_3( n ); \
|
|
|
|
}
|
2021-06-23 13:16:47 +02:00
|
|
|
#endif
|
|
|
|
|
2021-06-24 10:06:23 +02:00
|
|
|
/**
|
2021-07-14 13:05:51 +02:00
|
|
|
* Get the unsigned 16 bits integer corresponding to two bytes in
|
2021-07-14 12:53:07 +02:00
|
|
|
* little-endian order (LSB first).
|
2021-07-07 17:56:29 +02:00
|
|
|
*
|
2021-07-14 13:05:51 +02:00
|
|
|
* \param data Base address of the memory to get the two bytes from.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data of the first and least significant
|
2021-07-14 13:05:51 +02:00
|
|
|
* byte of the two bytes to build the 16 bits unsigned
|
2021-07-14 12:53:07 +02:00
|
|
|
* integer from.
|
2021-06-23 12:23:44 +02:00
|
|
|
*/
|
2021-07-07 17:56:29 +02:00
|
|
|
#ifndef MBEDTLS_GET_UINT16_LE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_GET_UINT16_LE( data, offset ) \
|
|
|
|
( \
|
|
|
|
( (uint16_t) ( data )[( offset ) ] ) \
|
|
|
|
| ( (uint16_t) ( data )[( offset ) + 1] << 8 ) \
|
2021-06-23 12:23:44 +02:00
|
|
|
)
|
2021-07-07 17:56:29 +02:00
|
|
|
#endif
|
2021-06-23 12:23:44 +02:00
|
|
|
|
2021-07-07 16:16:56 +02:00
|
|
|
/**
|
2021-07-14 12:53:07 +02:00
|
|
|
* Put in memory a 16 bits unsigned integer in little-endian order.
|
2021-07-07 17:56:29 +02:00
|
|
|
*
|
2021-07-13 13:13:19 +02:00
|
|
|
* \param n 16 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 16
|
2021-07-14 12:53:07 +02:00
|
|
|
* bits unsigned integer in.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data where to put the least significant
|
2021-07-14 12:53:07 +02:00
|
|
|
* byte of the 16 bits unsigned integer \p n.
|
2021-07-07 16:16:56 +02:00
|
|
|
*/
|
2021-07-05 16:37:39 +02:00
|
|
|
#ifndef MBEDTLS_PUT_UINT16_LE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_PUT_UINT16_LE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
|
2021-07-05 16:37:39 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-07-19 12:56:54 +02:00
|
|
|
/**
|
|
|
|
* Get the unsigned 16 bits integer corresponding to two bytes in
|
2021-07-19 16:29:18 +02:00
|
|
|
* big-endian order (MSB first).
|
2021-07-19 12:56:54 +02:00
|
|
|
*
|
|
|
|
* \param data Base address of the memory to get the two bytes from.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data of the first and most significant
|
2021-07-19 12:56:54 +02:00
|
|
|
* byte of the two bytes to build the 16 bits unsigned
|
|
|
|
* integer from.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_GET_UINT16_BE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_GET_UINT16_BE( data, offset ) \
|
|
|
|
( \
|
|
|
|
( (uint16_t) ( data )[( offset ) ] << 8 ) \
|
|
|
|
| ( (uint16_t) ( data )[( offset ) + 1] ) \
|
2021-07-19 12:56:54 +02:00
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put in memory a 16 bits unsigned integer in big-endian order.
|
|
|
|
*
|
|
|
|
* \param n 16 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 16
|
|
|
|
* bits unsigned integer in.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data where to put the most significant
|
2021-07-19 12:56:54 +02:00
|
|
|
* byte of the 16 bits unsigned integer \p n.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_PUT_UINT16_BE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_PUT_UINT16_BE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_1( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_0( n ); \
|
2021-07-19 12:56:54 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-10-27 07:52:04 +02:00
|
|
|
/**
|
2021-10-27 11:05:49 +02:00
|
|
|
* Get the unsigned 24 bits integer corresponding to three bytes in
|
2021-10-27 07:52:04 +02:00
|
|
|
* big-endian order (MSB first).
|
|
|
|
*
|
2021-10-27 11:05:49 +02:00
|
|
|
* \param data Base address of the memory to get the three bytes from.
|
|
|
|
* \param offset Offset from \p data of the first and most significant
|
|
|
|
* byte of the three bytes to build the 24 bits unsigned
|
2021-10-27 07:52:04 +02:00
|
|
|
* integer from.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_GET_UINT24_BE
|
|
|
|
#define MBEDTLS_GET_UINT24_BE( data , offset ) \
|
|
|
|
( \
|
|
|
|
( (uint32_t) ( data )[( offset ) ] << 16 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 2] ) \
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put in memory a 24 bits unsigned integer in big-endian order.
|
|
|
|
*
|
|
|
|
* \param n 24 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 24
|
|
|
|
* bits unsigned integer in.
|
2021-10-27 11:05:49 +02:00
|
|
|
* \param offset Offset from \p data where to put the most significant
|
2021-10-27 07:52:04 +02:00
|
|
|
* byte of the 24 bits unsigned integer \p n.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_PUT_UINT24_BE
|
|
|
|
#define MBEDTLS_PUT_UINT24_BE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_2( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
|
|
|
|
( data )[( offset ) + 2] = MBEDTLS_BYTE_0( n ); \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2021-10-27 11:05:49 +02:00
|
|
|
* Get the unsigned 24 bits integer corresponding to three bytes in
|
2021-10-27 07:52:04 +02:00
|
|
|
* little-endian order (LSB first).
|
|
|
|
*
|
2021-10-27 11:05:49 +02:00
|
|
|
* \param data Base address of the memory to get the three bytes from.
|
|
|
|
* \param offset Offset from \p data of the first and least significant
|
|
|
|
* byte of the three bytes to build the 24 bits unsigned
|
2021-10-27 07:52:04 +02:00
|
|
|
* integer from.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_GET_UINT24_LE
|
|
|
|
#define MBEDTLS_GET_UINT24_LE( data, offset ) \
|
|
|
|
( \
|
|
|
|
( (uint32_t) ( data )[( offset ) ] ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \
|
|
|
|
| ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put in memory a 24 bits unsigned integer in little-endian order.
|
|
|
|
*
|
|
|
|
* \param n 24 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 24
|
|
|
|
* bits unsigned integer in.
|
2021-10-27 11:05:49 +02:00
|
|
|
* \param offset Offset from \p data where to put the least significant
|
2021-10-27 07:52:04 +02:00
|
|
|
* byte of the 24 bits unsigned integer \p n.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_PUT_UINT24_LE
|
|
|
|
#define MBEDTLS_PUT_UINT24_LE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
|
|
|
|
( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-07-16 13:29:49 +02:00
|
|
|
/**
|
|
|
|
* Get the unsigned 64 bits integer corresponding to eight bytes in
|
|
|
|
* big-endian order (MSB first).
|
|
|
|
*
|
|
|
|
* \param data Base address of the memory to get the eight bytes from.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data of the first and most significant
|
2021-07-16 13:29:49 +02:00
|
|
|
* byte of the eight bytes to build the 64 bits unsigned
|
|
|
|
* integer from.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_GET_UINT64_BE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_GET_UINT64_BE( data, offset ) \
|
|
|
|
( \
|
|
|
|
( (uint64_t) ( data )[( offset ) ] << 56 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 1] << 48 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 2] << 40 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 3] << 32 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 4] << 24 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 5] << 16 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 6] << 8 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 7] ) \
|
2021-07-16 13:29:49 +02:00
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put in memory a 64 bits unsigned integer in big-endian order.
|
|
|
|
*
|
|
|
|
* \param n 64 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 64
|
|
|
|
* bits unsigned integer in.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data where to put the most significant
|
2021-07-16 13:29:49 +02:00
|
|
|
* byte of the 64 bits unsigned integer \p n.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_PUT_UINT64_BE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_PUT_UINT64_BE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_7( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_6( n ); \
|
|
|
|
( data )[( offset ) + 2] = MBEDTLS_BYTE_5( n ); \
|
|
|
|
( data )[( offset ) + 3] = MBEDTLS_BYTE_4( n ); \
|
|
|
|
( data )[( offset ) + 4] = MBEDTLS_BYTE_3( n ); \
|
|
|
|
( data )[( offset ) + 5] = MBEDTLS_BYTE_2( n ); \
|
|
|
|
( data )[( offset ) + 6] = MBEDTLS_BYTE_1( n ); \
|
|
|
|
( data )[( offset ) + 7] = MBEDTLS_BYTE_0( n ); \
|
2021-07-16 13:29:49 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the unsigned 64 bits integer corresponding to eight bytes in
|
|
|
|
* little-endian order (LSB first).
|
|
|
|
*
|
|
|
|
* \param data Base address of the memory to get the eight bytes from.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data of the first and least significant
|
2021-07-16 13:29:49 +02:00
|
|
|
* byte of the eight bytes to build the 64 bits unsigned
|
|
|
|
* integer from.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_GET_UINT64_LE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_GET_UINT64_LE( data, offset ) \
|
|
|
|
( \
|
|
|
|
( (uint64_t) ( data )[( offset ) + 7] << 56 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 6] << 48 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 5] << 40 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 4] << 32 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 3] << 24 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 2] << 16 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) + 1] << 8 ) \
|
|
|
|
| ( (uint64_t) ( data )[( offset ) ] ) \
|
2021-07-16 13:29:49 +02:00
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put in memory a 64 bits unsigned integer in little-endian order.
|
|
|
|
*
|
|
|
|
* \param n 64 bits unsigned integer to put in memory.
|
|
|
|
* \param data Base address of the memory where to put the 64
|
|
|
|
* bits unsigned integer in.
|
2021-10-28 04:26:13 +02:00
|
|
|
* \param offset Offset from \p data where to put the least significant
|
2021-07-16 13:29:49 +02:00
|
|
|
* byte of the 64 bits unsigned integer \p n.
|
|
|
|
*/
|
|
|
|
#ifndef MBEDTLS_PUT_UINT64_LE
|
2021-07-19 16:29:18 +02:00
|
|
|
#define MBEDTLS_PUT_UINT64_LE( n, data, offset ) \
|
|
|
|
{ \
|
|
|
|
( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \
|
|
|
|
( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \
|
|
|
|
( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \
|
|
|
|
( data )[( offset ) + 3] = MBEDTLS_BYTE_3( n ); \
|
|
|
|
( data )[( offset ) + 4] = MBEDTLS_BYTE_4( n ); \
|
|
|
|
( data )[( offset ) + 5] = MBEDTLS_BYTE_5( n ); \
|
|
|
|
( data )[( offset ) + 6] = MBEDTLS_BYTE_6( n ); \
|
|
|
|
( data )[( offset ) + 7] = MBEDTLS_BYTE_7( n ); \
|
2021-07-16 13:29:49 +02:00
|
|
|
}
|
|
|
|
#endif
|
2021-07-05 16:37:39 +02:00
|
|
|
|
2021-09-24 06:45:36 +02:00
|
|
|
/* Fix MSVC C99 compatible issue
|
|
|
|
* MSVC support __func__ from visual studio 2015( 1900 )
|
|
|
|
* Use MSVC predefine macro to avoid name check fail.
|
|
|
|
*/
|
|
|
|
#if (defined(_MSC_VER) && ( _MSC_VER <= 1900 ))
|
2021-09-28 10:13:44 +02:00
|
|
|
#define /*no-check-names*/ __func__ __FUNCTION__
|
2021-09-24 06:45:36 +02:00
|
|
|
#endif
|
|
|
|
|
2019-09-11 13:39:11 +02:00
|
|
|
#endif /* MBEDTLS_LIBRARY_COMMON_H */
|