Coverage Report

Created: 2023-12-10 07:59

/src/mbedtls/library/common.h
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * \file common.h
3
 *
4
 * \brief Utility macros for internal use in the library
5
 */
6
/*
7
 *  Copyright The Mbed TLS Contributors
8
 *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9
 */
10
11
#ifndef MBEDTLS_LIBRARY_COMMON_H
12
#define MBEDTLS_LIBRARY_COMMON_H
13
14
#include "mbedtls/build_info.h"
15
#include "alignment.h"
16
17
#include <assert.h>
18
#include <stddef.h>
19
#include <stdint.h>
20
#include <stddef.h>
21
22
#if defined(__ARM_NEON)
23
#include <arm_neon.h>
24
#define MBEDTLS_HAVE_NEON_INTRINSICS
25
#elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64)
26
#include <arm64_neon.h>
27
#define MBEDTLS_HAVE_NEON_INTRINSICS
28
#endif
29
30
31
#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \
32
    && !defined(__llvm__) && !defined(__INTEL_COMPILER)
33
/* Defined if the compiler really is gcc and not clang, etc */
34
#define MBEDTLS_COMPILER_IS_GCC
35
#define MBEDTLS_GCC_VERSION \
36
    (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
37
#endif
38
39
/** Helper to define a function as static except when building invasive tests.
40
 *
41
 * If a function is only used inside its own source file and should be
42
 * declared `static` to allow the compiler to optimize for code size,
43
 * but that function has unit tests, define it with
44
 * ```
45
 * MBEDTLS_STATIC_TESTABLE int mbedtls_foo(...) { ... }
46
 * ```
47
 * and declare it in a header in the `library/` directory with
48
 * ```
49
 * #if defined(MBEDTLS_TEST_HOOKS)
50
 * int mbedtls_foo(...);
51
 * #endif
52
 * ```
53
 */
54
#if defined(MBEDTLS_TEST_HOOKS)
55
#define MBEDTLS_STATIC_TESTABLE
56
#else
57
#define MBEDTLS_STATIC_TESTABLE static
58
#endif
59
60
#if defined(MBEDTLS_TEST_HOOKS)
61
extern void (*mbedtls_test_hook_test_fail)(const char *test, int line, const char *file);
62
#define MBEDTLS_TEST_HOOK_TEST_ASSERT(TEST) \
63
0
    do { \
64
0
        if ((!(TEST)) && ((*mbedtls_test_hook_test_fail) != NULL)) \
65
0
        { \
66
0
            (*mbedtls_test_hook_test_fail)( #TEST, __LINE__, __FILE__); \
67
0
        } \
68
0
    } while (0)
69
#else
70
#define MBEDTLS_TEST_HOOK_TEST_ASSERT(TEST)
71
#endif /* defined(MBEDTLS_TEST_HOOKS) */
72
73
/** \def ARRAY_LENGTH
74
 * Return the number of elements of a static or stack array.
75
 *
76
 * \param array         A value of array (not pointer) type.
77
 *
78
 * \return The number of elements of the array.
79
 */
80
/* A correct implementation of ARRAY_LENGTH, but which silently gives
81
 * a nonsensical result if called with a pointer rather than an array. */
82
#define ARRAY_LENGTH_UNSAFE(array)            \
83
    (sizeof(array) / sizeof(*(array)))
84
85
#if defined(__GNUC__)
86
/* Test if arg and &(arg)[0] have the same type. This is true if arg is
87
 * an array but not if it's a pointer. */
88
#define IS_ARRAY_NOT_POINTER(arg)                                     \
89
    (!__builtin_types_compatible_p(__typeof__(arg),                \
90
                                   __typeof__(&(arg)[0])))
91
/* A compile-time constant with the value 0. If `const_expr` is not a
92
 * compile-time constant with a nonzero value, cause a compile-time error. */
93
#define STATIC_ASSERT_EXPR(const_expr)                                \
94
0
    (0 && sizeof(struct { unsigned int STATIC_ASSERT : 1 - 2 * !(const_expr); }))
95
96
/* Return the scalar value `value` (possibly promoted). This is a compile-time
97
 * constant if `value` is. `condition` must be a compile-time constant.
98
 * If `condition` is false, arrange to cause a compile-time error. */
99
#define STATIC_ASSERT_THEN_RETURN(condition, value)   \
100
0
    (STATIC_ASSERT_EXPR(condition) ? 0 : (value))
101
102
#define ARRAY_LENGTH(array)                                           \
103
0
    (STATIC_ASSERT_THEN_RETURN(IS_ARRAY_NOT_POINTER(array),         \
104
0
                               ARRAY_LENGTH_UNSAFE(array)))
105
106
#else
107
/* If we aren't sure the compiler supports our non-standard tricks,
108
 * fall back to the unsafe implementation. */
109
#define ARRAY_LENGTH(array) ARRAY_LENGTH_UNSAFE(array)
110
#endif
111
/** Allow library to access its structs' private members.
112
 *
113
 * Although structs defined in header files are publicly available,
114
 * their members are private and should not be accessed by the user.
115
 */
116
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
117
118
/**
119
 * \brief       Securely zeroize a buffer then free it.
120
 *
121
 *              Similar to making consecutive calls to
122
 *              \c mbedtls_platform_zeroize() and \c mbedtls_free(), but has
123
 *              code size savings, and potential for optimisation in the future.
124
 *
125
 *              Guaranteed to be a no-op if \p buf is \c NULL and \p len is 0.
126
 *
127
 * \param buf   Buffer to be zeroized then freed.
128
 * \param len   Length of the buffer in bytes
129
 */
130
void mbedtls_zeroize_and_free(void *buf, size_t len);
131
132
/** Return an offset into a buffer.
133
 *
134
 * This is just the addition of an offset to a pointer, except that this
135
 * function also accepts an offset of 0 into a buffer whose pointer is null.
136
 * (`p + n` has undefined behavior when `p` is null, even when `n == 0`.
137
 * A null pointer is a valid buffer pointer when the size is 0, for example
138
 * as the result of `malloc(0)` on some platforms.)
139
 *
140
 * \param p     Pointer to a buffer of at least n bytes.
141
 *              This may be \p NULL if \p n is zero.
142
 * \param n     An offset in bytes.
143
 * \return      Pointer to offset \p n in the buffer \p p.
144
 *              Note that this is only a valid pointer if the size of the
145
 *              buffer is at least \p n + 1.
146
 */
147
static inline unsigned char *mbedtls_buffer_offset(
148
    unsigned char *p, size_t n)
149
0
{
150
0
    return p == NULL ? NULL : p + n;
151
0
}
Unexecuted instantiation: asn1_helpers.c:mbedtls_buffer_offset
Unexecuted instantiation: bignum_helpers.c:mbedtls_buffer_offset
Unexecuted instantiation: certs.c:mbedtls_buffer_offset
Unexecuted instantiation: helpers.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_helpers.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_exercise_key.c:mbedtls_buffer_offset
Unexecuted instantiation: random.c:mbedtls_buffer_offset
Unexecuted instantiation: threading_helpers.c:mbedtls_buffer_offset
Unexecuted instantiation: asn1parse.c:mbedtls_buffer_offset
Unexecuted instantiation: bignum.c:mbedtls_buffer_offset
Unexecuted instantiation: bignum_core.c:mbedtls_buffer_offset
Unexecuted instantiation: constant_time.c:mbedtls_buffer_offset
Unexecuted instantiation: ctr_drbg.c:mbedtls_buffer_offset
Unexecuted instantiation: ecp.c:mbedtls_buffer_offset
Unexecuted instantiation: ecp_curves.c:mbedtls_buffer_offset
Unexecuted instantiation: entropy.c:mbedtls_buffer_offset
Unexecuted instantiation: entropy_poll.c:mbedtls_buffer_offset
Unexecuted instantiation: md.c:mbedtls_buffer_offset
Unexecuted instantiation: md5.c:mbedtls_buffer_offset
Unexecuted instantiation: pk.c:mbedtls_buffer_offset
Unexecuted instantiation: pk_wrap.c:mbedtls_buffer_offset
Unexecuted instantiation: pkparse.c:mbedtls_buffer_offset
Unexecuted instantiation: pkwrite.c:mbedtls_buffer_offset
Unexecuted instantiation: platform.c:mbedtls_buffer_offset
Unexecuted instantiation: platform_util.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_aead.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_cipher.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_client.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_driver_wrappers_no_static.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_ecp.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_ffdh.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_hash.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_mac.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_pake.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_rsa.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_se.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_slot_management.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_crypto_storage.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_its_file.c:mbedtls_buffer_offset
Unexecuted instantiation: psa_util.c:mbedtls_buffer_offset
Unexecuted instantiation: ripemd160.c:mbedtls_buffer_offset
Unexecuted instantiation: rsa.c:mbedtls_buffer_offset
Unexecuted instantiation: rsa_alt_helpers.c:mbedtls_buffer_offset
Unexecuted instantiation: sha1.c:mbedtls_buffer_offset
Unexecuted instantiation: sha256.c:mbedtls_buffer_offset
Unexecuted instantiation: sha512.c:mbedtls_buffer_offset
Unexecuted instantiation: sha3.c:mbedtls_buffer_offset
Unexecuted instantiation: threading.c:mbedtls_buffer_offset
Unexecuted instantiation: aes.c:mbedtls_buffer_offset
Unexecuted instantiation: aesni.c:mbedtls_buffer_offset
Unexecuted instantiation: asn1write.c:mbedtls_buffer_offset
Unexecuted instantiation: ccm.c:mbedtls_buffer_offset
Unexecuted instantiation: chachapoly.c:mbedtls_buffer_offset
Unexecuted instantiation: cipher.c:mbedtls_buffer_offset
Unexecuted instantiation: cipher_wrap.c:mbedtls_buffer_offset
Unexecuted instantiation: cmac.c:mbedtls_buffer_offset
Unexecuted instantiation: des.c:mbedtls_buffer_offset
Unexecuted instantiation: ecdh.c:mbedtls_buffer_offset
Unexecuted instantiation: ecdsa.c:mbedtls_buffer_offset
Unexecuted instantiation: ecjpake.c:mbedtls_buffer_offset
Unexecuted instantiation: error.c:mbedtls_buffer_offset
Unexecuted instantiation: gcm.c:mbedtls_buffer_offset
Unexecuted instantiation: hmac_drbg.c:mbedtls_buffer_offset
Unexecuted instantiation: nist_kw.c:mbedtls_buffer_offset
Unexecuted instantiation: oid.c:mbedtls_buffer_offset
Unexecuted instantiation: pem.c:mbedtls_buffer_offset
Unexecuted instantiation: pkcs12.c:mbedtls_buffer_offset
Unexecuted instantiation: pkcs5.c:mbedtls_buffer_offset
Unexecuted instantiation: poly1305.c:mbedtls_buffer_offset
Unexecuted instantiation: aria.c:mbedtls_buffer_offset
Unexecuted instantiation: base64.c:mbedtls_buffer_offset
Unexecuted instantiation: camellia.c:mbedtls_buffer_offset
Unexecuted instantiation: chacha20.c:mbedtls_buffer_offset
152
153
/** Return an offset into a read-only buffer.
154
 *
155
 * Similar to mbedtls_buffer_offset(), but for const pointers.
156
 *
157
 * \param p     Pointer to a buffer of at least n bytes.
158
 *              This may be \p NULL if \p n is zero.
159
 * \param n     An offset in bytes.
160
 * \return      Pointer to offset \p n in the buffer \p p.
161
 *              Note that this is only a valid pointer if the size of the
162
 *              buffer is at least \p n + 1.
163
 */
164
static inline const unsigned char *mbedtls_buffer_offset_const(
165
    const unsigned char *p, size_t n)
166
0
{
167
0
    return p == NULL ? NULL : p + n;
168
0
}
Unexecuted instantiation: asn1_helpers.c:mbedtls_buffer_offset_const
Unexecuted instantiation: bignum_helpers.c:mbedtls_buffer_offset_const
Unexecuted instantiation: certs.c:mbedtls_buffer_offset_const
Unexecuted instantiation: helpers.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_helpers.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_exercise_key.c:mbedtls_buffer_offset_const
Unexecuted instantiation: random.c:mbedtls_buffer_offset_const
Unexecuted instantiation: threading_helpers.c:mbedtls_buffer_offset_const
Unexecuted instantiation: asn1parse.c:mbedtls_buffer_offset_const
Unexecuted instantiation: bignum.c:mbedtls_buffer_offset_const
Unexecuted instantiation: bignum_core.c:mbedtls_buffer_offset_const
Unexecuted instantiation: constant_time.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ctr_drbg.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ecp.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ecp_curves.c:mbedtls_buffer_offset_const
Unexecuted instantiation: entropy.c:mbedtls_buffer_offset_const
Unexecuted instantiation: entropy_poll.c:mbedtls_buffer_offset_const
Unexecuted instantiation: md.c:mbedtls_buffer_offset_const
Unexecuted instantiation: md5.c:mbedtls_buffer_offset_const
Unexecuted instantiation: pk.c:mbedtls_buffer_offset_const
Unexecuted instantiation: pk_wrap.c:mbedtls_buffer_offset_const
Unexecuted instantiation: pkparse.c:mbedtls_buffer_offset_const
Unexecuted instantiation: pkwrite.c:mbedtls_buffer_offset_const
Unexecuted instantiation: platform.c:mbedtls_buffer_offset_const
Unexecuted instantiation: platform_util.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_aead.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_cipher.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_client.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_driver_wrappers_no_static.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_ecp.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_ffdh.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_hash.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_mac.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_pake.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_rsa.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_se.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_slot_management.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_crypto_storage.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_its_file.c:mbedtls_buffer_offset_const
Unexecuted instantiation: psa_util.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ripemd160.c:mbedtls_buffer_offset_const
Unexecuted instantiation: rsa.c:mbedtls_buffer_offset_const
Unexecuted instantiation: rsa_alt_helpers.c:mbedtls_buffer_offset_const
Unexecuted instantiation: sha1.c:mbedtls_buffer_offset_const
Unexecuted instantiation: sha256.c:mbedtls_buffer_offset_const
Unexecuted instantiation: sha512.c:mbedtls_buffer_offset_const
Unexecuted instantiation: sha3.c:mbedtls_buffer_offset_const
Unexecuted instantiation: threading.c:mbedtls_buffer_offset_const
Unexecuted instantiation: aes.c:mbedtls_buffer_offset_const
Unexecuted instantiation: aesni.c:mbedtls_buffer_offset_const
Unexecuted instantiation: asn1write.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ccm.c:mbedtls_buffer_offset_const
Unexecuted instantiation: chachapoly.c:mbedtls_buffer_offset_const
Unexecuted instantiation: cipher.c:mbedtls_buffer_offset_const
Unexecuted instantiation: cipher_wrap.c:mbedtls_buffer_offset_const
Unexecuted instantiation: cmac.c:mbedtls_buffer_offset_const
Unexecuted instantiation: des.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ecdh.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ecdsa.c:mbedtls_buffer_offset_const
Unexecuted instantiation: ecjpake.c:mbedtls_buffer_offset_const
Unexecuted instantiation: error.c:mbedtls_buffer_offset_const
Unexecuted instantiation: gcm.c:mbedtls_buffer_offset_const
Unexecuted instantiation: hmac_drbg.c:mbedtls_buffer_offset_const
Unexecuted instantiation: nist_kw.c:mbedtls_buffer_offset_const
Unexecuted instantiation: oid.c:mbedtls_buffer_offset_const
Unexecuted instantiation: pem.c:mbedtls_buffer_offset_const
Unexecuted instantiation: pkcs12.c:mbedtls_buffer_offset_const
Unexecuted instantiation: pkcs5.c:mbedtls_buffer_offset_const
Unexecuted instantiation: poly1305.c:mbedtls_buffer_offset_const
Unexecuted instantiation: aria.c:mbedtls_buffer_offset_const
Unexecuted instantiation: base64.c:mbedtls_buffer_offset_const
Unexecuted instantiation: camellia.c:mbedtls_buffer_offset_const
Unexecuted instantiation: chacha20.c:mbedtls_buffer_offset_const
169
170
/**
171
 * Perform a fast block XOR operation, such that
172
 * r[i] = a[i] ^ b[i] where 0 <= i < n
173
 *
174
 * \param   r Pointer to result (buffer of at least \p n bytes). \p r
175
 *            may be equal to either \p a or \p b, but behaviour when
176
 *            it overlaps in other ways is undefined.
177
 * \param   a Pointer to input (buffer of at least \p n bytes)
178
 * \param   b Pointer to input (buffer of at least \p n bytes)
179
 * \param   n Number of bytes to process.
180
 */
181
inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned char *b, size_t n)
182
45.1k
{
183
45.1k
    size_t i = 0;
184
45.1k
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
185
#if defined(MBEDTLS_HAVE_NEON_INTRINSICS) && \
186
    (!(defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION < 70300))
187
    /* Old GCC versions generate a warning here, so disable the NEON path for these compilers */
188
    for (; (i + 16) <= n; i += 16) {
189
        uint8x16_t v1 = vld1q_u8(a + i);
190
        uint8x16_t v2 = vld1q_u8(b + i);
191
        uint8x16_t x = veorq_u8(v1, v2);
192
        vst1q_u8(r + i, x);
193
    }
194
#elif defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
195
    /* This codepath probably only makes sense on architectures with 64-bit registers */
196
135k
    for (; (i + 8) <= n; i += 8) {
197
90.2k
        uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
198
90.2k
        mbedtls_put_unaligned_uint64(r + i, x);
199
90.2k
    }
200
#else
201
    for (; (i + 4) <= n; i += 4) {
202
        uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
203
        mbedtls_put_unaligned_uint32(r + i, x);
204
    }
205
#endif
206
45.1k
#endif
207
45.1k
    for (; i < n; i++) {
208
0
        r[i] = a[i] ^ b[i];
209
0
    }
210
45.1k
}
211
212
/**
213
 * Perform a fast block XOR operation, such that
214
 * r[i] = a[i] ^ b[i] where 0 <= i < n
215
 *
216
 * In some situations, this can perform better than mbedtls_xor (e.g., it's about 5%
217
 * better in AES-CBC).
218
 *
219
 * \param   r Pointer to result (buffer of at least \p n bytes). \p r
220
 *            may be equal to either \p a or \p b, but behaviour when
221
 *            it overlaps in other ways is undefined.
222
 * \param   a Pointer to input (buffer of at least \p n bytes)
223
 * \param   b Pointer to input (buffer of at least \p n bytes)
224
 * \param   n Number of bytes to process.
225
 */
226
static inline void mbedtls_xor_no_simd(unsigned char *r,
227
                                       const unsigned char *a,
228
                                       const unsigned char *b,
229
                                       size_t n)
230
0
{
231
0
    size_t i = 0;
232
0
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
233
0
#if defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
234
    /* This codepath probably only makes sense on architectures with 64-bit registers */
235
0
    for (; (i + 8) <= n; i += 8) {
236
0
        uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i);
237
0
        mbedtls_put_unaligned_uint64(r + i, x);
238
0
    }
239
#else
240
    for (; (i + 4) <= n; i += 4) {
241
        uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
242
        mbedtls_put_unaligned_uint32(r + i, x);
243
    }
244
#endif
245
0
#endif
246
0
    for (; i < n; i++) {
247
0
        r[i] = a[i] ^ b[i];
248
0
    }
249
0
}
Unexecuted instantiation: asn1_helpers.c:mbedtls_xor_no_simd
Unexecuted instantiation: bignum_helpers.c:mbedtls_xor_no_simd
Unexecuted instantiation: certs.c:mbedtls_xor_no_simd
Unexecuted instantiation: helpers.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_helpers.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_exercise_key.c:mbedtls_xor_no_simd
Unexecuted instantiation: random.c:mbedtls_xor_no_simd
Unexecuted instantiation: threading_helpers.c:mbedtls_xor_no_simd
Unexecuted instantiation: asn1parse.c:mbedtls_xor_no_simd
Unexecuted instantiation: bignum.c:mbedtls_xor_no_simd
Unexecuted instantiation: bignum_core.c:mbedtls_xor_no_simd
Unexecuted instantiation: constant_time.c:mbedtls_xor_no_simd
Unexecuted instantiation: ctr_drbg.c:mbedtls_xor_no_simd
Unexecuted instantiation: ecp.c:mbedtls_xor_no_simd
Unexecuted instantiation: ecp_curves.c:mbedtls_xor_no_simd
Unexecuted instantiation: entropy.c:mbedtls_xor_no_simd
Unexecuted instantiation: entropy_poll.c:mbedtls_xor_no_simd
Unexecuted instantiation: md.c:mbedtls_xor_no_simd
Unexecuted instantiation: md5.c:mbedtls_xor_no_simd
Unexecuted instantiation: pk.c:mbedtls_xor_no_simd
Unexecuted instantiation: pk_wrap.c:mbedtls_xor_no_simd
Unexecuted instantiation: pkparse.c:mbedtls_xor_no_simd
Unexecuted instantiation: pkwrite.c:mbedtls_xor_no_simd
Unexecuted instantiation: platform.c:mbedtls_xor_no_simd
Unexecuted instantiation: platform_util.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_aead.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_cipher.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_client.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_driver_wrappers_no_static.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_ecp.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_ffdh.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_hash.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_mac.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_pake.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_rsa.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_se.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_slot_management.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_crypto_storage.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_its_file.c:mbedtls_xor_no_simd
Unexecuted instantiation: psa_util.c:mbedtls_xor_no_simd
Unexecuted instantiation: ripemd160.c:mbedtls_xor_no_simd
Unexecuted instantiation: rsa.c:mbedtls_xor_no_simd
Unexecuted instantiation: rsa_alt_helpers.c:mbedtls_xor_no_simd
Unexecuted instantiation: sha1.c:mbedtls_xor_no_simd
Unexecuted instantiation: sha256.c:mbedtls_xor_no_simd
Unexecuted instantiation: sha512.c:mbedtls_xor_no_simd
Unexecuted instantiation: sha3.c:mbedtls_xor_no_simd
Unexecuted instantiation: threading.c:mbedtls_xor_no_simd
Unexecuted instantiation: aes.c:mbedtls_xor_no_simd
Unexecuted instantiation: aesni.c:mbedtls_xor_no_simd
Unexecuted instantiation: asn1write.c:mbedtls_xor_no_simd
Unexecuted instantiation: ccm.c:mbedtls_xor_no_simd
Unexecuted instantiation: chachapoly.c:mbedtls_xor_no_simd
Unexecuted instantiation: cipher.c:mbedtls_xor_no_simd
Unexecuted instantiation: cipher_wrap.c:mbedtls_xor_no_simd
Unexecuted instantiation: cmac.c:mbedtls_xor_no_simd
Unexecuted instantiation: des.c:mbedtls_xor_no_simd
Unexecuted instantiation: ecdh.c:mbedtls_xor_no_simd
Unexecuted instantiation: ecdsa.c:mbedtls_xor_no_simd
Unexecuted instantiation: ecjpake.c:mbedtls_xor_no_simd
Unexecuted instantiation: error.c:mbedtls_xor_no_simd
Unexecuted instantiation: gcm.c:mbedtls_xor_no_simd
Unexecuted instantiation: hmac_drbg.c:mbedtls_xor_no_simd
Unexecuted instantiation: nist_kw.c:mbedtls_xor_no_simd
Unexecuted instantiation: oid.c:mbedtls_xor_no_simd
Unexecuted instantiation: pem.c:mbedtls_xor_no_simd
Unexecuted instantiation: pkcs12.c:mbedtls_xor_no_simd
Unexecuted instantiation: pkcs5.c:mbedtls_xor_no_simd
Unexecuted instantiation: poly1305.c:mbedtls_xor_no_simd
Unexecuted instantiation: aria.c:mbedtls_xor_no_simd
Unexecuted instantiation: base64.c:mbedtls_xor_no_simd
Unexecuted instantiation: camellia.c:mbedtls_xor_no_simd
Unexecuted instantiation: chacha20.c:mbedtls_xor_no_simd
250
251
/* Fix MSVC C99 compatible issue
252
 *      MSVC support __func__ from visual studio 2015( 1900 )
253
 *      Use MSVC predefine macro to avoid name check fail.
254
 */
