blob: d67e487a3317146cf6d694af55c21a10c85095a6 [file] [log] [blame]
Ronald Cron4b8b1992020-06-09 13:52:23 +02001/**
2 * \file macros.h
3 *
4 * \brief This file contains generic macros for the purpose of testing.
5 */
6
Bence Szépkúti86974652020-06-15 11:59:37 +02007/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02008 * Copyright The Mbed TLS Contributors
Ronald Cron4b8b1992020-06-09 13:52:23 +02009 * 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.
Ronald Cron4b8b1992020-06-09 13:52:23 +020022 */
23
24#ifndef TEST_MACROS_H
25#define TEST_MACROS_H
26
27#if !defined(MBEDTLS_CONFIG_FILE)
28#include "mbedtls/config.h"
29#else
30#include MBEDTLS_CONFIG_FILE
31#endif
32
Ronald Cron849930a2020-06-03 08:06:47 +020033#include <stdlib.h>
34
Ronald Cron849930a2020-06-03 08:06:47 +020035#include "mbedtls/platform.h"
Ronald Cron849930a2020-06-03 08:06:47 +020036
37#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
38#include "mbedtls/memory_buffer_alloc.h"
39#endif
40
Chris Jonesa6d155f2021-02-09 12:09:33 +000041/**
42 * \brief This macro tests the expression passed to it as a test step or
43 * individual test in a test case.
44 *
45 * It allows a library function to return a value and return an error
46 * code that can be tested.
47 *
48 * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
49 * callback, MBEDTLS_PARAM_FAILED(), will be assumed to be a test
50 * failure.
51 *
52 * This macro is not suitable for negative parameter validation tests,
53 * as it assumes the test step will not create an error.
54 *
55 * Failing the test means:
56 * - Mark this test case as failed.
57 * - Print a message identifying the failure.
58 * - Jump to the \c exit label.
59 *
60 * This macro expands to an instruction, not an expression.
61 * It may jump to the \c exit label.
62 *
63 * \param TEST The test expression to be tested.
64 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010065#define TEST_ASSERT(TEST) \
Chris Jonesa6d155f2021-02-09 12:09:33 +000066 do { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010067 if (!(TEST)) \
68 { \
69 mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
70 goto exit; \
71 } \
72 } while (0)
Chris Jonesa6d155f2021-02-09 12:09:33 +000073
Agathiyan Bragadeesh27e29892023-07-14 17:28:27 +010074/** This macro asserts fails the test with given output message.
75 *
76 * \param MESSAGE The message to be outputed on assertion
77 */
78#define TEST_FAIL(MESSAGE) \
79 do { \
80 mbedtls_test_fail(MESSAGE, __LINE__, __FILE__); \
Agathiyan Bragadeesh1dd20a32023-07-21 17:07:00 +010081 goto exit; \
82 } while (0)
Agathiyan Bragadeesh27e29892023-07-14 17:28:27 +010083
Gilles Peskineb4366492021-04-29 20:28:54 +020084/** Evaluate two integer expressions and fail the test case if they have
85 * different values.
Chris Jonesa6d155f2021-02-09 12:09:33 +000086 *
Gilles Peskineb4366492021-04-29 20:28:54 +020087 * The two expressions should have the same signedness, otherwise the
88 * comparison is not meaningful if the signed value is negative.
89 *
90 * \param expr1 An integral-typed expression to evaluate.
91 * \param expr2 Another integral-typed expression to evaluate.
Chris Jonesa6d155f2021-02-09 12:09:33 +000092 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010093#define TEST_EQUAL(expr1, expr2) \
Gilles Peskineb4366492021-04-29 20:28:54 +020094 do { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010095 if (!mbedtls_test_equal( #expr1 " == " #expr2, __LINE__, __FILE__, \
96 expr1, expr2)) \
97 goto exit; \
98 } while (0)
Chris Jonesa6d155f2021-02-09 12:09:33 +000099
Gilles Peskine063700d2022-04-13 23:59:52 +0200100/** Evaluate two unsigned integer expressions and fail the test case
101 * if they are not in increasing order (left <= right).
102 *
103 * \param expr1 An integral-typed expression to evaluate.
104 * \param expr2 Another integral-typed expression to evaluate.
105 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100106#define TEST_LE_U(expr1, expr2) \
Gilles Peskine063700d2022-04-13 23:59:52 +0200107 do { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100108 if (!mbedtls_test_le_u( #expr1 " <= " #expr2, __LINE__, __FILE__, \
109 expr1, expr2)) \
110 goto exit; \
111 } while (0)
Gilles Peskine063700d2022-04-13 23:59:52 +0200112
113/** Evaluate two signed integer expressions and fail the test case
114 * if they are not in increasing order (left <= right).
115 *
116 * \param expr1 An integral-typed expression to evaluate.
117 * \param expr2 Another integral-typed expression to evaluate.
118 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100119#define TEST_LE_S(expr1, expr2) \
Gilles Peskine063700d2022-04-13 23:59:52 +0200120 do { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100121 if (!mbedtls_test_le_s( #expr1 " <= " #expr2, __LINE__, __FILE__, \
122 expr1, expr2)) \
123 goto exit; \
124 } while (0)
Gilles Peskine063700d2022-04-13 23:59:52 +0200125
Chris Jonesa6d155f2021-02-09 12:09:33 +0000126/** Allocate memory dynamically and fail the test case if this fails.
127 * The allocated memory will be filled with zeros.
128 *
129 * You must set \p pointer to \c NULL before calling this macro and
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100130 * put `mbedtls_free(pointer)` in the test's cleanup code.
Chris Jonesa6d155f2021-02-09 12:09:33 +0000131 *
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100132 * If \p item_count is zero, the resulting \p pointer will be \c NULL.
Chris Jonesa6d155f2021-02-09 12:09:33 +0000133 * This is usually what we want in tests since API functions are
134 * supposed to accept null pointers when a buffer size is zero.
135 *
136 * This macro expands to an instruction, not an expression.
137 * It may jump to the \c exit label.
138 *
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100139 * \param pointer An lvalue where the address of the allocated buffer
140 * will be stored.
141 * This expression may be evaluated multiple times.
142 * \param item_count Number of elements to allocate.
143 * This expression may be evaluated multiple times.
Chris Jonesa6d155f2021-02-09 12:09:33 +0000144 *
145 */
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100146#define TEST_CALLOC(pointer, item_count) \
Tom Cosgrove13575022023-09-04 11:05:59 +0100147 do { \
148 TEST_ASSERT((pointer) == NULL); \
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100149 if ((item_count) != 0) { \
Tom Cosgrove13575022023-09-04 11:05:59 +0100150 (pointer) = mbedtls_calloc(sizeof(*(pointer)), \
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100151 (item_count)); \
Tom Cosgrove13575022023-09-04 11:05:59 +0100152 TEST_ASSERT((pointer) != NULL); \
153 } \
154 } while (0)
155
Dave Rodgman72aa6832023-09-19 17:34:39 +0100156/** Allocate memory dynamically and fail the test case if this fails.
157 * The allocated memory will be filled with zeros.
158 *
159 * You must set \p pointer to \c NULL before calling this macro and
160 * put `mbedtls_free(pointer)` in the test's cleanup code.
161 *
162 * If \p item_count is zero, the resulting \p pointer will not be \c NULL.
163 *
164 * This macro expands to an instruction, not an expression.
165 * It may jump to the \c exit label.
166 *
167 * \param pointer An lvalue where the address of the allocated buffer
168 * will be stored.
169 * This expression may be evaluated multiple times.
170 * \param item_count Number of elements to allocate.
171 * This expression may be evaluated multiple times.
172 *
Dave Rodgman3ca2f5c2023-09-19 18:30:25 +0100173 * Note: if passing size 0, mbedtls_calloc may return NULL. In this case,
174 * we reattempt to allocate with the smallest possible buffer to assure a
175 * non-NULL pointer.
Dave Rodgman72aa6832023-09-19 17:34:39 +0100176 */
177#define TEST_CALLOC_NONNULL(pointer, item_count) \
178 do { \
179 TEST_ASSERT((pointer) == NULL); \
180 (pointer) = mbedtls_calloc(sizeof(*(pointer)), \
181 (item_count)); \
Dave Rodgman3ca2f5c2023-09-19 18:30:25 +0100182 if (((pointer) == NULL) && ((item_count) == 0)) { \
183 (pointer) = mbedtls_calloc(1, 1); \
184 } \
Dave Rodgman72aa6832023-09-19 17:34:39 +0100185 TEST_ASSERT((pointer) != NULL); \
186 } while (0)
187
Tom Cosgrove13575022023-09-04 11:05:59 +0100188/* For backwards compatibility */
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100189#define ASSERT_ALLOC(pointer, item_count) TEST_CALLOC(pointer, item_count)
Chris Jonesa6d155f2021-02-09 12:09:33 +0000190
191/** Allocate memory dynamically. If the allocation fails, skip the test case.
192 *
Tom Cosgrove30ceb232023-09-04 11:20:19 +0100193 * This macro behaves like #TEST_CALLOC, except that if the allocation
Chris Jonesa6d155f2021-02-09 12:09:33 +0000194 * fails, it marks the test as skipped rather than failed.
195 */
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100196#define TEST_CALLOC_OR_SKIP(pointer, item_count) \
Tom Cosgrove20e27de2023-09-04 11:09:08 +0100197 do { \
198 TEST_ASSERT((pointer) == NULL); \
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100199 if ((item_count) != 0) { \
Tom Cosgrove20e27de2023-09-04 11:09:08 +0100200 (pointer) = mbedtls_calloc(sizeof(*(pointer)), \
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100201 (item_count)); \
Tom Cosgrove20e27de2023-09-04 11:09:08 +0100202 TEST_ASSUME((pointer) != NULL); \
203 } \
204 } while (0)
205
206/* For backwards compatibility */
Tom Cosgrovecd5a7c72023-07-21 11:34:44 +0100207#define ASSERT_ALLOC_WEAK(pointer, item_count) TEST_CALLOC_OR_SKIP(pointer, item_count)
Chris Jonesa6d155f2021-02-09 12:09:33 +0000208
209/** Compare two buffers and fail the test case if they differ.
210 *
211 * This macro expands to an instruction, not an expression.
212 * It may jump to the \c exit label.
213 *
214 * \param p1 Pointer to the start of the first buffer.
215 * \param size1 Size of the first buffer in bytes.
216 * This expression may be evaluated multiple times.
217 * \param p2 Pointer to the start of the second buffer.
218 * \param size2 Size of the second buffer in bytes.
219 * This expression may be evaluated multiple times.
220 */
Tom Cosgroveba3b14d2023-09-04 11:23:02 +0100221#define TEST_MEMORY_COMPARE(p1, size1, p2, size2) \
Tom Cosgrovef88ee8b2023-09-04 11:04:40 +0100222 do { \
Manuel Pégourié-Gonnard3c301912023-02-09 09:15:04 +0100223 TEST_EQUAL((size1), (size2)); \
Tom Cosgrovef88ee8b2023-09-04 11:04:40 +0100224 if ((size1) != 0) { \
225 TEST_ASSERT(memcmp((p1), (p2), (size1)) == 0); \
226 } \
227 } while (0)
228
229/* For backwards compatibility */
Tom Cosgroveba3b14d2023-09-04 11:23:02 +0100230#define ASSERT_COMPARE(p1, size1, p2, size2) TEST_MEMORY_COMPARE(p1, size1, p2, size2)
Chris Jonesa6d155f2021-02-09 12:09:33 +0000231
232/**
233 * \brief This macro tests the expression passed to it and skips the
234 * running test if it doesn't evaluate to 'true'.
235 *
236 * \param TEST The test expression to be tested.
237 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100238#define TEST_ASSUME(TEST) \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000239 do { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100240 if (!(TEST)) \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000241 { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100242 mbedtls_test_skip( #TEST, __LINE__, __FILE__); \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000243 goto exit; \
244 } \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100245 } while (0)
Chris Jonesa6d155f2021-02-09 12:09:33 +0000246
247#if defined(MBEDTLS_CHECK_PARAMS) && !defined(MBEDTLS_PARAM_FAILED_ALT)
248/**
249 * \brief This macro tests the statement passed to it as a test step or
250 * individual test in a test case. The macro assumes the test will fail
251 * and will generate an error.
252 *
253 * It allows a library function to return a value and tests the return
254 * code on return to confirm the given error code was returned.
255 *
256 * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
257 * callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
258 * expected failure, and the test will pass.
259 *
260 * This macro is intended for negative parameter validation tests,
261 * where the failing function may return an error value or call
262 * MBEDTLS_PARAM_FAILED() to indicate the error.
263 *
264 * \param PARAM_ERROR_VALUE The expected error code.
265 *
266 * \param TEST The test expression to be tested.
267 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100268#define TEST_INVALID_PARAM_RET(PARAM_ERR_VALUE, TEST) \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000269 do { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100270 mbedtls_test_param_failed_expect_call(); \
271 if (((TEST) != (PARAM_ERR_VALUE)) || \
272 (mbedtls_test_param_failed_check_expected_call() != 0)) \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000273 { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100274 mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000275 goto exit; \
276 } \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100277 mbedtls_test_param_failed_check_expected_call(); \
278 } while (0)
Chris Jonesa6d155f2021-02-09 12:09:33 +0000279
280/**
281 * \brief This macro tests the statement passed to it as a test step or
282 * individual test in a test case. The macro assumes the test will fail
283 * and will generate an error.
284 *
285 * It assumes the library function under test cannot return a value and
286 * assumes errors can only be indicated byt calls to
287 * MBEDTLS_PARAM_FAILED().
288 *
289 * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
290 * callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
291 * expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
292 * can be made.
293 *
294 * This macro is intended for negative parameter validation tests,
295 * where the failing function can only return an error by calling
296 * MBEDTLS_PARAM_FAILED() to indicate the error.
297 *
298 * \param TEST The test expression to be tested.
299 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100300#define TEST_INVALID_PARAM(TEST) \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000301 do { \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100302 memcpy(jmp_tmp, mbedtls_test_param_failed_get_state_buf(), \
303 sizeof(jmp_tmp)); \
304 if (setjmp(mbedtls_test_param_failed_get_state_buf()) == 0) \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000305 { \
306 TEST; \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100307 mbedtls_test_fail( #TEST, __LINE__, __FILE__); \
Chris Jonesa6d155f2021-02-09 12:09:33 +0000308 goto exit; \
309 } \
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100310 mbedtls_test_param_failed_reset_state(); \
311 } while (0)
Chris Jonesa6d155f2021-02-09 12:09:33 +0000312#endif /* MBEDTLS_CHECK_PARAMS && !MBEDTLS_PARAM_FAILED_ALT */
313
314/**
315 * \brief This macro tests the statement passed to it as a test step or
316 * individual test in a test case. The macro assumes the test will not fail.
317 *
318 * It assumes the library function under test cannot return a value and
319 * assumes errors can only be indicated by calls to
320 * MBEDTLS_PARAM_FAILED().
321 *
322 * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
323 * callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
324 * expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
325 * can be made.
326 *
327 * This macro is intended to test that functions returning void
328 * accept all of the parameter values they're supposed to accept - eg
329 * that they don't call MBEDTLS_PARAM_FAILED() when a parameter
330 * that's allowed to be NULL happens to be NULL.
331 *
332 * Note: for functions that return something other that void,
333 * checking that they accept all the parameters they're supposed to
334 * accept is best done by using TEST_ASSERT() and checking the return
335 * value as well.
336 *
337 * Note: this macro is available even when #MBEDTLS_CHECK_PARAMS is
338 * disabled, as it makes sense to check that the functions accept all
339 * legal values even if this option is disabled - only in that case,
340 * the test is more about whether the function segfaults than about
341 * whether it invokes MBEDTLS_PARAM_FAILED().
342 *
343 * \param TEST The test expression to be tested.
344 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100345#define TEST_VALID_PARAM(TEST) \
346 TEST_ASSERT((TEST, 1));
Chris Jonesa6d155f2021-02-09 12:09:33 +0000347
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100348#define TEST_HELPER_ASSERT(a) if (!(a)) \
349 { \
350 mbedtls_fprintf(stderr, "Assertion Failed at %s:%d - %s\n", \
351 __FILE__, __LINE__, #a); \
352 mbedtls_exit(1); \
353 }
Ronald Cron849930a2020-06-03 08:06:47 +0200354
Gilles Peskinec86a1652021-02-15 12:17:00 +0100355/** \def ARRAY_LENGTH
356 * Return the number of elements of a static or stack array.
357 *
358 * \param array A value of array (not pointer) type.
359 *
360 * \return The number of elements of the array.
361 */
362/* A correct implementation of ARRAY_LENGTH, but which silently gives
363 * a nonsensical result if called with a pointer rather than an array. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100364#define ARRAY_LENGTH_UNSAFE(array) \
365 (sizeof(array) / sizeof(*(array)))
Gilles Peskinec86a1652021-02-15 12:17:00 +0100366
Ronald Cron849930a2020-06-03 08:06:47 +0200367#if defined(__GNUC__)
368/* Test if arg and &(arg)[0] have the same type. This is true if arg is
369 * an array but not if it's a pointer. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100370#define IS_ARRAY_NOT_POINTER(arg) \
371 (!__builtin_types_compatible_p(__typeof__(arg), \
372 __typeof__(&(arg)[0])))
Ronald Cron849930a2020-06-03 08:06:47 +0200373/* A compile-time constant with the value 0. If `const_expr` is not a
374 * compile-time constant with a nonzero value, cause a compile-time error. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100375#define STATIC_ASSERT_EXPR(const_expr) \
376 (0 && sizeof(struct { unsigned int STATIC_ASSERT : 1 - 2 * !(const_expr); }))
Gilles Peskinec86a1652021-02-15 12:17:00 +0100377
Ronald Cron849930a2020-06-03 08:06:47 +0200378/* Return the scalar value `value` (possibly promoted). This is a compile-time
379 * constant if `value` is. `condition` must be a compile-time constant.
380 * If `condition` is false, arrange to cause a compile-time error. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100381#define STATIC_ASSERT_THEN_RETURN(condition, value) \
382 (STATIC_ASSERT_EXPR(condition) ? 0 : (value))
Ronald Cron849930a2020-06-03 08:06:47 +0200383
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100384#define ARRAY_LENGTH(array) \
385 (STATIC_ASSERT_THEN_RETURN(IS_ARRAY_NOT_POINTER(array), \
386 ARRAY_LENGTH_UNSAFE(array)))
Ronald Cron849930a2020-06-03 08:06:47 +0200387
Gilles Peskinec86a1652021-02-15 12:17:00 +0100388#else
389/* If we aren't sure the compiler supports our non-standard tricks,
390 * fall back to the unsafe implementation. */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100391#define ARRAY_LENGTH(array) ARRAY_LENGTH_UNSAFE(array)
Gilles Peskinec86a1652021-02-15 12:17:00 +0100392#endif
393
Ronald Cron849930a2020-06-03 08:06:47 +0200394/** Return the smaller of two values.
395 *
396 * \param x An integer-valued expression without side effects.
397 * \param y An integer-valued expression without side effects.
398 *
399 * \return The smaller of \p x and \p y.
400 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100401#define MIN(x, y) ((x) < (y) ? (x) : (y))
Ronald Cron849930a2020-06-03 08:06:47 +0200402
403/** Return the larger of two values.
404 *
405 * \param x An integer-valued expression without side effects.
406 * \param y An integer-valued expression without side effects.
407 *
408 * \return The larger of \p x and \p y.
409 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100410#define MAX(x, y) ((x) > (y) ? (x) : (y))
Ronald Cron849930a2020-06-03 08:06:47 +0200411
412/*
413 * 32-bit integer manipulation macros (big endian)
414 */
415#ifndef GET_UINT32_BE
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100416#define GET_UINT32_BE(n, b, i) \
417 { \
418 (n) = ((uint32_t) (b)[(i)] << 24) \
419 | ((uint32_t) (b)[(i) + 1] << 16) \
420 | ((uint32_t) (b)[(i) + 2] << 8) \
421 | ((uint32_t) (b)[(i) + 3]); \
422 }
Ronald Cron849930a2020-06-03 08:06:47 +0200423#endif
424
425#ifndef PUT_UINT32_BE
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100426#define PUT_UINT32_BE(n, b, i) \
427 { \
428 (b)[(i)] = (unsigned char) ((n) >> 24); \
429 (b)[(i) + 1] = (unsigned char) ((n) >> 16); \
430 (b)[(i) + 2] = (unsigned char) ((n) >> 8); \
431 (b)[(i) + 3] = (unsigned char) ((n)); \
432 }
Ronald Cron849930a2020-06-03 08:06:47 +0200433#endif
434
Ronald Cron4b8b1992020-06-09 13:52:23 +0200435#endif /* TEST_MACROS_H */