Bitcoin Core  24.99.0
P2P Digital Currency
Classes | Macros | Functions | Variables
util.h File Reference
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  secp256k1_callback
 

Macros

#define STR_(x)   #x
 
#define STR(x)   STR_(x)
 
#define DEBUG_CONFIG_MSG(x)   "DEBUG_CONFIG: " x
 
#define DEBUG_CONFIG_DEF(x)   DEBUG_CONFIG_MSG(#x "=" STR(x))
 
#define TEST_FAILURE(msg)
 
#define EXPECT(x, c)   (x)
 
#define CHECK(cond)
 
#define VERIFY_CHECK(cond)   do { (void)(cond); } while(0)
 
#define VERIFY_SETUP(stmt)
 
#define VG_UNDEF(x, y)
 
#define VG_CHECK(x, y)
 
#define VG_CHECK_VERIFY(x, y)
 
#define ALIGNMENT   16
 
#define ROUND_TO_ALIGN(size)   ((((size) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT)
 
#define SECP256K1_RESTRICT
 
#define I64FORMAT   "lld"
 
#define I64uFORMAT   "llu"
 
#define SECP256K1_GNUC_EXT
 
#define SECP256K1_WIDEMUL_INT64   1
 
#define __has_builtin(x)   0
 

Functions

static SECP256K1_INLINE void secp256k1_callback_call (const secp256k1_callback *const cb, const char *const text)
 
static void secp256k1_default_illegal_callback_fn (const char *str, void *data)
 
static void secp256k1_default_error_callback_fn (const char *str, void *data)
 
static SECP256K1_INLINE void * checked_malloc (const secp256k1_callback *cb, size_t size)
 
static SECP256K1_INLINE void * checked_realloc (const secp256k1_callback *cb, void *ptr, size_t size)
 
static SECP256K1_INLINE void secp256k1_memczero (void *s, size_t len, int flag)
 
static SECP256K1_INLINE int secp256k1_memcmp_var (const void *s1, const void *s2, size_t n)
 Semantics like memcmp. More...
 
static SECP256K1_INLINE void secp256k1_int_cmov (int *r, const int *a, int flag)
 If flag is true, set *r equal to *a; otherwise leave it. More...
 
static SECP256K1_INLINE int secp256k1_ctz32_var_debruijn (uint32_t x)
 
static SECP256K1_INLINE int secp256k1_ctz64_var_debruijn (uint64_t x)
 
static SECP256K1_INLINE int secp256k1_ctz32_var (uint32_t x)
 
static SECP256K1_INLINE int secp256k1_ctz64_var (uint64_t x)
 
static SECP256K1_INLINE uint32_t secp256k1_read_be32 (const unsigned char *p)
 
static SECP256K1_INLINE void secp256k1_write_be32 (unsigned char *p, uint32_t x)
 

Variables

static const secp256k1_callback default_illegal_callback
 
static const secp256k1_callback default_error_callback
 

Macro Definition Documentation

◆ __has_builtin

#define __has_builtin (   x)    0

Definition at line 265 of file util.h.

◆ ALIGNMENT

#define ALIGNMENT   16

Definition at line 145 of file util.h.

◆ CHECK

#define CHECK (   cond)
Value:
do { \
if (EXPECT(!(cond), 0)) { \
TEST_FAILURE("test condition failed: " #cond); \
} \
} while(0)
#define EXPECT(x, c)
Definition: util.h:75

Definition at line 85 of file util.h.

◆ DEBUG_CONFIG_DEF

#define DEBUG_CONFIG_DEF (   x)    DEBUG_CONFIG_MSG(#x "=" STR(x))

Definition at line 22 of file util.h.

◆ DEBUG_CONFIG_MSG

#define DEBUG_CONFIG_MSG (   x)    "DEBUG_CONFIG: " x

Definition at line 21 of file util.h.

◆ EXPECT

#define EXPECT (   x,
 
)    (x)

Definition at line 75 of file util.h.

◆ I64FORMAT

#define I64FORMAT   "lld"

Definition at line 171 of file util.h.

◆ I64uFORMAT

#define I64uFORMAT   "llu"

Definition at line 172 of file util.h.

◆ ROUND_TO_ALIGN

#define ROUND_TO_ALIGN (   size)    ((((size) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT)

Definition at line 148 of file util.h.

◆ SECP256K1_GNUC_EXT

#define SECP256K1_GNUC_EXT

Definition at line 178 of file util.h.

◆ SECP256K1_RESTRICT

