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 | |
| 26 | #if defined(MBEDTLS_CONFIG_FILE) |
| 27 | #include MBEDTLS_CONFIG_FILE |
| 28 | #else |
| 29 | #include "mbedtls/config.h" |
| 30 | #endif |
| 31 | |
Joe Subbiani | c045dc1 | 2021-07-14 12:31:31 +0100 | [diff] [blame] | 32 | #include <stdint.h> |
| 33 | |
Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 34 | /** Helper to define a function as static except when building invasive tests. |
| 35 | * |
| 36 | * If a function is only used inside its own source file and should be |
| 37 | * declared `static` to allow the compiler to optimize for code size, |
| 38 | * but that function has unit tests, define it with |
| 39 | * ``` |
| 40 | * MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... } |
| 41 | * ``` |
| 42 | * and declare it in a header in the `library/` directory with |
| 43 | * ``` |
| 44 | * #if defined(MBEDTLS_TEST_HOOKS) |
| 45 | * int mbedtls_foo(...); |
| 46 | * #endif |
| 47 | * ``` |
| 48 | */ |
| 49 | #if defined(MBEDTLS_TEST_HOOKS) |
| 50 | #define MBEDTLS_STATIC_TESTABLE |
| 51 | #else |
| 52 | #define MBEDTLS_STATIC_TESTABLE static |
| 53 | #endif |
| 54 | |
Joe Subbiani | ba486b0 | 2021-06-22 15:51:53 +0100 | [diff] [blame] | 55 | /** Allow library to access its structs' private members. |
| 56 | * |
| 57 | * Although structs defined in header files are publicly available, |
| 58 | * their members are private and should not be accessed by the user. |
| 59 | */ |
| 60 | #define MBEDTLS_ALLOW_PRIVATE_ACCESS |
| 61 | |
| 62 | /** Byte Reading Macros |
Joe Subbiani | 61f7d73 | 2021-06-24 09:06:23 +0100 | [diff] [blame] | 63 | * |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 64 | * Obtain the most significant byte of x using 0xff |
| 65 | * Using MBEDTLS_BYTE_a will shift a*8 bits |
| 66 | * to retrieve the next byte of information |
Joe Subbiani | ba486b0 | 2021-06-22 15:51:53 +0100 | [diff] [blame] | 67 | */ |
Joe Subbiani | c045dc1 | 2021-07-14 12:31:31 +0100 | [diff] [blame] | 68 | #define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) ) |
Joe Subbiani | 2bbafda | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 69 | #define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) ) |
| 70 | #define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) ) |
| 71 | #define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) ) |
Joe Subbiani | c045dc1 | 2021-07-14 12:31:31 +0100 | [diff] [blame] | 72 | #define MBEDTLS_BYTE_4( x ) ( (uint8_t) ( ( ( x ) >> 32 ) & 0xff ) ) |
| 73 | #define MBEDTLS_BYTE_5( x ) ( (uint8_t) ( ( ( x ) >> 40 ) & 0xff ) ) |
| 74 | #define MBEDTLS_BYTE_6( x ) ( (uint8_t) ( ( ( x ) >> 48 ) & 0xff ) ) |
| 75 | #define MBEDTLS_BYTE_7( x ) ( (uint8_t) ( ( ( x ) >> 56 ) & 0xff ) ) |
Joe Subbiani | 6b897c9 | 2021-07-08 14:59:52 +0100 | [diff] [blame] | 76 | |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 77 | /** |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 78 | * Get the unsigned 32 bits integer corresponding to four bytes in |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 79 | * big-endian order (MSB first). |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 80 | * |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 81 | * \param data Base address of the memory to get the four bytes from. |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 82 | * \param offset Offset from \p base of the first and most significant |
| 83 | * byte of the four bytes to build the 32 bits unsigned |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 84 | * integer from. |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 85 | */ |
| 86 | #ifndef MBEDTLS_GET_UINT32_BE |
| 87 | #define MBEDTLS_GET_UINT32_BE( data , offset ) \ |
| 88 | ( \ |
| 89 | ( (uint32_t) ( data )[( offset ) ] << 24 ) \ |
| 90 | | ( (uint32_t) ( data )[( offset ) + 1] << 16 ) \ |
| 91 | | ( (uint32_t) ( data )[( offset ) + 2] << 8 ) \ |
| 92 | | ( (uint32_t) ( data )[( offset ) + 3] ) \ |
| 93 | ) |
| 94 | #endif |
| 95 | |
| 96 | /** |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 97 | * Put in memory a 32 bits unsigned integer in big-endian order. |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 98 | * |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 99 | * \param n 32 bits unsigned integer to put in memory. |
| 100 | * \param data Base address of the memory where to put the 32 |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 101 | * bits unsigned integer in. |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 102 | * \param offset Offset from \p base where to put the most significant |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 103 | * byte of the 32 bits unsigned integer \p n. |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 104 | */ |
Joe Subbiani | 2bbafda | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 105 | #ifndef MBEDTLS_PUT_UINT32_BE |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 106 | #define MBEDTLS_PUT_UINT32_BE( n, data, offset ) \ |
| 107 | do { \ |
| 108 | ( data )[( offset ) ] = (unsigned char) ( (n) >> 24 ); \ |
| 109 | ( data )[( offset ) + 1] = (unsigned char) ( (n) >> 16 ); \ |
| 110 | ( data )[( offset ) + 2] = (unsigned char) ( (n) >> 8 ); \ |
| 111 | ( data )[( offset ) + 3] = (unsigned char) ( (n) ); \ |
Joe Subbiani | 2bbafda | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 112 | } while( 0 ) |
Joe Subbiani | aa5f6a6 | 2021-06-23 11:49:03 +0100 | [diff] [blame] | 113 | #endif |
| 114 | |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 115 | /** |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 116 | * Get the unsigned 32 bits integer corresponding to four bytes in |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 117 | * little-endian order (LSB first). |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 118 | * |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 119 | * \param data Base address of the memory to get the four bytes from. |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 120 | * \param offset Offset from \p base of the first and least significant |
| 121 | * byte of the four bytes to build the 32 bits unsigned |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 122 | * integer from. |
Joe Subbiani | 4fb7555 | 2021-06-23 12:16:47 +0100 | [diff] [blame] | 123 | */ |
Joe Subbiani | 2bbafda | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 124 | #ifndef MBEDTLS_GET_UINT32_LE |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 125 | #define MBEDTLS_GET_UINT32_LE( data, offset ) \ |
| 126 | ( \ |
| 127 | ( (uint32_t) ( data )[( offset ) ] ) \ |
| 128 | | ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \ |
| 129 | | ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \ |
| 130 | | ( (uint32_t) ( data )[( offset ) + 3] << 24 ) \ |
| 131 | ) |
Joe Subbiani | 4fb7555 | 2021-06-23 12:16:47 +0100 | [diff] [blame] | 132 | #endif |
| 133 | |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 134 | /** |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 135 | * Put in memory a 32 bits unsigned integer in little-endian order. |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 136 | * |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 137 | * \param n 32 bits unsigned integer to put in memory. |
| 138 | * \param data Base address of the memory where to put the 32 |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 139 | * bits unsigned integer in. |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 140 | * \param offset Offset from \p base where to put the least significant |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 141 | * byte of the 32 bits unsigned integer \p n. |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 142 | */ |
Joe Subbiani | 2bbafda | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 143 | #ifndef MBEDTLS_PUT_UINT32_LE |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 144 | #define MBEDTLS_PUT_UINT32_LE( n, data, offset ) \ |
| 145 | do { \ |
| 146 | ( data )[( offset ) ] = (unsigned char) ( ( (n) ) & 0xFF ); \ |
| 147 | ( data )[( offset ) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \ |
| 148 | ( data )[( offset ) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \ |
| 149 | ( data )[( offset ) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \ |
Joe Subbiani | 2bbafda | 2021-06-24 13:00:03 +0100 | [diff] [blame] | 150 | } while( 0 ) |
Joe Subbiani | 4fb7555 | 2021-06-23 12:16:47 +0100 | [diff] [blame] | 151 | #endif |
| 152 | |
Joe Subbiani | 61f7d73 | 2021-06-24 09:06:23 +0100 | [diff] [blame] | 153 | /** |
Joe Subbiani | 5b96e67 | 2021-07-14 12:05:51 +0100 | [diff] [blame] | 154 | * Get the unsigned 16 bits integer corresponding to two bytes in |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 155 | * little-endian order (LSB first). |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 156 | * |
Joe Subbiani | 5b96e67 | 2021-07-14 12:05:51 +0100 | [diff] [blame] | 157 | * \param data Base address of the memory to get the two bytes from. |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 158 | * \param offset Offset from \p base of the first and least significant |
Joe Subbiani | 5b96e67 | 2021-07-14 12:05:51 +0100 | [diff] [blame] | 159 | * byte of the two bytes to build the 16 bits unsigned |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 160 | * integer from. |
Joe Subbiani | 927488e | 2021-06-23 11:23:44 +0100 | [diff] [blame] | 161 | */ |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 162 | #ifndef MBEDTLS_GET_UINT16_LE |
| 163 | #define MBEDTLS_GET_UINT16_LE( data, offset ) \ |
| 164 | ( \ |
| 165 | ( (uint16_t) ( data )[( offset ) ] ) \ |
| 166 | | ( (uint16_t) ( data )[( offset ) + 1] << 8 ) \ |
Joe Subbiani | 927488e | 2021-06-23 11:23:44 +0100 | [diff] [blame] | 167 | ) |
Joe Subbiani | 9231d5f | 2021-07-07 16:56:29 +0100 | [diff] [blame] | 168 | #endif |
Joe Subbiani | 927488e | 2021-06-23 11:23:44 +0100 | [diff] [blame] | 169 | |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 170 | /** |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 171 | * Put in memory a 16 bits unsigned integer in little-endian order. |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 172 | * |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 173 | * \param n 16 bits unsigned integer to put in memory. |
| 174 | * \param data Base address of the memory where to put the 16 |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 175 | * bits unsigned integer in. |
Joe Subbiani | 6350d3a | 2021-07-13 12:13:19 +0100 | [diff] [blame] | 176 | * \param offset Offset from \p base where to put the least significant |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 177 | * byte of the 16 bits unsigned integer \p n. |
Joe Subbiani | 266476d | 2021-07-07 15:16:56 +0100 | [diff] [blame] | 178 | */ |
Joe Subbiani | 4530b27 | 2021-07-05 15:37:39 +0100 | [diff] [blame] | 179 | #ifndef MBEDTLS_PUT_UINT16_LE |
Joe Subbiani | 0a65d53 | 2021-07-14 11:53:07 +0100 | [diff] [blame] | 180 | #define MBEDTLS_PUT_UINT16_LE( n, data, offset ) \ |
| 181 | { \ |
| 182 | ( data )[( offset ) ] = (unsigned char) ( ( (n) ) & 0xFF ); \ |
| 183 | ( data )[( offset ) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \ |
Joe Subbiani | 4530b27 | 2021-07-05 15:37:39 +0100 | [diff] [blame] | 184 | } |
| 185 | #endif |
| 186 | |
Joe Subbiani | 1bd5d7d | 2021-07-16 12:29:49 +0100 | [diff] [blame] | 187 | /** |
Joe Subbiani | c54e908 | 2021-07-19 11:56:54 +0100 | [diff] [blame^] | 188 | * Get the unsigned 16 bits integer corresponding to two bytes in |
| 189 | * big-endian order (LSB first). |
| 190 | * |
| 191 | * \param data Base address of the memory to get the two bytes from. |
| 192 | * \param offset Offset from \p base of the first and most significant |
| 193 | * byte of the two bytes to build the 16 bits unsigned |
| 194 | * integer from. |
| 195 | */ |
| 196 | #ifndef MBEDTLS_GET_UINT16_BE |
| 197 | #define MBEDTLS_GET_UINT16_BE( data, offset ) \ |
| 198 | ( \ |
| 199 | ( (uint16_t) ( data )[( offset ) ] << 8 ) \ |
| 200 | | ( (uint16_t) ( data )[( offset ) + 1] ) \ |
| 201 | ) |
| 202 | #endif |
| 203 | |
| 204 | /** |
| 205 | * Put in memory a 16 bits unsigned integer in big-endian order. |
| 206 | * |
| 207 | * \param n 16 bits unsigned integer to put in memory. |
| 208 | * \param data Base address of the memory where to put the 16 |
| 209 | * bits unsigned integer in. |
| 210 | * \param offset Offset from \p base where to put the most significant |
| 211 | * byte of the 16 bits unsigned integer \p n. |
| 212 | */ |
| 213 | #ifndef MBEDTLS_PUT_UINT16_BE |
| 214 | #define MBEDTLS_PUT_UINT16_BE( n, data, offset ) \ |
| 215 | { \ |
| 216 | ( data )[( offset ) ] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \ |
| 217 | ( data )[( offset ) + 1] = (unsigned char) ( ( (n) ) & 0xFF ); \ |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | /** |
Joe Subbiani | 1bd5d7d | 2021-07-16 12:29:49 +0100 | [diff] [blame] | 222 | * Get the unsigned 64 bits integer corresponding to eight bytes in |
| 223 | * big-endian order (MSB first). |
| 224 | * |
| 225 | * \param data Base address of the memory to get the eight bytes from. |
| 226 | * \param offset Offset from \p base of the first and most significant |
| 227 | * byte of the eight bytes to build the 64 bits unsigned |
| 228 | * integer from. |
| 229 | */ |
| 230 | #ifndef MBEDTLS_GET_UINT64_BE |
| 231 | #define MBEDTLS_GET_UINT64_BE( data, offset ) \ |
| 232 | ( \ |
| 233 | ( (uint64_t) ( data )[( offset ) ] << 56 ) \ |
| 234 | | ( (uint64_t) ( data )[( offset ) + 1] << 48 ) \ |
| 235 | | ( (uint64_t) ( data )[( offset ) + 2] << 40 ) \ |
| 236 | | ( (uint64_t) ( data )[( offset ) + 3] << 32 ) \ |
| 237 | | ( (uint64_t) ( data )[( offset ) + 4] << 24 ) \ |
| 238 | | ( (uint64_t) ( data )[( offset ) + 5] << 16 ) \ |
| 239 | | ( (uint64_t) ( data )[( offset ) + 6] << 8 ) \ |
| 240 | | ( (uint64_t) ( data )[( offset ) + 7] ) \ |
| 241 | ) |
| 242 | #endif |
| 243 | |
| 244 | /** |
| 245 | * Put in memory a 64 bits unsigned integer in big-endian order. |
| 246 | * |
| 247 | * \param n 64 bits unsigned integer to put in memory. |
| 248 | * \param data Base address of the memory where to put the 64 |
| 249 | * bits unsigned integer in. |
| 250 | * \param offset Offset from \p base where to put the most significant |
| 251 | * byte of the 64 bits unsigned integer \p n. |
| 252 | */ |
| 253 | #ifndef MBEDTLS_PUT_UINT64_BE |
| 254 | #define MBEDTLS_PUT_UINT64_BE( n, data, offset ) \ |
| 255 | { \ |
| 256 | ( data )[( offset ) ] = (unsigned char) ( (n) >> 56 ); \ |
| 257 | ( data )[( offset ) + 1] = (unsigned char) ( (n) >> 48 ); \ |
| 258 | ( data )[( offset ) + 2] = (unsigned char) ( (n) >> 40 ); \ |
| 259 | ( data )[( offset ) + 3] = (unsigned char) ( (n) >> 32 ); \ |
| 260 | ( data )[( offset ) + 4] = (unsigned char) ( (n) >> 24 ); \ |
| 261 | ( data )[( offset ) + 5] = (unsigned char) ( (n) >> 16 ); \ |
| 262 | ( data )[( offset ) + 6] = (unsigned char) ( (n) >> 8 ); \ |
| 263 | ( data )[( offset ) + 7] = (unsigned char) ( (n) ); \ |
| 264 | } |
| 265 | #endif |
| 266 | |
| 267 | /** |
| 268 | * Get the unsigned 64 bits integer corresponding to eight bytes in |
| 269 | * little-endian order (LSB first). |
| 270 | * |
| 271 | * \param data Base address of the memory to get the eight bytes from. |
| 272 | * \param offset Offset from \p base of the first and least significant |
| 273 | * byte of the eight bytes to build the 64 bits unsigned |
| 274 | * integer from. |
| 275 | */ |
| 276 | #ifndef MBEDTLS_GET_UINT64_LE |
| 277 | #define MBEDTLS_GET_UINT64_LE( data, offset ) \ |
| 278 | ( \ |
| 279 | ( (uint64_t) ( data )[( offset ) + 7] << 56 ) \ |
| 280 | | ( (uint64_t) ( data )[( offset ) + 6] << 48 ) \ |
| 281 | | ( (uint64_t) ( data )[( offset ) + 5] << 40 ) \ |
| 282 | | ( (uint64_t) ( data )[( offset ) + 4] << 32 ) \ |
| 283 | | ( (uint64_t) ( data )[( offset ) + 3] << 24 ) \ |
| 284 | | ( (uint64_t) ( data )[( offset ) + 2] << 16 ) \ |
| 285 | | ( (uint64_t) ( data )[( offset ) + 1] << 8 ) \ |
| 286 | | ( (uint64_t) ( data )[( offset ) ] ) \ |
| 287 | ) |
| 288 | #endif |
| 289 | |
| 290 | /** |
| 291 | * Put in memory a 64 bits unsigned integer in little-endian order. |
| 292 | * |
| 293 | * \param n 64 bits unsigned integer to put in memory. |
| 294 | * \param data Base address of the memory where to put the 64 |
| 295 | * bits unsigned integer in. |
| 296 | * \param offset Offset from \p base where to put the least significant |
| 297 | * byte of the 64 bits unsigned integer \p n. |
| 298 | */ |
| 299 | #ifndef MBEDTLS_PUT_UINT64_LE |
| 300 | #define MBEDTLS_PUT_UINT64_LE( n, data, offset ) \ |
| 301 | { \ |
| 302 | ( data )[( offset ) + 7] = (unsigned char) ( (n) >> 56 ); \ |
| 303 | ( data )[( offset ) + 6] = (unsigned char) ( (n) >> 48 ); \ |
| 304 | ( data )[( offset ) + 5] = (unsigned char) ( (n) >> 40 ); \ |
| 305 | ( data )[( offset ) + 4] = (unsigned char) ( (n) >> 32 ); \ |
| 306 | ( data )[( offset ) + 3] = (unsigned char) ( (n) >> 24 ); \ |
| 307 | ( data )[( offset ) + 2] = (unsigned char) ( (n) >> 16 ); \ |
| 308 | ( data )[( offset ) + 1] = (unsigned char) ( (n) >> 8 ); \ |
| 309 | ( data )[( offset ) ] = (unsigned char) ( (n) ); \ |
| 310 | } |
| 311 | #endif |
Joe Subbiani | 4530b27 | 2021-07-05 15:37:39 +0100 | [diff] [blame] | 312 | |
Gilles Peskine | c4672fd | 2019-09-11 13:39:11 +0200 | [diff] [blame] | 313 | #endif /* MBEDTLS_LIBRARY_COMMON_H */ |