255
#if (defined(_MSC_VER) && (_MSC_VER <= 1900))
256
#define /*no-check-names*/ __func__ __FUNCTION__
257
#endif
258
259
/* Define `asm` for compilers which don't define it. */
260
/* *INDENT-OFF* */
261
#ifndef asm
262
#if defined(__IAR_SYSTEMS_ICC__)
263
#define asm __asm
264
#else
265
43.1M
#define asm __asm__
266
#endif
267
#endif
268
/* *INDENT-ON* */
269
270
/*
271
 * Define the constraint used for read-only pointer operands to aarch64 asm.
272
 *
273
 * This is normally the usual "r", but for aarch64_32 (aka ILP32,
274
 * as found in watchos), "p" is required to avoid warnings from clang.
275
 *
276
 * Note that clang does not recognise '+p' or '=p', and armclang
277
 * does not recognise 'p' at all. Therefore, to update a pointer from
278
 * aarch64 assembly, it is necessary to use something like:
279
 *
280
 * uintptr_t uptr = (uintptr_t) ptr;
281
 * asm( "ldr x4, [%x0], #8" ... : "+r" (uptr) : : )
282
 * ptr = (void*) uptr;
283
 *
284
 * Note that the "x" in "%x0" is neccessary; writing "%0" will cause warnings.
285
 */