#define SECP256K1_RESTRICT

Definition at line 160 of file util.h.

◆ SECP256K1_WIDEMUL_INT64

#define SECP256K1_WIDEMUL_INT64   1

Definition at line 261 of file util.h.

◆ STR

#define STR (   x)    STR_(x)

Definition at line 20 of file util.h.

◆ STR_

#define STR_ (   x)    #x

Definition at line 19 of file util.h.

◆ TEST_FAILURE

#define TEST_FAILURE (   msg)
Value:
do { \
fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \
abort(); \
} while(0)

Definition at line 66 of file util.h.

◆ VERIFY_CHECK

#define VERIFY_CHECK (   cond)    do { (void)(cond); } while(0)

Definition at line 100 of file util.h.

◆ VERIFY_SETUP

#define VERIFY_SETUP (   stmt)

Definition at line 101 of file util.h.

◆ VG_CHECK

#define VG_CHECK (   x,
 
)

Definition at line 112 of file util.h.

◆ VG_CHECK_VERIFY

#define VG_CHECK_VERIFY (   x,
 
)

Definition at line 120 of file util.h.

◆ VG_UNDEF

#define VG_UNDEF (   x,
 
)

Definition at line 111 of file util.h.

Function Documentation

◆ checked_malloc()

static SECP256K1_INLINE void* checked_malloc ( const secp256k1_callback cb,
size_t  size 
)
static

Definition at line 123 of file util.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checked_realloc()

static SECP256K1_INLINE void* checked_realloc ( const secp256k1_callback cb,
void *  ptr,
size_t  size 
)
static

Definition at line 131 of file util.h.

Here is the call graph for this function:

◆ secp256k1_callback_call()

static SECP256K1_INLINE void secp256k1_callback_call ( const secp256k1_callback *const  cb,
const char *const  text 
)
static

Definition at line 29 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_ctz32_var()

static SECP256K1_INLINE int secp256k1_ctz32_var ( uint32_t  x)
static

Definition at line 294 of file util.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secp256k1_ctz32_var_debruijn()

static SECP256K1_INLINE int secp256k1_ctz32_var_debruijn ( uint32_t  x)
static

Definition at line 271 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_ctz64_var()

static SECP256K1_INLINE int secp256k1_ctz64_var ( uint64_t  x)
static

Definition at line 312 of file util.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secp256k1_ctz64_var_debruijn()

static SECP256K1_INLINE int secp256k1_ctz64_var_debruijn ( uint64_t  x)
static

Definition at line 283 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_default_error_callback_fn()

static void secp256k1_default_error_callback_fn ( const char *  str,
void *  data 
)
static

Definition at line 39 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_default_illegal_callback_fn()

static void secp256k1_default_illegal_callback_fn ( const char *  str,
void *  data 
)
static

Definition at line 34 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_int_cmov()

static SECP256K1_INLINE void secp256k1_int_cmov ( int *  r,
const int *  a,
int  flag 
)
static

If flag is true, set *r equal to *a; otherwise leave it.

Constant-time. Both *r and *a must be initialized and non-negative.

Definition at line 215 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_memcmp_var()

static SECP256K1_INLINE int secp256k1_memcmp_var ( const void *  s1,
const void *  s2,
size_t  n 
)
static

Semantics like memcmp.

Variable-time.

We use this to avoid possible compiler bugs with memcmp, e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189

Definition at line 201 of file util.h.

◆ secp256k1_memczero()

static SECP256K1_INLINE void secp256k1_memczero ( void *  s,
size_t  len,
int  flag 
)
static

Definition at line 182 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_read_be32()

static SECP256K1_INLINE uint32_t secp256k1_read_be32 ( const unsigned char *  p)
static

Definition at line 330 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_write_be32()

static SECP256K1_INLINE void secp256k1_write_be32 ( unsigned char *  p,
uint32_t  x 
)
static

Definition at line 338 of file util.h.

Here is the caller graph for this function:

Variable Documentation

◆ default_error_callback

const secp256k1_callback default_error_callback
static
Initial value:
= {
NULL
}
static void secp256k1_default_error_callback_fn(const char *str, void *data)
Definition: util.h:39

Definition at line 54 of file util.h.

◆ default_illegal_callback

const secp256k1_callback default_illegal_callback
static
Initial value:
= {
NULL
}
static void secp256k1_default_illegal_callback_fn(const char *str, void *data)
Definition: util.h:34

Definition at line 49 of file util.h.