Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
util.h File Reference
#include "../include/secp256k1.h"
#include "checkmem.h"
#include <string.h>
#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)
#define STR(x)
#define DEBUG_CONFIG_MSG(x)
#define DEBUG_CONFIG_DEF(x)
#define PRINT_BUF(buf, len)
#define SECP256K1_INLINE
#define STATIC_ASSERT(expr)
 Assert statically that expr is true.
#define ASSERT_INT_CONST_AND_DO(expr, stmt)
 Assert statically that expr is an integer constant expression, and run stmt.
#define TEST_FAILURE(msg)
#define EXPECT(x, c)
#define CHECK(cond)
#define VERIFY_CHECK(cond)
#define ALIGNMENT   16
#define CEIL_DIV(x, y)
#define ROUND_TO_ALIGN(size)
#define SECP256K1_RESTRICT
#define SECP256K1_GNUC_EXT
#define SECP256K1_WIDEMUL_INT128   1
#define SECP256K1_INT128_STRUCT   1
#define __has_builtin(x)

Functions

static void print_buf_plain (const unsigned char *buf, size_t len)
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 secp256k1_memczero (void *s, size_t len, int flag)
static SECP256K1_INLINE void secp256k1_memzero_explicit (void *ptr, size_t len)
static SECP256K1_INLINE void secp256k1_memclear_explicit (void *ptr, size_t len)
static SECP256K1_INLINE int secp256k1_memcmp_var (const void *s1, const void *s2, size_t n)
 Semantics like memcmp.
static SECP256K1_INLINE int secp256k1_is_zero_array (const unsigned char *s, size_t len)
static SECP256K1_INLINE void secp256k1_int_cmov (int *r, const int *a, int flag)
 If flag is 1, set *r equal to *a; if flag is 0, leave it.
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)
static SECP256K1_INLINE uint64_t secp256k1_read_be64 (const unsigned char *p)
static SECP256K1_INLINE void secp256k1_write_be64 (unsigned char *p, uint64_t x)
static SECP256K1_INLINE uint32_t secp256k1_rotr32 (const uint32_t x, const unsigned int by)

Variables

static const secp256k1_callback default_illegal_callback
static const secp256k1_callback default_error_callback

Macro Definition Documentation

◆ __has_builtin

#define __has_builtin ( x)
Value:
0

Definition at line 351 of file util.h.

◆ ALIGNMENT

#define ALIGNMENT   16

Definition at line 176 of file util.h.

◆ ASSERT_INT_CONST_AND_DO

#define ASSERT_INT_CONST_AND_DO ( expr,
stmt )
Value:
do { \
switch(42) { \
/* C allows only integer constant expressions as case labels. */ \
case /* ERROR: integer argument is not constant */ (expr): \
break; \
default: ; \
} \
stmt; \
} while(0)

Assert statically that expr is an integer constant expression, and run stmt.

Useful for example to enforce that magnitude arguments are constant.

Definition at line 77 of file util.h.

◆ CEIL_DIV

#define CEIL_DIV ( x,
y )
Value:
(1 + ((x) - 1) / (y))

Definition at line 180 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:26

Definition at line 148 of file util.h.

◆ DEBUG_CONFIG_DEF

#define DEBUG_CONFIG_DEF ( x)
Value:
#define DEBUG_CONFIG_MSG(x)
Definition util.h:25
#define STR(x)
Definition util.h:24

Definition at line 26 of file util.h.

◆ DEBUG_CONFIG_MSG

#define DEBUG_CONFIG_MSG ( x)
Value:
"DEBUG_CONFIG: " x

Definition at line 25 of file util.h.

◆ EXPECT

#define EXPECT ( x,
c )
Value:
(x)

Definition at line 138 of file util.h.

◆ PRINT_BUF

