Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file common.h |
| 3 | * |
| 4 | * \brief Utility macros for internal use in the library |
| 5 | */ |
| 6 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | * See the License for the specific language governing permissions and |
| 20 | * limitations under the License. |
Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifndef MBEDTLS_LIBRARY_COMMON_H |
| 24 | #define MBEDTLS_LIBRARY_COMMON_H |
| 25 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 26 | #include "mbedtls/build_info.h" |
Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 27 | |
Joe Subbiani | 2194dc4 | 2021-07-14 12:31:31 +0100 | [diff] [blame] | 28 | #include <stdint.h> |
| 29 | |
Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 30 | /** Helper to define a function as static except when building invasive tests. |
| 31 | * |
| 32 | * If a function is only used inside its own source file and should be |
| 33 | * declared `static` to allow the compiler to optimize for code size, |
| 34 | * but that function has unit tests, define it with |
| 35 | * ``` |
| 36 | * MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... } |
| 37 | * ``` |
| 38 | * and declare it in a header in the `library/` directory with |
| 39 | * ``` |
| 40 | * #if defined(MBEDTLS_TEST_HOOKS) |
| 41 | * int mbedtls_foo(...); |
| 42 | * #endif |
| 43 | * ``` |
| 44 | */ |
| 45 | #if defined(MBEDTLS_TEST_HOOKS) |
| 46 | #define MBEDTLS_STATIC_TESTABLE |
| 47 | #else |
| 48 | #define MBEDTLS_STATIC_TESTABLE static |
| 49 | #endif |
| 50 | |
TRodziewicz | 7871c2e | 2021-07-07 17:29:43 +0200 | [diff] [blame] | 51 | #if defined(MBEDTLS_TEST_HOOKS) |
| 52 | extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file ); |
| 53 | #define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST ) \ |
| 54 | do { \ |
| 55 | if( ( ! ( TEST ) ) && ( ( *mbedtls_test_hook_test_fail ) != NULL ) ) \ |
| 56 | { \ |
| 57 | ( *mbedtls_test_hook_test_fail )( #TEST, __LINE__, __FILE__ ); \ |
| 58 | } \ |
| 59 | } while( 0 ) |
| 60 | #else |
| 61 | #define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST ) |
| 62 | #endif /* defined(MBEDTLS_TEST_HOOKS) */ |
| 63 | |
Mateusz Starzyk | 57d1d19 | 2021-05-27 14:39:53 +0200 | [diff] [blame] | 64 | /** Allow library to access its structs' private members. |
Mateusz Starzyk | 2c09c9b | 2021-05-14 22:20:10 +0200 | [diff] [blame] | 65 | * |
| 66 | * Although structs defined in header files are publicly available, |
| 67 | * their members are private and should not be accessed by the user. |
| 68 | */ |
| 69 | #define MBEDTLS_ALLOW_PRIVATE_ACCESS |
| 70 | |
Joe Subbiani | 50dde56 | 2021-06-22 15:51:53 +0100 | [diff] [blame] | 71 | /** Byte Reading Macros |
Joe Subbiani | 6f2bb0c | 2021-06-24 09:06:23 +0100 | [diff] [blame] | 72 | * |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 73 | * Obtain the most significant byte of x using 0xff |
| 74 | * Using MBEDTLS_BYTE_a will shift a*8 bits |
| 75 | * to retrieve the next byte of information |
Joe Subbiani | 50dde56 | 2021-06-22 15:51:53 +0100 | [diff] [blame] | 76 | */ |
Joe Subbiani | 2194dc4 | 2021-07-14 12:31:31 +0100 | [diff] [blame] | 77 | #define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) ) |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 78 | #define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) ) |
| 79 | #define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) ) |
| 80 | #define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) ) |
Joe Subbiani | 2194dc4 | 2021-07-14 12:31:31 +0100 | [diff] [blame] | 81 | #define MBEDTLS_BYTE_4( x ) ( (uint8_t) ( ( ( x ) >> 32 ) & 0xff ) ) |
| 82 | #define MBEDTLS_BYTE_5( x ) ( (uint8_t) ( ( ( x ) >> 40 ) & 0xff ) ) |
| 83 | #define MBEDTLS_BYTE_6( x ) ( (uint8_t) ( ( ( x ) >> 48 ) & 0xff ) ) |
| 84 | #define MBEDTLS_BYTE_7( x ) ( (uint8_t) ( ( ( x ) >> 56 ) & 0xff ) ) |
Joe Subbiani | cd84d76 | 2021-07-08 14:59:52 +0100 | [diff] [blame] | 85 | |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 86 | /** |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 87 | * Get the unsigned 32 bits integer corresponding to four bytes in |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 88 | * big-endian order (MSB first). |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 89 | * |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 90 | * \param data Base address of the memory to get the four bytes from. |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 91 | * \param offset Offset from \p base of the first and most significant |
| 92 | * byte of the four bytes to build the 32 bits unsigned |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 93 | * integer from. |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 94 | */ |
| 95 | #ifndef MBEDTLS_GET_UINT32_BE |
| 96 | #define MBEDTLS_GET_UINT32_BE( data , offset ) \ |
| 97 | ( \ |
| 98 | ( (uint32_t) ( data )[( offset ) ] << 24 ) \ |
| 99 | | ( (uint32_t) ( data )[( offset ) + 1] << 16 ) \ |
| 100 | | ( (uint32_t) ( data )[( offset ) + 2] << 8 ) \ |
| 101 | | ( (uint32_t) ( data )[( offset ) + 3] ) \ |
| 102 | ) |
| 103 | #endif |
| 104 | |
| 105 | /** |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 106 | * Put in memory a 32 bits unsigned integer in big-endian order. |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 107 | * |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 108 | * \param n 32 bits unsigned integer to put in memory. |
| 109 | * \param data Base address of the memory where to put the 32 |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 110 | * bits unsigned integer in. |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 111 | * \param offset Offset from \p base where to put the most significant |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 112 | * byte of the 32 bits unsigned integer \p n. |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 113 | */ |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 114 | #ifndef MBEDTLS_PUT_UINT32_BE |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 115 | #define MBEDTLS_PUT_UINT32_BE( n, data, offset ) \ |
| 116 | do { \ |
| 117 | ( data )[( offset ) ] = (unsigned char) ( (n) >> 24 ); \ |
| 118 | ( data )[( offset ) + 1] = (unsigned char) ( (n) >> 16 ); \ |
| 119 | ( data )[( offset ) + 2] = (unsigned char) ( (n) >> 8 ); \ |
| 120 | ( data )[( offset ) + 3] = (unsigned char) ( (n) ); \ |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 121 | } while( 0 ) |
Joe Subbiani | 30d974c | 2021-06-23 11:49:03 +0100 | [diff] [blame] | 122 | #endif |
| 123 | |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 124 | /** |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 125 | * Get the unsigned 32 bits integer corresponding to four bytes in |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 126 | * little-endian order (LSB first). |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 127 | * |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 128 | * \param data Base address of the memory to get the four bytes from. |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 129 | * \param offset Offset from \p base of the first and least significant |
| 130 | * byte of the four bytes to build the 32 bits unsigned |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 131 | * integer from. |
Joe Subbiani | 54c6134 | 2021-06-23 12:16:47 +0100 | [diff] [blame] | 132 | */ |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 133 | #ifndef MBEDTLS_GET_UINT32_LE |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 134 | #define MBEDTLS_GET_UINT32_LE( data, offset ) \ |
| 135 | ( \ |
| 136 | ( (uint32_t) ( data )[( offset ) ] ) \ |
| 137 | | ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \ |
| 138 | | ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \ |
| 139 | | ( (uint32_t) ( data )[( offset ) + 3] << 24 ) \ |
| 140 | ) |
Joe Subbiani | 54c6134 | 2021-06-23 12:16:47 +0100 | [diff] [blame] | 141 | #endif |
| 142 | |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 143 | /** |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 144 | * Put in memory a 32 bits unsigned integer in little-endian order. |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 145 | * |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 146 | * \param n 32 bits unsigned integer to put in memory. |
| 147 | * \param data Base address of the memory where to put the 32 |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 148 | * bits unsigned integer in. |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 149 | * \param offset Offset from \p base where to put the least significant |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 150 | * byte of the 32 bits unsigned integer \p n. |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 151 | */ |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 152 | #ifndef MBEDTLS_PUT_UINT32_LE |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 153 | #define MBEDTLS_PUT_UINT32_LE( n, data, offset ) \ |
| 154 | do { \ |
| 155 | ( data )[( offset ) ] = (unsigned char) ( ( (n) ) & 0xFF ); \ |
| 156 | ( data )[( offset ) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \ |
| 157 | ( data )[( offset ) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \ |
| 158 | ( data )[( offset ) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \ |
Joe Subbiani | 5ecac21 | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 159 | } while( 0 ) |
Joe Subbiani | 54c6134 | 2021-06-23 12:16:47 +0100 | [diff] [blame] | 160 | #endif |
| 161 | |
Joe Subbiani | 6f2bb0c | 2021-06-24 09:06:23 +0100 | [diff] [blame] | 162 | /** |
Joe Subbiani | bf7ea84 | 2021-07-14 12:05:51 +0100 | [diff] [blame] | 163 | * Get the unsigned 16 bits integer corresponding to two bytes in |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 164 | * little-endian order (LSB first). |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 165 | * |
Joe Subbiani | bf7ea84 | 2021-07-14 12:05:51 +0100 | [diff] [blame] | 166 | * \param data Base address of the memory to get the two bytes from. |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 167 | * \param offset Offset from \p base of the first and least significant |
Joe Subbiani | bf7ea84 | 2021-07-14 12:05:51 +0100 | [diff] [blame] | 168 | * byte of the two bytes to build the 16 bits unsigned |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 169 | * integer from. |
Joe Subbiani | 3b39450 | 2021-06-23 11:23:44 +0100 | [diff] [blame] | 170 | */ |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 171 | #ifndef MBEDTLS_GET_UINT16_LE |
| 172 | #define MBEDTLS_GET_UINT16_LE( data, offset ) \ |
| 173 | ( \ |
| 174 | ( (uint16_t) ( data )[( offset ) ] ) \ |
| 175 | | ( (uint16_t) ( data )[( offset ) + 1] << 8 ) \ |
Joe Subbiani | 3b39450 | 2021-06-23 11:23:44 +0100 | [diff] [blame] | 176 | ) |
Joe Subbiani | 6a50631 | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 177 | #endif |
Joe Subbiani | 3b39450 | 2021-06-23 11:23:44 +0100 | [diff] [blame] | 178 | |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 179 | /** |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 180 | * Put in memory a 16 bits unsigned integer in little-endian order. |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 181 | * |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 182 | * \param n 16 bits unsigned integer to put in memory. |
| 183 | * \param data Base address of the memory where to put the 16 |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 184 | * bits unsigned integer in. |
Joe Subbiani | f5462d9 | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 185 | * \param offset Offset from \p base where to put the least significant |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 186 | * byte of the 16 bits unsigned integer \p n. |
Joe Subbiani | 394bdd6 | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 187 | */ |
Joe Subbiani | 9fa9ac3 | 2021-07-05 15:37:39 +0100 | [diff] [blame] | 188 | #ifndef MBEDTLS_PUT_UINT16_LE |
Joe Subbiani | 635231a | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 189 | #define MBEDTLS_PUT_UINT16_LE( n, data, offset ) \ |
| 190 | { \ |
| 191 | ( data )[( offset ) ] = (unsigned char) ( ( (n) ) & 0xFF ); \ |
| 192 | ( data )[( offset ) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \ |
Joe Subbiani | 9fa9ac3 | 2021-07-05 15:37:39 +0100 | [diff] [blame] | 193 | } |
| 194 | #endif |
| 195 | |
Joe Subbiani | 99edd6c | 2021-07-16 12:29:49 +0100 | [diff] [blame] | 196 | /** |
| 197 | * Get the unsigned 64 bits integer corresponding to eight bytes in |
| 198 | * big-endian order (MSB first). |
| 199 | * |
| 200 | * \param data Base address of the memory to get the eight bytes from. |
| 201 | * \param offset Offset from \p base of the first and most significant |
| 202 | * byte of the eight bytes to build the 64 bits unsigned |
| 203 | * integer from. |
| 204 | */ |
| 205 | #ifndef MBEDTLS_GET_UINT64_BE |
| 206 | #define MBEDTLS_GET_UINT64_BE( data, offset ) \ |
| 207 | ( \ |
| 208 | ( (uint64_t) ( data )[( offset ) ] << 56 ) \ |
| 209 | | ( (uint64_t) ( data )[( offset ) + 1] << 48 ) \ |
| 210 | | ( (uint64_t) ( data )[( offset ) + 2] << 40 ) \ |
| 211 | | ( (uint64_t) ( data )[( offset ) + 3] << 32 ) \ |
| 212 | | ( (uint64_t) ( data )[( offset ) + 4] << 24 ) \ |
| 213 | | ( (uint64_t) ( data )[( offset ) + 5] << 16 ) \ |
| 214 | | ( (uint64_t) ( data )[( offset ) + 6] << 8 ) \ |
| 215 | | ( (uint64_t) ( data )[( offset ) + 7] ) \ |
| 216 | ) |
| 217 | #endif |
| 218 | |
| 219 | /** |
| 220 | * Put in memory a 64 bits unsigned integer in big-endian order. |
| 221 | * |
| 222 | * \param n 64 bits unsigned integer to put in memory. |
| 223 | * \param data Base address of the memory where to put the 64 |
| 224 | * bits unsigned integer in. |
| 225 | * \param offset Offset from \p base where to put the most significant |
| 226 | * byte of the 64 bits unsigned integer \p n. |
| 227 | */ |
| 228 | #ifndef MBEDTLS_PUT_UINT64_BE |
| 229 | #define MBEDTLS_PUT_UINT64_BE( n, data, offset ) \ |
| 230 | { \ |
| 231 | ( data )[( offset ) ] = (unsigned char) ( (n) >> 56 ); \ |
| 232 | ( data )[( offset ) + 1] = (unsigned char) ( (n) >> 48 ); \ |
| 233 | ( data )[( offset ) + 2] = (unsigned char) ( (n) >> 40 ); \ |
| 234 | ( data )[( offset ) + 3] = (unsigned char) ( (n) >> 32 ); \ |
| 235 | ( data )[( offset ) + 4] = (unsigned char) ( (n) >> 24 ); \ |
| 236 | ( data )[( offset ) + 5] = (unsigned char) ( (n) >> 16 ); \ |
| 237 | ( data )[( offset ) + 6] = (unsigned char) ( (n) >> 8 ); \ |
| 238 | ( data )[( offset ) + 7] = (unsigned char) ( (n) ); \ |
| 239 | } |
| 240 | #endif |
| 241 | |
| 242 | /** |
| 243 | * Get the unsigned 64 bits integer corresponding to eight bytes in |
| 244 | * little-endian order (LSB first). |
| 245 | * |
| 246 | * \param data Base address of the memory to get the eight bytes from. |
| 247 | * \param offset Offset from \p base of the first and least significant |
| 248 | * byte of the eight bytes to build the 64 bits unsigned |
| 249 | * integer from. |
| 250 | */ |
| 251 | #ifndef MBEDTLS_GET_UINT64_LE |
| 252 | #define MBEDTLS_GET_UINT64_LE( data, offset ) \ |
| 253 | ( \ |
| 254 | ( (uint64_t) ( data )[( offset ) + 7] << 56 ) \ |
| 255 | | ( (uint64_t) ( data )[( offset ) + 6] << 48 ) \ |
| 256 | | ( (uint64_t) ( data )[( offset ) + 5] << 40 ) \ |
| 257 | | ( (uint64_t) ( data )[( offset ) + 4] << 32 ) \ |
| 258 | | ( (uint64_t) ( data )[( offset ) + 3] << 24 ) \ |
| 259 | | ( (uint64_t) ( data )[( offset ) + 2] << 16 ) \ |
| 260 | | ( (uint64_t) ( data )[( offset ) + 1] << 8 ) \ |
| 261 | | ( (uint64_t) ( data )[( offset ) ] ) \ |
| 262 | ) |
| 263 | #endif |
| 264 | |
| 265 | /** |
| 266 | * Put in memory a 64 bits unsigned integer in little-endian order. |
| 267 | * |
| 268 | * \param n 64 bits unsigned integer to put in memory. |
| 269 | * \param data Base address of the memory where to put the 64 |
| 270 | * bits unsigned integer in. |
| 271 | * \param offset Offset from \p base where to put the least significant |
| 272 | * byte of the 64 bits unsigned integer \p n. |
| 273 | */ |
| 274 | #ifndef MBEDTLS_PUT_UINT64_LE |
| 275 | #define MBEDTLS_PUT_UINT64_LE( n, data, offset ) \ |
| 276 | { \ |
| 277 | ( data )[( offset ) + 7] = (unsigned char) ( (n) >> 56 ); \ |
| 278 | ( data )[( offset ) + 6] = (unsigned char) ( (n) >> 48 ); \ |
| 279 | ( data )[( offset ) + 5] = (unsigned char) ( (n) >> 40 ); \ |
| 280 | ( data )[( offset ) + 4] = (unsigned char) ( (n) >> 32 ); \ |
| 281 | ( data )[( offset ) + 3] = (unsigned char) ( (n) >> 24 ); \ |
| 282 | ( data )[( offset ) + 2] = (unsigned char) ( (n) >> 16 ); \ |
| 283 | ( data )[( offset ) + 1] = (unsigned char) ( (n) >> 8 ); \ |
| 284 | ( data )[( offset ) ] = (unsigned char) ( (n) ); \ |
| 285 | } |
| 286 | #endif |
Joe Subbiani | 9fa9ac3 | 2021-07-05 15:37:39 +0100 | [diff] [blame] | 287 | |
Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 288 | #endif /* MBEDTLS_LIBRARY_COMMON_H */ |