286
#if defined(__aarch64__) && defined(MBEDTLS_HAVE_ASM)
287
#if UINTPTR_MAX == 0xfffffffful
288
/* ILP32: Specify the pointer operand slightly differently, as per #7787. */
289
#define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "p"
290
#elif UINTPTR_MAX == 0xfffffffffffffffful
291
/* Normal case (64-bit pointers): use "r" as the constraint for pointer operands to asm */
292
#define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "r"
293
#else
294
#error "Unrecognised pointer size for aarch64"
295
#endif
296
#endif
297
298
/* Always provide a static assert macro, so it can be used unconditionally.
299
 * It will expand to nothing on some systems.
300
 * Can be used outside functions (but don't add a trailing ';' in that case:
301
 * the semicolon is included here to avoid triggering -Wextra-semi when
302
 * MBEDTLS_STATIC_ASSERT() expands to nothing).
303
 * Can't use the C11-style `defined(static_assert)` on FreeBSD, since it
304
 * defines static_assert even with -std=c99, but then complains about it.
305
 */
306
#if defined(static_assert) && !defined(__FreeBSD__)
307
#define MBEDTLS_STATIC_ASSERT(expr, msg)    static_assert(expr, msg);
308
#else
309
#define MBEDTLS_STATIC_ASSERT(expr, msg)
310
#endif
311
312
#if defined(__has_builtin)
313
#define MBEDTLS_HAS_BUILTIN(x) __has_builtin(x)
314
#else
315
#define MBEDTLS_HAS_BUILTIN(x) 0
316
#endif
317
318
/* Define compiler branch hints */
319
#if MBEDTLS_HAS_BUILTIN(__builtin_expect)
320
#define MBEDTLS_LIKELY(x)       __builtin_expect(!!(x), 1)
321
0
#define MBEDTLS_UNLIKELY(x)     __builtin_expect(!!(x), 0)
322
#else
323
#define MBEDTLS_LIKELY(x)       x
324
#define MBEDTLS_UNLIKELY(x)     x
325
#endif
326
327
/* MBEDTLS_ASSUME may be used to provide additional information to the compiler
328
 * which can result in smaller code-size. */
