1 // Copyright (c) 2013 Pieter Wuille
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef _SECP256K1_UTIL_H_
6 #define _SECP256K1_UTIL_H_
8 #if defined HAVE_CONFIG_H
9 #include "libsecp256k1-config.h"
16 #define TEST_FAILURE(msg) do { \
17 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \
21 #ifndef HAVE_BUILTIN_EXPECT
22 #define EXPECT(x,c) __builtin_expect((x),(c))
24 #define EXPECT(x,c) (x)
27 #define CHECK(cond) do { \
28 if (EXPECT(!(cond), 0)) { \
29 TEST_FAILURE("test condition failed: " #cond); \
33 // Like assert(), but safe to use on expressions with side effects.
35 #define DEBUG_CHECK CHECK
37 #define DEBUG_CHECK(cond) do { (cond); } while(0)
40 // Like DEBUG_CHECK(), but when VERIFY is defined instead of NDEBUG not defined.
42 #define VERIFY_CHECK CHECK
44 #define VERIFY_CHECK(cond) do { (cond); } while(0)
47 /** Seed the pseudorandom number generator. */
48 static inline void secp256k1_rand_seed(uint64_t v);
50 /** Generate a pseudorandom 32-bit number. */
51 static uint32_t secp256k1_rand32(void);
53 /** Generate a pseudorandom 32-byte array. */
54 static void secp256k1_rand256(unsigned char *b32);
56 /** Generate a pseudorandom 32-byte array with long sequences of zero and one bits. */
57 static void secp256k1_rand256_test(unsigned char *b32);