UltrafastSecp256k1 3.50.0
Ultra high-performance secp256k1 elliptic curve cryptography library
Loading...
Searching...
No Matches
sanitizer_scale.hpp
Go to the documentation of this file.
1// sanitizer_scale.hpp -- reduce test iteration counts under sanitizers
2// Sanitizers (ASan, TSan, UBSan) add 3-15x runtime overhead.
3// This header provides a compile-time flag and helper to scale down
4// iteration counts so tests finish within CI timeouts.
5//
6// Usage:
7// #include "secp256k1/sanitizer_scale.hpp"
8// const int N = SCALED(10000, 200); // 10000 normal, 200 under sanitizer
9
10#ifndef SECP256K1_SANITIZER_SCALE_HPP
11#define SECP256K1_SANITIZER_SCALE_HPP
12
13// Detect sanitizer builds (Clang, GCC, MSVC)
14#if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__)
15# define SECP256K1_SANITIZER_BUILD 1
16#elif defined(__has_feature)
17# if __has_feature(address_sanitizer) || __has_feature(thread_sanitizer) || \
18 __has_feature(memory_sanitizer) || __has_feature(undefined_behavior_sanitizer)
19# define SECP256K1_SANITIZER_BUILD 1
20# endif
21#endif
22
23#ifndef SECP256K1_SANITIZER_BUILD
24# define SECP256K1_SANITIZER_BUILD 0
25#endif
26
27// Detect embedded / resource-constrained targets
28#if defined(SECP256K1_PLATFORM_ESP32) || defined(ESP_PLATFORM) || defined(SECP256K1_PLATFORM_STM32)
29# define SECP256K1_EMBEDDED_BUILD 1
30#else
31# define SECP256K1_EMBEDDED_BUILD 0
32#endif
33
34// SCALED(normal, reduced) -- pick count based on build type
35// Uses reduced counts under sanitizers AND on embedded targets (ESP32, STM32)
36// where the 240 MHz CPU makes large iteration counts impractical.
37#define SCALED(normal, reduced) ((SECP256K1_SANITIZER_BUILD || SECP256K1_EMBEDDED_BUILD) ? (reduced) : (normal))
38
39#endif // SECP256K1_SANITIZER_SCALE_HPP