329
#if MBEDTLS_HAS_BUILTIN(__builtin_assume)
330
/* clang provides __builtin_assume */
331
0
#define MBEDTLS_ASSUME(x)       __builtin_assume(x)
332
#elif MBEDTLS_HAS_BUILTIN(__builtin_unreachable)
333
/* gcc and IAR can use __builtin_unreachable */
334
#define MBEDTLS_ASSUME(x)       do { if (!(x)) __builtin_unreachable(); } while (0)
335
#elif defined(_MSC_VER)
336
/* Supported by MSVC since VS 2005 */
337
#define MBEDTLS_ASSUME(x)       __assume(x)
338
#else
339
#define MBEDTLS_ASSUME(x)       do { } while (0)
340
#endif
341
342
/* For gcc -Os, override with -O2 for a given function.
343
 *
344
 * This will not affect behaviour for other optimisation settings, e.g. -O0.
345
 */
346
#if defined(MBEDTLS_COMPILER_IS_GCC) && defined(__OPTIMIZE_SIZE__)
347
#define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE __attribute__((optimize("-O2")))
348
#else
349
#define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
350
#endif
351
352
/* Suppress compiler warnings for unused functions and variables. */
353
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__has_attribute)
354
#    if __has_attribute(unused)
355
#        define MBEDTLS_MAYBE_UNUSED __attribute__((unused))
356
#    endif
357
#endif
358
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__GNUC__)
359
#    define MBEDTLS_MAYBE_UNUSED __attribute__((unused))
360
#endif
361
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__IAR_SYSTEMS_ICC__) && defined(__VER__)
362
/* IAR does support __attribute__((unused)), but only if the -e flag (extended language support)
363
 * is given; the pragma always works.
364
 * Unfortunately the pragma affects the rest of the file where it is used, but this is harmless.
365
 * Check for version 5.2 or later - this pragma may be supported by earlier versions, but I wasn't
366
 * able to find documentation).
367
 */
368
#    if (__VER__ >= 5020000)
369
#        define MBEDTLS_MAYBE_UNUSED _Pragma("diag_suppress=Pe177")
370
#    endif
371
#endif
372
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(_MSC_VER)
373
#    define MBEDTLS_MAYBE_UNUSED __pragma(warning(suppress:4189))
374
#endif
375
#if !defined(MBEDTLS_MAYBE_UNUSED)
376
#    define MBEDTLS_MAYBE_UNUSED
377
#endif
378
379
#endif /* MBEDTLS_LIBRARY_COMMON_H */