#define PRINT_BUF ( buf,
len )
Value:
do { \
printf("%s[%lu] = ", #buf, (unsigned long)len); \
print_buf_plain(buf, len); \
} while(0)

Definition at line 29 of file util.h.

◆ ROUND_TO_ALIGN

#define ROUND_TO_ALIGN ( size)
Value:
#define ALIGNMENT
Definition util.h:176
#define CEIL_DIV(x, y)
Definition util.h:180

Definition at line 182 of file util.h.

◆ SECP256K1_GNUC_EXT

#define SECP256K1_GNUC_EXT

Definition at line 204 of file util.h.

◆ SECP256K1_INLINE

#define SECP256K1_INLINE

Definition at line 54 of file util.h.

◆ SECP256K1_INT128_STRUCT

#define SECP256K1_INT128_STRUCT   1

Definition at line 344 of file util.h.

◆ SECP256K1_RESTRICT

#define SECP256K1_RESTRICT

Definition at line 194 of file util.h.

◆ SECP256K1_WIDEMUL_INT128

#define SECP256K1_WIDEMUL_INT128   1

Definition at line 343 of file util.h.

◆ STATIC_ASSERT

#define STATIC_ASSERT ( expr)
Value:
do { \
switch(0) { \
case 0: \
/* If expr evaluates to 0, we have two case labels "0", which is illegal. */ \
case /* ERROR: static assertion failed */ (expr): \
; \
} \
} while(0)

Assert statically that expr is true.

This is a statement-like macro and can only be used inside functions.

Definition at line 64 of file util.h.

◆ STR

#define STR ( x)
Value:
STR_(x)
#define STR_(x)
Definition util.h:23

Definition at line 24 of file util.h.

◆ STR_

#define STR_ ( x)
Value:
#x

Definition at line 23 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 129 of file util.h.

◆ VERIFY_CHECK

#define VERIFY_CHECK ( cond)

Definition at line 159 of file util.h.

Function Documentation

◆ checked_malloc()

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

Definition at line 162 of file util.h.

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

◆ print_buf_plain()

void print_buf_plain ( const unsigned char * buf,
size_t len )
static

Definition at line 34 of file util.h.

◆ secp256k1_callback_call()

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

Definition at line 92 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_ctz32_var()

SECP256K1_INLINE int secp256k1_ctz32_var ( uint32_t x)
static

Definition at line 380 of file util.h.

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

◆ secp256k1_ctz32_var_debruijn()

SECP256K1_INLINE int secp256k1_ctz32_var_debruijn ( uint32_t x)
static

Definition at line 357 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_ctz64_var()

SECP256K1_INLINE int secp256k1_ctz64_var ( uint64_t x)
static

Definition at line 398 of file util.h.

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

◆ secp256k1_ctz64_var_debruijn()

SECP256K1_INLINE int secp256k1_ctz64_var_debruijn ( uint64_t x)
static

Definition at line 369 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_default_error_callback_fn()

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

Definition at line 102 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_default_illegal_callback_fn()

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

Definition at line 97 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_int_cmov()

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

If flag is 1, set *r equal to *a; if flag is 0, leave it.

Constant-time. Both *r and *a must be initialized and non-negative. Flag must be 0 or 1.

Definition at line 300 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_is_zero_array()

SECP256K1_INLINE int secp256k1_is_zero_array ( const unsigned char * s,
size_t len )
static

Definition at line 284 of file util.h.

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

◆ secp256k1_memclear_explicit()

SECP256K1_INLINE void secp256k1_memclear_explicit ( void * ptr,
size_t len )
static

Definition at line 256 of file util.h.

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

◆ secp256k1_memcmp_var()

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 269 of file util.h.

◆ secp256k1_memczero()

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

Definition at line 208 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_memzero_explicit()

SECP256K1_INLINE void secp256k1_memzero_explicit ( void * ptr,
size_t len )
static

Definition at line 224 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_read_be32()

SECP256K1_INLINE uint32_t secp256k1_read_be32 ( const unsigned char * p)
static

Definition at line 416 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_read_be64()

SECP256K1_INLINE uint64_t secp256k1_read_be64 ( const unsigned char * p)
static

Definition at line 432 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_rotr32()

SECP256K1_INLINE uint32_t secp256k1_rotr32 ( const uint32_t x,
const unsigned int by )
static

Definition at line 456 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_write_be32()

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

Definition at line 424 of file util.h.

Here is the caller graph for this function:

◆ secp256k1_write_be64()

SECP256K1_INLINE void secp256k1_write_be64 ( unsigned char * p,
uint64_t x )
static

Definition at line 444 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:102

Definition at line 117 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:97

Definition at line 112 of file util.h.