diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44c2754bbd..d556c9b09a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,9 +103,9 @@ jobs: - env_vars: { WIDEMUL: 'int128', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes' } - env_vars: { WIDEMUL: 'int128', ASM: 'x86_64', ELLSWIFT: 'yes' } - env_vars: { RECOVERY: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes' } - - env_vars: { CTIMETESTS: 'no', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', CPPFLAGS: '-DVERIFY' } + - env_vars: { CTIMETESTS: 'no', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', CPPFLAGS: '-DSECP256K1_VERIFY' } - env_vars: { BUILD: 'distcheck', WITH_VALGRIND: 'no', CTIMETESTS: 'no', BENCH: 'no' } - - env_vars: { CPPFLAGS: '-DDETERMINISTIC' } + - env_vars: { CPPFLAGS: '-DSECP256K1_DETERMINISTIC' } - env_vars: { CFLAGS: '-O0', CTIMETESTS: 'no' } - env_vars: { CFLAGS: '-O1', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes' } - env_vars: { ECMULTGENKB: 2, ECMULTWINDOW: 2 } @@ -464,7 +464,7 @@ jobs: - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', CC: 'gcc' } - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 } - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', CC: 'gcc', WRAPPER_CMD: 'valgrind --error-exitcode=42', SECP256K1_TEST_ITERS: 2 } - - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', CPPFLAGS: '-DVERIFY', CTIMETESTS: 'no' } + - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', CPPFLAGS: '-DSECP256K1_VERIFY', CTIMETESTS: 'no' } - BUILD: 'distcheck' steps: @@ -519,7 +519,7 @@ jobs: - { WIDEMUL: 'int128', RECOVERY: 'yes' } - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes' } - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', CC: 'gcc' } - - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', CPPFLAGS: '-DVERIFY' } + - { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', MUSIG: 'yes', ELLSWIFT: 'yes', CPPFLAGS: '-DSECP256K1_VERIFY' } - BUILD: 'distcheck' steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef69c0891..807d8b0a15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,27 +55,27 @@ option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON) option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF) if(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS) - add_compile_definitions(USE_EXTERNAL_DEFAULT_CALLBACKS=1) + add_compile_definitions(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS=1) endif() set(SECP256K1_ECMULT_WINDOW_SIZE 15 CACHE STRING "Window size for ecmult precomputation for verification, specified as integer in range [2..24]. The default value is a reasonable setting for desktop machines (currently 15). [default=15]") set_property(CACHE SECP256K1_ECMULT_WINDOW_SIZE PROPERTY STRINGS 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24) include(CheckStringOptionValue) check_string_option_value(SECP256K1_ECMULT_WINDOW_SIZE) -add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE}) +add_compile_definitions(SECP256K1_ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE}) set(SECP256K1_ECMULT_GEN_KB 86 CACHE STRING "The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms). Larger values result in possibly better signing or key generation performance at the cost of a larger table. Valid choices are 2, 22, 86. The default value is a reasonable setting for desktop machines (currently 86). [default=86]") set_property(CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS 2 22 86) check_string_option_value(SECP256K1_ECMULT_GEN_KB) if(SECP256K1_ECMULT_GEN_KB EQUAL 2) - add_compile_definitions(COMB_BLOCKS=2) - add_compile_definitions(COMB_TEETH=5) + add_compile_definitions(SECP256K1_COMB_BLOCKS=2) + add_compile_definitions(SECP256K1_COMB_TEETH=5) elseif(SECP256K1_ECMULT_GEN_KB EQUAL 22) - add_compile_definitions(COMB_BLOCKS=11) - add_compile_definitions(COMB_TEETH=6) + add_compile_definitions(SECP256K1_COMB_BLOCKS=11) + add_compile_definitions(SECP256K1_COMB_TEETH=6) elseif(SECP256K1_ECMULT_GEN_KB EQUAL 86) - add_compile_definitions(COMB_BLOCKS=43) - add_compile_definitions(COMB_TEETH=6) + add_compile_definitions(SECP256K1_COMB_BLOCKS=43) + add_compile_definitions(SECP256K1_COMB_TEETH=6) endif() set(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY "OFF" CACHE STRING "Test-only override of the (autodetected by the C code) \"widemul\" setting. Legal values are: \"OFF\", \"int128_struct\", \"int128\" or \"int64\". [default=OFF]") @@ -83,7 +83,7 @@ set_property(CACHE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY PROPERTY STRINGS "OFF" check_string_option_value(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY) if(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY) string(TOUPPER "${SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY}" widemul_upper_value) - add_compile_definitions(USE_FORCE_WIDEMUL_${widemul_upper_value}=1) + add_compile_definitions(SECP256K1_USE_FORCE_WIDEMUL_${widemul_upper_value}=1) endif() mark_as_advanced(FORCE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY) @@ -95,7 +95,7 @@ if(SECP256K1_ASM STREQUAL "arm32") include(CheckArm32Assembly) check_arm32_assembly() if(HAVE_ARM32_ASM) - add_compile_definitions(USE_EXTERNAL_ASM=1) + add_compile_definitions(SECP256K1_USE_EXTERNAL_ASM=1) else() message(FATAL_ERROR "ARM32 assembly requested but not available.") endif() @@ -104,7 +104,7 @@ elseif(SECP256K1_ASM) check_x86_64_assembly() if(HAVE_X86_64_ASM) set(SECP256K1_ASM "x86_64") - add_compile_definitions(USE_ASM_X86_64=1) + add_compile_definitions(SECP256K1_USE_ASM_X86_64=1) elseif(SECP256K1_ASM STREQUAL "AUTO") set(SECP256K1_ASM "OFF") else() @@ -127,7 +127,7 @@ if(SECP256K1_VALGRIND) if(Valgrind_FOUND) set(SECP256K1_VALGRIND ON) include_directories(${Valgrind_INCLUDE_DIR}) - add_compile_definitions(VALGRIND) + add_compile_definitions(SECP256K1_VALGRIND) elseif(SECP256K1_VALGRIND STREQUAL "AUTO") set(SECP256K1_VALGRIND OFF) else() @@ -156,7 +156,7 @@ else() endif() # Define custom "Coverage" build type. -set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DCOVERAGE=1 --coverage" CACHE STRING +set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DSECP256K1_COVERAGE=1 --coverage" CACHE STRING "Flags used by the C compiler during \"Coverage\" builds." FORCE ) diff --git a/Makefile.am b/Makefile.am index 07d7a2ba7f..9778e6b829 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,7 +130,7 @@ if !ENABLE_COVERAGE TESTS += tests noinst_PROGRAMS += tests tests_SOURCES = $(noverify_tests_SOURCES) -tests_CPPFLAGS = $(noverify_tests_CPPFLAGS) -DVERIFY +tests_CPPFLAGS = $(noverify_tests_CPPFLAGS) -DSECP256K1_VERIFY tests_LDADD = $(noverify_tests_LDADD) tests_LDFLAGS = $(noverify_tests_LDFLAGS) endif @@ -148,7 +148,7 @@ noinst_PROGRAMS += exhaustive_tests exhaustive_tests_SOURCES = src/tests_exhaustive.c exhaustive_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES) if !ENABLE_COVERAGE -exhaustive_tests_CPPFLAGS += -DVERIFY +exhaustive_tests_CPPFLAGS += -DSECP256K1_VERIFY endif # Note: do not include $(PRECOMPUTED_LIB) in exhaustive_tests (it uses runtime-generated tables). exhaustive_tests_LDADD = $(COMMON_LIB) @@ -217,11 +217,11 @@ EXTRA_PROGRAMS = precompute_ecmult precompute_ecmult_gen CLEANFILES = $(EXTRA_PROGRAMS) precompute_ecmult_SOURCES = src/precompute_ecmult.c -precompute_ecmult_CPPFLAGS = $(SECP_CONFIG_DEFINES) -DVERIFY +precompute_ecmult_CPPFLAGS = $(SECP_CONFIG_DEFINES) -DSECP256K1_VERIFY precompute_ecmult_LDADD = $(COMMON_LIB) precompute_ecmult_gen_SOURCES = src/precompute_ecmult_gen.c -precompute_ecmult_gen_CPPFLAGS = $(SECP_CONFIG_DEFINES) -DVERIFY +precompute_ecmult_gen_CPPFLAGS = $(SECP_CONFIG_DEFINES) -DSECP256K1_VERIFY precompute_ecmult_gen_LDADD = $(COMMON_LIB) # See Automake manual, Section "Errors with distclean". diff --git a/configure.ac b/configure.ac index a21447ced5..b135f018ab 100644 --- a/configure.ac +++ b/configure.ac @@ -267,7 +267,7 @@ if test x"$enable_ctime_tests" = x"yes"; then fi if test x"$enable_coverage" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOVERAGE=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_COVERAGE=1" SECP_CFLAGS="-O0 --coverage $SECP_CFLAGS" # If coverage is enabled, and the user has not overridden CFLAGS, # override Autoconf's value "-g -O2" with "-g". Otherwise we'd end up @@ -319,7 +319,7 @@ enable_external_asm=no case $set_asm in x86_64) - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_ASM_X86_64=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_USE_ASM_X86_64=1" ;; arm32) enable_external_asm=yes @@ -332,20 +332,20 @@ no) esac if test x"$enable_external_asm" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_ASM=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_USE_EXTERNAL_ASM=1" fi # Select wide multiplication implementation case $set_widemul in int128_struct) - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT128_STRUCT=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_USE_FORCE_WIDEMUL_INT128_STRUCT=1" ;; int128) - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT128=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_USE_FORCE_WIDEMUL_INT128=1" ;; int64) - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_FORCE_WIDEMUL_INT64=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_USE_FORCE_WIDEMUL_INT64=1" ;; auto) ;; @@ -365,19 +365,19 @@ case $set_ecmult_window in # not in range AC_MSG_ERROR($error_window_size) fi - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DECMULT_WINDOW_SIZE=$set_ecmult_window" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_ECMULT_WINDOW_SIZE=$set_ecmult_window" ;; esac case $set_ecmult_gen_kb in 2) - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=2 -DCOMB_TEETH=5" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_COMB_BLOCKS=2 -DSECP256K1_COMB_TEETH=5" ;; 22) - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=11 -DCOMB_TEETH=6" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_COMB_BLOCKS=11 -DSECP256K1_COMB_TEETH=6" ;; 86) - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOMB_BLOCKS=43 -DCOMB_TEETH=6" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_COMB_BLOCKS=43 -DSECP256K1_COMB_TEETH=6" ;; *) AC_MSG_ERROR(['ecmult gen table size not 2, 22 or 86']) @@ -385,7 +385,7 @@ case $set_ecmult_gen_kb in esac if test x"$enable_valgrind" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES $VALGRIND_CPPFLAGS -DVALGRIND" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES $VALGRIND_CPPFLAGS -DSECP256K1_VALGRIND" fi # Add -Werror and similar flags passed from the outside (for testing, e.g., in CI). @@ -400,7 +400,7 @@ SECP_CFLAGS="$SECP_CFLAGS $WERROR_CFLAGS" # Processing must be done in a reverse topological sorting of the dependency graph # (dependent module first). if test x"$enable_module_ellswift" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_ENABLE_MODULE_ELLSWIFT=1" fi if test x"$enable_module_musig" = x"yes"; then @@ -408,7 +408,7 @@ if test x"$enable_module_musig" = x"yes"; then AC_MSG_ERROR([Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.]) fi enable_module_schnorrsig=yes - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_MUSIG=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_ENABLE_MODULE_MUSIG=1" fi if test x"$enable_module_schnorrsig" = x"yes"; then @@ -416,23 +416,23 @@ if test x"$enable_module_schnorrsig" = x"yes"; then AC_MSG_ERROR([Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.]) fi enable_module_extrakeys=yes - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_SCHNORRSIG=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_ENABLE_MODULE_SCHNORRSIG=1" fi if test x"$enable_module_extrakeys" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_EXTRAKEYS=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_ENABLE_MODULE_EXTRAKEYS=1" fi if test x"$enable_module_recovery" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_RECOVERY=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_ENABLE_MODULE_RECOVERY=1" fi if test x"$enable_module_ecdh" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDH=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_ENABLE_MODULE_ECDH=1" fi if test x"$enable_external_default_callbacks" = x"yes"; then - SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" + SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DSECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS=1" fi ### @@ -449,7 +449,7 @@ fi if test "x$enable_tests" != x"no"; then AC_CHECK_HEADERS([sys/types.h sys/wait.h unistd.h]) AS_IF([test "x$ac_cv_header_sys_types_h" = xyes && test "x$ac_cv_header_sys_wait_h" = xyes && - test "x$ac_cv_header_unistd_h" = xyes], [TEST_DEFINES="-DSUPPORTS_CONCURRENCY=1"], TEST_DEFINES="") + test "x$ac_cv_header_unistd_h" = xyes], [TEST_DEFINES="-DSECP256K1_SUPPORTS_CONCURRENCY=1"], TEST_DEFINES="") AC_SUBST(TEST_DEFINES) fi diff --git a/include/secp256k1.h b/include/secp256k1.h index 9de45f1f7d..d31bea6bb1 100644 --- a/include/secp256k1.h +++ b/include/secp256k1.h @@ -348,7 +348,7 @@ SECP256K1_API void secp256k1_context_destroy( * default callback will be used. The library provides a default callback which * writes the message to stderr and calls abort. This default callback can be * replaced at link time if the preprocessor macro - * USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build + * SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build * has been configured with --enable-external-default-callbacks (GNU Autotools) or * -DSECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS=ON (CMake). Then the * following two symbols must be provided to link against: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 322f1987dd..67ddec1a8f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ set_property(TARGET secp256k1 PROPERTY PUBLIC_HEADER # Processing must be done in a topological sorting of the dependency graph # (dependent module first). if(SECP256K1_ENABLE_MODULE_ELLSWIFT) - add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1) + add_compile_definitions(SECP256K1_ENABLE_MODULE_ELLSWIFT=1) set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_ellswift.h) endif() @@ -17,7 +17,7 @@ if(SECP256K1_ENABLE_MODULE_MUSIG) message(FATAL_ERROR "Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.") endif() set(SECP256K1_ENABLE_MODULE_SCHNORRSIG ON) - add_compile_definitions(ENABLE_MODULE_MUSIG=1) + add_compile_definitions(SECP256K1_ENABLE_MODULE_MUSIG=1) set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_musig.h) endif() @@ -26,22 +26,22 @@ if(SECP256K1_ENABLE_MODULE_SCHNORRSIG) message(FATAL_ERROR "Module dependency error: You have disabled the extrakeys module explicitly, but it is required by the schnorrsig module.") endif() set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON) - add_compile_definitions(ENABLE_MODULE_SCHNORRSIG=1) + add_compile_definitions(SECP256K1_ENABLE_MODULE_SCHNORRSIG=1) set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_schnorrsig.h) endif() if(SECP256K1_ENABLE_MODULE_EXTRAKEYS) - add_compile_definitions(ENABLE_MODULE_EXTRAKEYS=1) + add_compile_definitions(SECP256K1_ENABLE_MODULE_EXTRAKEYS=1) set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_extrakeys.h) endif() if(SECP256K1_ENABLE_MODULE_RECOVERY) - add_compile_definitions(ENABLE_MODULE_RECOVERY=1) + add_compile_definitions(SECP256K1_ENABLE_MODULE_RECOVERY=1) set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_recovery.h) endif() if(SECP256K1_ENABLE_MODULE_ECDH) - add_compile_definitions(ENABLE_MODULE_ECDH=1) + add_compile_definitions(SECP256K1_ENABLE_MODULE_ECDH=1) set_property(TARGET secp256k1 APPEND PROPERTY PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/secp256k1_ecdh.h) endif() @@ -141,7 +141,7 @@ if(SECP256K1_BUILD_TESTS) set(TEST_DEFINITIONS "") if(HAVE_SYS_TYPES_H AND HAVE_SYS_WAIT_H AND HAVE_UNISTD_H) - list(APPEND TEST_DEFINITIONS SUPPORTS_CONCURRENCY=1) + list(APPEND TEST_DEFINITIONS SECP256K1_SUPPORTS_CONCURRENCY=1) endif() function(add_executable_and_tests exe_name verify_definition) @@ -161,7 +161,7 @@ if(SECP256K1_BUILD_TESTS) add_executable_and_tests(noverify_tests "") if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage") - add_executable_and_tests(tests VERIFY) + add_executable_and_tests(tests SECP256K1_VERIFY) endif() unset(TEST_DEFINITIONS) endif() @@ -170,7 +170,7 @@ if(SECP256K1_BUILD_EXHAUSTIVE_TESTS) # Note: do not include secp256k1_precomputed in exhaustive_tests (it uses runtime-generated tables). add_executable(exhaustive_tests tests_exhaustive.c) target_link_libraries(exhaustive_tests secp256k1_asm) - target_compile_definitions(exhaustive_tests PRIVATE $<$>:VERIFY>) + target_compile_definitions(exhaustive_tests PRIVATE $<$>:SECP256K1_VERIFY>) add_test(NAME secp256k1.exhaustive_tests COMMAND exhaustive_tests) set_tests_properties(secp256k1.exhaustive_tests PROPERTIES LABELS secp256k1_exhaustive diff --git a/src/bench.c b/src/bench.c index f561ad1c9d..7b6edc7032 100644 --- a/src/bench.c +++ b/src/bench.c @@ -16,19 +16,19 @@ static void help(const char *executable_path, int default_iters) { printf("Benchmarks the following algorithms:\n"); printf(" - ECDSA signing/verification\n"); -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY printf(" - Public key recovery (optional module)\n"); #endif -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH printf(" - ECDH key exchange (optional module)\n"); #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG printf(" - Schnorr signatures (optional module)\n"); #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT printf(" - ElligatorSwift (optional module)\n"); #endif @@ -46,21 +46,21 @@ static void help(const char *executable_path, int default_iters) { printf(" ec : all EC public key algorithms (keygen)\n"); printf(" ec_keygen : EC public key generation\n"); -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY printf(" ecdsa_recover : ECDSA public key recovery algorithm\n"); #endif -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH printf(" ecdh : ECDH key exchange algorithm\n"); #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG printf(" schnorrsig : all Schnorr signature algorithms (sign, verify)\n"); printf(" schnorrsig_sign : Schnorr sigining algorithm\n"); printf(" schnorrsig_verify : Schnorr verification algorithm\n"); #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT printf(" ellswift : all ElligatorSwift benchmarks (encode, decode, keygen, ecdh)\n"); printf(" ellswift_encode : ElligatorSwift encoding\n"); printf(" ellswift_decode : ElligatorSwift decoding\n"); @@ -154,19 +154,19 @@ static void bench_keygen_run(void *arg, int iters) { } -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH # include "modules/ecdh/bench_impl.h" #endif -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY # include "modules/recovery/bench_impl.h" #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG # include "modules/schnorrsig/bench_impl.h" #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT # include "modules/ellswift/bench_impl.h" #endif @@ -206,7 +206,7 @@ int main(int argc, char** argv) { } /* Check if the user tries to benchmark optional module without building it */ -#ifndef ENABLE_MODULE_ECDH +#ifndef SECP256K1_ENABLE_MODULE_ECDH if (have_flag(argc, argv, "ecdh")) { fprintf(stderr, "./bench: ECDH module not enabled.\n"); fprintf(stderr, "See README.md for configuration instructions.\n\n"); @@ -214,7 +214,7 @@ int main(int argc, char** argv) { } #endif -#ifndef ENABLE_MODULE_RECOVERY +#ifndef SECP256K1_ENABLE_MODULE_RECOVERY if (have_flag(argc, argv, "recover") || have_flag(argc, argv, "ecdsa_recover")) { fprintf(stderr, "./bench: Public key recovery module not enabled.\n"); fprintf(stderr, "See README.md for configuration instructions.\n\n"); @@ -222,7 +222,7 @@ int main(int argc, char** argv) { } #endif -#ifndef ENABLE_MODULE_SCHNORRSIG +#ifndef SECP256K1_ENABLE_MODULE_SCHNORRSIG if (have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "schnorrsig_sign") || have_flag(argc, argv, "schnorrsig_verify")) { fprintf(stderr, "./bench: Schnorr signatures module not enabled.\n"); fprintf(stderr, "See README.md for configuration instructions.\n\n"); @@ -230,7 +230,7 @@ int main(int argc, char** argv) { } #endif -#ifndef ENABLE_MODULE_ELLSWIFT +#ifndef SECP256K1_ENABLE_MODULE_ELLSWIFT if (have_flag(argc, argv, "ellswift") || have_flag(argc, argv, "ellswift_encode") || have_flag(argc, argv, "ellswift_decode") || have_flag(argc, argv, "encode") || have_flag(argc, argv, "decode") || have_flag(argc, argv, "ellswift_keygen") || have_flag(argc, argv, "ellswift_ecdh")) { @@ -264,22 +264,22 @@ int main(int argc, char** argv) { secp256k1_context_destroy(data.ctx); -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH /* ECDH benchmarks */ run_ecdh_bench(iters, argc, argv); #endif -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY /* ECDSA recovery benchmarks */ run_recovery_bench(iters, argc, argv); #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG /* Schnorr signature benchmarks */ run_schnorrsig_bench(iters, argc, argv); #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT /* ElligatorSwift benchmarks */ run_ellswift_bench(iters, argc, argv); #endif diff --git a/src/checkmem.h b/src/checkmem.h index 88c65c8ebf..d801f1c3e7 100644 --- a/src/checkmem.h +++ b/src/checkmem.h @@ -23,7 +23,7 @@ * - Assert or otherwise fail in case the len-byte memory block pointed to by p is * not considered entirely defined. * - SECP256K1_CHECKMEM_CHECK_VERIFY(p, len): - * - Like SECP256K1_CHECKMEM_CHECK, but only works in VERIFY mode. + * - Like SECP256K1_CHECKMEM_CHECK, but only works in SECP256K1_VERIFY mode. * - SECP256K1_CHECKMEM_UNDEFINE(p, len): * - marks the len-byte memory block pointed to by p as undefined data (secret data, * in the context of constant-time checking). @@ -42,7 +42,7 @@ #define SECP256K1_CHECKMEM_NOOP(p, len) do { (void)(p); (void)(len); } while(0) /* If compiling under msan, map the SECP256K1_CHECKMEM_* functionality to msan. - * Choose this preferentially, even when VALGRIND is defined, as msan-compiled + * Choose this preferentially, even when SECP256K1_VALGRIND is defined, as msan-compiled * binaries can't be run under valgrind anyway. */ #if defined(__has_feature) # if __has_feature(memory_sanitizer) @@ -70,10 +70,10 @@ # define SECP256K1_CHECKMEM_MSAN_DEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) #endif -/* If valgrind integration is desired (through the VALGRIND define), implement the +/* If valgrind integration is desired (through the SECP256K1_VALGRIND define), implement the * SECP256K1_CHECKMEM_* macros using valgrind. */ #if !defined SECP256K1_CHECKMEM_ENABLED -# if defined VALGRIND +# if defined SECP256K1_VALGRIND # include # if defined(__clang__) && defined(__APPLE__) # pragma clang diagnostic push @@ -108,7 +108,7 @@ # define SECP256K1_CHECKMEM_RUNNING() (0) #endif -#if defined VERIFY +#if defined SECP256K1_VERIFY #define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_CHECK((p), (len)) #else #define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) diff --git a/src/ctime_tests.c b/src/ctime_tests.c index f80042a8e8..c6bd371ec4 100644 --- a/src/ctime_tests.c +++ b/src/ctime_tests.c @@ -16,27 +16,27 @@ # error "This tool cannot be compiled without memory-checking interface (valgrind or msan)" #endif -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH # include "../include/secp256k1_ecdh.h" #endif -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY # include "../include/secp256k1_recovery.h" #endif -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS # include "../include/secp256k1_extrakeys.h" #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG #include "../include/secp256k1_schnorrsig.h" #endif -#ifdef ENABLE_MODULE_MUSIG +#ifdef SECP256K1_ENABLE_MODULE_MUSIG #include "../include/secp256k1_musig.h" #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT #include "../include/secp256k1_ellswift.h" #endif @@ -83,14 +83,14 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) { unsigned char msg[32]; unsigned char sig[74]; unsigned char spubkey[33]; -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY secp256k1_ecdsa_recoverable_signature recoverable_signature; int recid; #endif -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS secp256k1_keypair keypair; #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT unsigned char ellswift[64]; static const unsigned char prefix[64] = {'t', 'e', 's', 't'}; #endif @@ -115,7 +115,7 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) { CHECK(ret); CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, sig, &siglen, &signature)); -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH /* Test ECDH. */ SECP256K1_CHECKMEM_UNDEFINE(key, 32); ret = secp256k1_ecdh(ctx, msg, &pubkey, key, NULL, NULL); @@ -123,7 +123,7 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) { CHECK(ret == 1); #endif -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY /* Test signing a recoverable signature. */ SECP256K1_CHECKMEM_UNDEFINE(key, 32); ret = secp256k1_ecdsa_sign_recoverable(ctx, &recoverable_signature, msg, key, NULL, NULL); @@ -157,7 +157,7 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) { CHECK(ret == 1); /* Test keypair_create and keypair_xonly_tweak_add. */ -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS SECP256K1_CHECKMEM_UNDEFINE(key, 32); ret = secp256k1_keypair_create(ctx, &keypair, key); SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); @@ -176,7 +176,7 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) { CHECK(ret == 1); #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG SECP256K1_CHECKMEM_UNDEFINE(key, 32); ret = secp256k1_keypair_create(ctx, &keypair, key); SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); @@ -186,7 +186,7 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) { CHECK(ret == 1); #endif -#ifdef ENABLE_MODULE_MUSIG +#ifdef SECP256K1_ENABLE_MODULE_MUSIG { secp256k1_pubkey pk; const secp256k1_pubkey *pk_ptr[1]; @@ -238,7 +238,7 @@ static void run_tests(secp256k1_context *ctx, unsigned char *key) { } #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT SECP256K1_CHECKMEM_UNDEFINE(key, 32); ret = secp256k1_ellswift_create(ctx, ellswift, key, NULL); SECP256K1_CHECKMEM_DEFINE(&ret, sizeof(ret)); diff --git a/src/ecdsa_impl.h b/src/ecdsa_impl.h index ce36e85e6a..6c3d65b833 100644 --- a/src/ecdsa_impl.h +++ b/src/ecdsa_impl.h @@ -195,7 +195,7 @@ static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar *sigr, const secp256k1_scalar *sigs, const secp256k1_ge *pubkey, const secp256k1_scalar *message) { unsigned char c[32]; secp256k1_scalar sn, u1, u2; -#if !defined(EXHAUSTIVE_TEST_ORDER) +#if !defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) secp256k1_fe xr; #endif secp256k1_gej pubkeyj; @@ -214,7 +214,7 @@ static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar *sigr, const secp25 return 0; } -#if defined(EXHAUSTIVE_TEST_ORDER) +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) { secp256k1_scalar computed_r; secp256k1_ge pr_ge; diff --git a/src/ecmult.h b/src/ecmult.h index 8d0a9f4905..a37e5cc92a 100644 --- a/src/ecmult.h +++ b/src/ecmult.h @@ -11,19 +11,19 @@ #include "scalar.h" #include "scratch.h" -#ifndef ECMULT_WINDOW_SIZE -# define ECMULT_WINDOW_SIZE 15 -# ifdef DEBUG_CONFIG -# pragma message DEBUG_CONFIG_MSG("ECMULT_WINDOW_SIZE undefined, assuming default value") +#ifndef SECP256K1_ECMULT_WINDOW_SIZE +# define SECP256K1_ECMULT_WINDOW_SIZE 15 +# ifdef SECP256K1_DEBUG_CONFIG +# pragma message DEBUG_CONFIG_MSG("SECP256K1_ECMULT_WINDOW_SIZE undefined, assuming default value") # endif #endif -#ifdef DEBUG_CONFIG -# pragma message DEBUG_CONFIG_DEF(ECMULT_WINDOW_SIZE) +#ifdef SECP256K1_DEBUG_CONFIG +# pragma message DEBUG_CONFIG_DEF(SECP256K1_ECMULT_WINDOW_SIZE) #endif /* No one will ever need more than a window size of 24. The code might - * be correct for larger values of ECMULT_WINDOW_SIZE but this is not + * be correct for larger values of SECP256K1_ECMULT_WINDOW_SIZE but this is not * tested. * * The following limitations are known, and there are probably more: @@ -33,8 +33,8 @@ * If WINDOW_G > 31 and int has 32 bits, then the code is incorrect * because certain expressions will overflow. */ -#if ECMULT_WINDOW_SIZE < 2 || ECMULT_WINDOW_SIZE > 24 -# error Set ECMULT_WINDOW_SIZE to an integer in range [2..24]. +#if SECP256K1_ECMULT_WINDOW_SIZE < 2 || SECP256K1_ECMULT_WINDOW_SIZE > 24 +# error Set SECP256K1_ECMULT_WINDOW_SIZE to an integer in range [2..24]. #endif /** The number of entries a table with precomputed multiples needs to have. */ diff --git a/src/ecmult_const_impl.h b/src/ecmult_const_impl.h index 1d24aeaf36..3385e00aae 100644 --- a/src/ecmult_const_impl.h +++ b/src/ecmult_const_impl.h @@ -12,18 +12,18 @@ #include "ecmult_const.h" #include "ecmult_impl.h" -#if defined(EXHAUSTIVE_TEST_ORDER) -/* We need 2^ECMULT_CONST_GROUP_SIZE - 1 to be less than EXHAUSTIVE_TEST_ORDER, because +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) +/* We need 2^ECMULT_CONST_GROUP_SIZE - 1 to be less than SECP256K1_EXHAUSTIVE_TEST_ORDER, because * the tables cannot have infinities in them (this breaks the effective-affine technique's * z-ratio tracking) */ -# if EXHAUSTIVE_TEST_ORDER == 199 +# if SECP256K1_EXHAUSTIVE_TEST_ORDER == 199 # define ECMULT_CONST_GROUP_SIZE 4 -# elif EXHAUSTIVE_TEST_ORDER == 13 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 13 # define ECMULT_CONST_GROUP_SIZE 3 -# elif EXHAUSTIVE_TEST_ORDER == 7 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 7 # define ECMULT_CONST_GROUP_SIZE 2 # else -# error "Unknown EXHAUSTIVE_TEST_ORDER" +# error "Unknown SECP256K1_EXHAUSTIVE_TEST_ORDER" # endif #else /* Group size 4 or 5 appears optimal. */ @@ -103,8 +103,8 @@ static void secp256k1_ecmult_const_odd_multiples_table_globalz(secp256k1_ge *pre /* For K as defined in the comment of secp256k1_ecmult_const, we have several precomputed * formulas/constants. * - in exhaustive test mode, we give an explicit expression to compute it at compile time: */ -#ifdef EXHAUSTIVE_TEST_ORDER -static const secp256k1_scalar secp256k1_ecmult_const_K = ((SECP256K1_SCALAR_CONST(0, 0, 0, (1U << (ECMULT_CONST_BITS - 128)) - 2U, 0, 0, 0, 0) + EXHAUSTIVE_TEST_ORDER - 1U) * (1U + EXHAUSTIVE_TEST_LAMBDA)) % EXHAUSTIVE_TEST_ORDER; +#ifdef SECP256K1_EXHAUSTIVE_TEST_ORDER +static const secp256k1_scalar secp256k1_ecmult_const_K = ((SECP256K1_SCALAR_CONST(0, 0, 0, (1U << (ECMULT_CONST_BITS - 128)) - 2U, 0, 0, 0, 0) + SECP256K1_EXHAUSTIVE_TEST_ORDER - 1U) * (1U + EXHAUSTIVE_TEST_LAMBDA)) % SECP256K1_EXHAUSTIVE_TEST_ORDER; /* - for the real secp256k1 group we have constants for various ECMULT_CONST_BITS values. */ #elif ECMULT_CONST_BITS == 129 /* For GROUP_SIZE = 1,3. */ @@ -209,7 +209,7 @@ static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, cons secp256k1_scalar_add(&v1, &v1, &S_OFFSET); secp256k1_scalar_add(&v2, &v2, &S_OFFSET); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* Verify that v1 and v2 are in range [0, 2^129-1]. */ for (i = 129; i < 256; ++i) { VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&v1, i, 1) == 0); diff --git a/src/ecmult_gen.h b/src/ecmult_gen.h index 43dd10c38d..a0caf2fd72 100644 --- a/src/ecmult_gen.h +++ b/src/ecmult_gen.h @@ -13,104 +13,104 @@ /* Configuration parameters for the signed-digit multi-comb algorithm: * - * - COMB_BLOCKS is the number of blocks the input is split into. Each + * - SECP256K1_COMB_BLOCKS is the number of blocks the input is split into. Each * has a corresponding table. - * - COMB_TEETH is the number of bits simultaneously covered by one table. + * - SECP256K1_COMB_TEETH is the number of bits simultaneously covered by one table. * - COMB_RANGE is the number of bits in supported scalars. For production * purposes, only 256 is reasonable, but smaller numbers are supported for * exhaustive test mode. * * The comb's spacing (COMB_SPACING), or the distance between the teeth, - * is defined as ceil(COMB_RANGE / (COMB_BLOCKS * COMB_TEETH)). Each block covers - * COMB_SPACING * COMB_TEETH consecutive bits in the input. + * is defined as ceil(COMB_RANGE / (SECP256K1_COMB_BLOCKS * SECP256K1_COMB_TEETH)). Each block covers + * COMB_SPACING * SECP256K1_COMB_TEETH consecutive bits in the input. * - * The size of the precomputed table is COMB_BLOCKS * (1 << (COMB_TEETH - 1)) + * The size of the precomputed table is SECP256K1_COMB_BLOCKS * (1 << (SECP256K1_COMB_TEETH - 1)) * secp256k1_ge_storages. * - * The number of point additions equals COMB_BLOCKS * COMB_SPACING. Each point - * addition involves a cmov from (1 << (COMB_TEETH - 1)) table entries and a + * The number of point additions equals SECP256K1_COMB_BLOCKS * COMB_SPACING. Each point + * addition involves a cmov from (1 << (SECP256K1_COMB_TEETH - 1)) table entries and a * conditional negation. * * The number of point doublings is COMB_SPACING - 1. */ -#if defined(EXHAUSTIVE_TEST_ORDER) +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) /* We need to control these values for exhaustive tests because * the table cannot have infinities in them (secp256k1_ge_storage * doesn't support infinities) */ -# undef COMB_BLOCKS -# undef COMB_TEETH -# if EXHAUSTIVE_TEST_ORDER == 7 +# undef SECP256K1_COMB_BLOCKS +# undef SECP256K1_COMB_TEETH +# if SECP256K1_EXHAUSTIVE_TEST_ORDER == 7 # define COMB_RANGE 3 -# define COMB_BLOCKS 1 -# define COMB_TEETH 2 -# elif EXHAUSTIVE_TEST_ORDER == 13 +# define SECP256K1_COMB_BLOCKS 1 +# define SECP256K1_COMB_TEETH 2 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 13 # define COMB_RANGE 4 -# define COMB_BLOCKS 1 -# define COMB_TEETH 2 -# elif EXHAUSTIVE_TEST_ORDER == 199 +# define SECP256K1_COMB_BLOCKS 1 +# define SECP256K1_COMB_TEETH 2 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 199 # define COMB_RANGE 8 -# define COMB_BLOCKS 2 -# define COMB_TEETH 3 +# define SECP256K1_COMB_BLOCKS 2 +# define SECP256K1_COMB_TEETH 3 # else # error "Unknown exhaustive test order" # endif -# if (COMB_RANGE >= 32) || ((EXHAUSTIVE_TEST_ORDER >> (COMB_RANGE - 1)) != 1) -# error "COMB_RANGE != ceil(log2(EXHAUSTIVE_TEST_ORDER+1))" +# if (COMB_RANGE >= 32) || ((SECP256K1_EXHAUSTIVE_TEST_ORDER >> (COMB_RANGE - 1)) != 1) +# error "COMB_RANGE != ceil(log2(SECP256K1_EXHAUSTIVE_TEST_ORDER+1))" # endif -#else /* !defined(EXHAUSTIVE_TEST_ORDER) */ +#else /* !defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) */ # define COMB_RANGE 256 -#endif /* defined(EXHAUSTIVE_TEST_ORDER) */ +#endif /* defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) */ /* Use (11, 6) as default configuration, which results in a 22 kB table. */ -#ifndef COMB_BLOCKS -# define COMB_BLOCKS 11 -# ifdef DEBUG_CONFIG -# pragma message DEBUG_CONFIG_MSG("COMB_BLOCKS undefined, assuming default value") +#ifndef SECP256K1_COMB_BLOCKS +# define SECP256K1_COMB_BLOCKS 11 +# ifdef SECP256K1_DEBUG_CONFIG +# pragma message DEBUG_CONFIG_MSG("SECP256K1_COMB_BLOCKS undefined, assuming default value") # endif #endif -#ifndef COMB_TEETH -# define COMB_TEETH 6 -# ifdef DEBUG_CONFIG -# pragma message DEBUG_CONFIG_MSG("COMB_TEETH undefined, assuming default value") +#ifndef SECP256K1_COMB_TEETH +# define SECP256K1_COMB_TEETH 6 +# ifdef SECP256K1_DEBUG_CONFIG +# pragma message DEBUG_CONFIG_MSG("SECP256K1_COMB_TEETH undefined, assuming default value") # endif #endif -/* Use ceil(COMB_RANGE / (COMB_BLOCKS * COMB_TEETH)) as COMB_SPACING. */ -#define COMB_SPACING CEIL_DIV(COMB_RANGE, COMB_BLOCKS * COMB_TEETH) +/* Use ceil(COMB_RANGE / (SECP256K1_COMB_BLOCKS * SECP256K1_COMB_TEETH)) as COMB_SPACING. */ +#define COMB_SPACING CEIL_DIV(COMB_RANGE, SECP256K1_COMB_BLOCKS * SECP256K1_COMB_TEETH) /* Range checks on the parameters. */ /* The remaining COMB_* parameters are derived values, don't modify these. */ /* - The number of bits covered by all the blocks; must be at least COMB_RANGE. */ -#define COMB_BITS (COMB_BLOCKS * COMB_TEETH * COMB_SPACING) +#define COMB_BITS (SECP256K1_COMB_BLOCKS * SECP256K1_COMB_TEETH * COMB_SPACING) /* - The number of entries per table. */ -#define COMB_POINTS (1 << (COMB_TEETH - 1)) +#define COMB_POINTS (1 << (SECP256K1_COMB_TEETH - 1)) /* Sanity checks. */ -#if !(1 <= COMB_BLOCKS && COMB_BLOCKS <= 256) -# error "COMB_BLOCKS must be in the range [1, 256]" +#if !(1 <= SECP256K1_COMB_BLOCKS && SECP256K1_COMB_BLOCKS <= 256) +# error "SECP256K1_COMB_BLOCKS must be in the range [1, 256]" #endif -#if !(1 <= COMB_TEETH && COMB_TEETH <= 8) -# error "COMB_TEETH must be in the range [1, 8]" +#if !(1 <= SECP256K1_COMB_TEETH && SECP256K1_COMB_TEETH <= 8) +# error "SECP256K1_COMB_TEETH must be in the range [1, 8]" #endif #if COMB_BITS < COMB_RANGE -# error "COMB_BLOCKS * COMB_TEETH * COMB_SPACING is too low" +# error "SECP256K1_COMB_BLOCKS * SECP256K1_COMB_TEETH * COMB_SPACING is too low" #endif /* These last 2 checks are not strictly required, but prevent gratuitously inefficient * configurations. Note that they compare with 256 rather than COMB_RANGE, so they do * permit somewhat excessive values for the exhaustive test case, where testing with * suboptimal parameters may be desirable. */ -#if (COMB_BLOCKS - 1) * COMB_TEETH * COMB_SPACING >= 256 -# error "COMB_BLOCKS can be reduced" +#if (SECP256K1_COMB_BLOCKS - 1) * SECP256K1_COMB_TEETH * COMB_SPACING >= 256 +# error "SECP256K1_COMB_BLOCKS can be reduced" #endif -#if COMB_BLOCKS * (COMB_TEETH - 1) * COMB_SPACING >= 256 -# error "COMB_TEETH can be reduced" +#if SECP256K1_COMB_BLOCKS * (SECP256K1_COMB_TEETH - 1) * COMB_SPACING >= 256 +# error "SECP256K1_COMB_TEETH can be reduced" #endif -#ifdef DEBUG_CONFIG +#ifdef SECP256K1_DEBUG_CONFIG # pragma message DEBUG_CONFIG_DEF(COMB_RANGE) -# pragma message DEBUG_CONFIG_DEF(COMB_BLOCKS) -# pragma message DEBUG_CONFIG_DEF(COMB_TEETH) +# pragma message DEBUG_CONFIG_DEF(SECP256K1_COMB_BLOCKS) +# pragma message DEBUG_CONFIG_DEF(SECP256K1_COMB_TEETH) # pragma message DEBUG_CONFIG_DEF(COMB_SPACING) #endif diff --git a/src/ecmult_gen_compute_table_impl.h b/src/ecmult_gen_compute_table_impl.h index 6aa8d84082..a64dcd54b2 100644 --- a/src/ecmult_gen_compute_table_impl.h +++ b/src/ecmult_gen_compute_table_impl.h @@ -37,7 +37,7 @@ static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, cons secp256k1_gej_add_ge_var(&u, &u, gen, NULL); } } -#ifdef VERIFY +#ifdef SECP256K1_VERIFY { /* Verify that u*2 = gen. */ secp256k1_gej double_u; diff --git a/src/ecmult_gen_impl.h b/src/ecmult_gen_impl.h index 2159eed5e1..7128bde4f7 100644 --- a/src/ecmult_gen_impl.h +++ b/src/ecmult_gen_impl.h @@ -118,9 +118,9 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 * (2*d[i]-1) * 2^(i-1) * G points, for various combinations of i positions. * We rewrite our equation in terms of these table entries. * - * Let mask(b) = sum(2^((b*COMB_TEETH + t)*COMB_SPACING) for t=0..COMB_TEETH-1), - * with b ranging from 0 to COMB_BLOCKS-1. So for example with COMB_BLOCKS=11, - * COMB_TEETH=6, COMB_SPACING=4, we would have: + * Let mask(b) = sum(2^((b*SECP256K1_COMB_TEETH + t)*COMB_SPACING) for t=0..SECP256K1_COMB_TEETH-1), + * with b ranging from 0 to SECP256K1_COMB_BLOCKS-1. So for example with SECP256K1_COMB_BLOCKS=11, + * SECP256K1_COMB_TEETH=6, COMB_SPACING=4, we would have: * mask(0) = 2^0 + 2^4 + 2^8 + 2^12 + 2^16 + 2^20, * mask(1) = 2^24 + 2^28 + 2^32 + 2^36 + 2^40 + 2^44, * mask(2) = 2^48 + 2^52 + 2^56 + 2^60 + 2^64 + 2^68, @@ -130,14 +130,14 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 * We will split up the bits d[i] using these masks. Specifically, each mask is * used COMB_SPACING times, with different shifts: * - * d = (d & mask(0)<<0) + (d & mask(1)<<0) + ... + (d & mask(COMB_BLOCKS-1)<<0) + - * (d & mask(0)<<1) + (d & mask(1)<<1) + ... + (d & mask(COMB_BLOCKS-1)<<1) + + * d = (d & mask(0)<<0) + (d & mask(1)<<0) + ... + (d & mask(SECP256K1_COMB_BLOCKS-1)<<0) + + * (d & mask(0)<<1) + (d & mask(1)<<1) + ... + (d & mask(SECP256K1_COMB_BLOCKS-1)<<1) + * ... * (d & mask(0)<<(COMB_SPACING-1)) + ... * * Now define table(b, m) = (m - mask(b)/2) * G, and we will precompute these values for - * b=0..COMB_BLOCKS-1, and for all values m which (d & mask(b)) can take (so m can take on - * 2^COMB_TEETH distinct values). + * b=0..SECP256K1_COMB_BLOCKS-1, and for all values m which (d & mask(b)) can take (so m can take on + * 2^SECP256K1_COMB_TEETH distinct values). * * If m=(d & mask(b)), then table(b, m) is the sum of 2^i * (2*d[i]-1) * G/2, with i * iterating over the set bits in mask(b). In our example, table(2, 2^48 + 2^56 + 2^68) @@ -145,15 +145,15 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 * * With that, we can rewrite comb(d, G/2) as: * - * 2^0 * (table(0, d>>0 & mask(0)) + ... + table(COMB_BLOCKS-1, d>>0 & mask(COMP_BLOCKS-1))) - * + 2^1 * (table(0, d>>1 & mask(0)) + ... + table(COMB_BLOCKS-1, d>>1 & mask(COMP_BLOCKS-1))) - * + 2^2 * (table(0, d>>2 & mask(0)) + ... + table(COMB_BLOCKS-1, d>>2 & mask(COMP_BLOCKS-1))) + * 2^0 * (table(0, d>>0 & mask(0)) + ... + table(SECP256K1_COMB_BLOCKS-1, d>>0 & mask(COMP_BLOCKS-1))) + * + 2^1 * (table(0, d>>1 & mask(0)) + ... + table(SECP256K1_COMB_BLOCKS-1, d>>1 & mask(COMP_BLOCKS-1))) + * + 2^2 * (table(0, d>>2 & mask(0)) + ... + table(SECP256K1_COMB_BLOCKS-1, d>>2 & mask(COMP_BLOCKS-1))) * + ... * + 2^(COMB_SPACING-1) * (table(0, d>>(COMB_SPACING-1) & mask(0)) + ...) * * Or more generically as * - * sum(2^i * sum(table(b, d>>i & mask(b)), b=0..COMB_BLOCKS-1), i=0..COMB_SPACING-1) + * sum(2^i * sum(table(b, d>>i & mask(b)), b=0..SECP256K1_COMB_BLOCKS-1), i=0..COMB_SPACING-1) * * This is implemented using an outer loop that runs in reverse order over the lines of this * equation, which in each iteration runs an inner loop that adds the terms of that line and @@ -162,7 +162,7 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 * In pseudocode: * c = infinity * for comb_off in range(COMB_SPACING - 1, -1, -1): - * for block in range(COMB_BLOCKS): + * for block in range(SECP256K1_COMB_BLOCKS): * c += table(block, (d >> comb_off) & mask(block)) * if comb_off > 0: * c = 2*c @@ -174,7 +174,7 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 * an incomplete addition formula for most of the multiplication. * * The last question is how to implement the table(b, m) function. For any value of b, - * m=(d & mask(b)) can only take on at most 2^COMB_TEETH possible values (the last one may have + * m=(d & mask(b)) can only take on at most 2^SECP256K1_COMB_TEETH possible values (the last one may have * fewer as there mask(b) may exceed the curve order). So we could create COMB_BLOCK tables * which contain a value for each such m value. * @@ -194,9 +194,9 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 uint32_t block; uint32_t bit_pos = comb_off; /* Inner loop: for each block, add table entries to the result. */ - for (block = 0; block < COMB_BLOCKS; ++block) { + for (block = 0; block < SECP256K1_COMB_BLOCKS; ++block) { /* Gather the mask(block)-selected bits of d into bits. They're packed: - * bits[tooth] = d[(block*COMB_TEETH + tooth)*COMB_SPACING + comb_off]. */ + * bits[tooth] = d[(block*SECP256K1_COMB_TEETH + tooth)*COMB_SPACING + comb_off]. */ uint32_t bits = 0, sign, abs, index, tooth; /* Instead of reading individual bits here to construct the bits variable, * build up the result by xoring rotated reads together. In every iteration, @@ -206,7 +206,7 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 * just two values when reading a single bit into a variable.) See: * https://www.usenix.org/system/files/conference/usenixsecurity18/sec18-alam.pdf */ - for (tooth = 0; tooth < COMB_TEETH; ++tooth) { + for (tooth = 0; tooth < SECP256K1_COMB_TEETH; ++tooth) { /* Construct bitdata s.t. the bottom bit is the bit we'd like to read. * * We could just set bitdata = recoded[bit_pos >> 5] >> (bit_pos & 0x1f) @@ -229,7 +229,7 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25 /* If the top bit of bits is 1, flip them all (corresponding to looking up * the negated table value), and remember to negate the result in sign. */ - sign = (bits >> (COMB_TEETH - 1)) & 1; + sign = (bits >> (SECP256K1_COMB_TEETH - 1)) & 1; abs = (bits ^ -sign) & (COMB_POINTS - 1); VERIFY_CHECK(sign == 0 || sign == 1); VERIFY_CHECK(abs < COMB_POINTS); diff --git a/src/ecmult_impl.h b/src/ecmult_impl.h index 1a05244c24..277e86d7e9 100644 --- a/src/ecmult_impl.h +++ b/src/ecmult_impl.h @@ -16,13 +16,13 @@ #include "ecmult.h" #include "precomputed_ecmult.h" -#if defined(EXHAUSTIVE_TEST_ORDER) +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) /* We need to lower these values for exhaustive tests because * the tables cannot have infinities in them (this breaks the * affine-isomorphism stuff which tracks z-ratios) */ -# if EXHAUSTIVE_TEST_ORDER > 128 +# if SECP256K1_EXHAUSTIVE_TEST_ORDER > 128 # define WINDOW_A 5 -# elif EXHAUSTIVE_TEST_ORDER > 8 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER > 8 # define WINDOW_A 4 # else # define WINDOW_A 2 @@ -30,7 +30,7 @@ #else /* optimal for 128-bit and 256-bit exponents. */ # define WINDOW_A 5 -/** Larger values for ECMULT_WINDOW_SIZE result in possibly better +/** Larger values for SECP256K1_ECMULT_WINDOW_SIZE result in possibly better * performance at the cost of an exponentially larger precomputed * table. The exact table size is * (1 << (WINDOW_G - 2)) * sizeof(secp256k1_ge_storage) bytes, @@ -205,7 +205,7 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a, bit += now; } -#ifdef VERIFY +#ifdef SECP256K1_VERIFY { int verify_bit = bit; diff --git a/src/field.h b/src/field.h index 945029ecd8..3f1fa8a543 100644 --- a/src/field.h +++ b/src/field.h @@ -24,12 +24,12 @@ * - magnitude: an integer in [0,32] * - normalized: 0 or 1; normalized=1 implies magnitude <= 1. * - * In VERIFY mode, they are materialized explicitly as fields in the struct, + * In SECP256K1_VERIFY mode, they are materialized explicitly as fields in the struct, * allowing run-time verification of these properties. In that case, the field * implementation also provides a secp256k1_fe_verify routine to verify that * these fields match the run-time value and perform internal consistency * checks. */ -#ifdef VERIFY +#ifdef SECP256K1_VERIFY # define SECP256K1_FE_VERIFY_FIELDS \ int magnitude; \ int normalized; @@ -45,7 +45,7 @@ #error "Please select wide multiplication implementation" #endif -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* Magnitude and normalized value for constants. */ #define SECP256K1_FE_VERIFY_CONST(d7, d6, d5, d4, d3, d2, d1, d0) \ /* Magnitude is 0 for constant 0; 1 otherwise. */ \ @@ -71,8 +71,8 @@ static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST( 0x9cf04975ul, 0x12f58995ul, 0xc1396c28ul, 0x719501eeul ); -#ifndef VERIFY -/* In non-VERIFY mode, we #define the fe operations to be identical to their +#ifndef SECP256K1_VERIFY +/* In non-SECP256K1_VERIFY mode, we #define the fe operations to be identical to their * internal field implementation, to avoid the potential overhead of a * function call (even though presumably inlinable). */ # define secp256k1_fe_normalize secp256k1_fe_impl_normalize @@ -101,7 +101,7 @@ static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST( # define secp256k1_fe_half secp256k1_fe_impl_half # define secp256k1_fe_add_int secp256k1_fe_impl_add_int # define secp256k1_fe_is_square_var secp256k1_fe_impl_is_square_var -#endif /* !defined(VERIFY) */ +#endif /* !defined(SECP256K1_VERIFY) */ /** Normalize a field element. * @@ -340,11 +340,11 @@ static void secp256k1_fe_get_bounds(secp256k1_fe *r, int m); */ static int secp256k1_fe_is_square_var(const secp256k1_fe *a); -/** Check invariants on a field element (no-op unless VERIFY is enabled). */ +/** Check invariants on a field element (no-op unless SECP256K1_VERIFY is enabled). */ static void secp256k1_fe_verify(const secp256k1_fe *a); #define SECP256K1_FE_VERIFY(a) secp256k1_fe_verify(a) -/** Check that magnitude of a is at most m (no-op unless VERIFY is enabled). */ +/** Check that magnitude of a is at most m (no-op unless SECP256K1_VERIFY is enabled). */ static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m); #define SECP256K1_FE_VERIFY_MAGNITUDE(a, m) secp256k1_fe_verify_magnitude(a, m) diff --git a/src/field_10x26_impl.h b/src/field_10x26_impl.h index aa45434d9d..a49721b686 100644 --- a/src/field_10x26_impl.h +++ b/src/field_10x26_impl.h @@ -12,7 +12,7 @@ #include "field.h" #include "modinv32_impl.h" -#ifdef VERIFY +#ifdef SECP256K1_VERIFY static void secp256k1_fe_impl_verify(const secp256k1_fe *a) { const uint32_t *d = a->n; int m = a->normalized ? 1 : 2 * a->magnitude; @@ -388,7 +388,7 @@ SECP256K1_INLINE static void secp256k1_fe_impl_add_int(secp256k1_fe *r, int a) { r->n[0] += a; } -#if defined(USE_EXTERNAL_ASM) +#if defined(SECP256K1_USE_EXTERNAL_ASM) /* External assembler implementation */ void secp256k1_fe_mul_inner(uint32_t *r, const uint32_t *a, const uint32_t * SECP256K1_RESTRICT b); @@ -1222,7 +1222,7 @@ static int secp256k1_fe_impl_is_square_var(const secp256k1_fe *x) { if (jac == 0) { /* secp256k1_jacobi32_maybe_var failed to compute the Jacobi symbol. Fall back * to computing a square root. This should be extremely rare with random - * input (except in VERIFY mode, where a lower iteration count is used). */ + * input (except in SECP256K1_VERIFY mode, where a lower iteration count is used). */ secp256k1_fe dummy; ret = secp256k1_fe_sqrt(&dummy, &tmp); } else { diff --git a/src/field_5x52_impl.h b/src/field_5x52_impl.h index 3a976135eb..3cbc0b1b40 100644 --- a/src/field_5x52_impl.h +++ b/src/field_5x52_impl.h @@ -14,7 +14,7 @@ #include "field_5x52_int128_impl.h" -#ifdef VERIFY +#ifdef SECP256K1_VERIFY static void secp256k1_fe_impl_verify(const secp256k1_fe *a) { const uint64_t *d = a->n; int m = a->normalized ? 1 : 2 * a->magnitude; @@ -512,7 +512,7 @@ static int secp256k1_fe_impl_is_square_var(const secp256k1_fe *x) { if (jac == 0) { /* secp256k1_jacobi64_maybe_var failed to compute the Jacobi symbol. Fall back * to computing a square root. This should be extremely rare with random - * input (except in VERIFY mode, where a lower iteration count is used). */ + * input (except in SECP256K1_VERIFY mode, where a lower iteration count is used). */ secp256k1_fe dummy; ret = secp256k1_fe_sqrt(&dummy, &tmp); } else { diff --git a/src/field_impl.h b/src/field_impl.h index 7aa7de431a..b80956ad59 100644 --- a/src/field_impl.h +++ b/src/field_impl.h @@ -135,7 +135,7 @@ static int secp256k1_fe_sqrt(secp256k1_fe * SECP256K1_RESTRICT r, const secp256k secp256k1_fe_sqr(&t1, r); ret = secp256k1_fe_equal(&t1, a); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY if (!ret) { secp256k1_fe_negate(&t1, &t1, 1); secp256k1_fe_normalize_var(&t1); @@ -145,7 +145,7 @@ static int secp256k1_fe_sqrt(secp256k1_fe * SECP256K1_RESTRICT r, const secp256k return ret; } -#ifndef VERIFY +#ifndef SECP256K1_VERIFY static void secp256k1_fe_verify(const secp256k1_fe *a) { (void)a; } static void secp256k1_fe_verify_magnitude(const secp256k1_fe *a, int m) { (void)a; (void)m; } #else @@ -452,6 +452,6 @@ SECP256K1_INLINE static void secp256k1_fe_half(secp256k1_fe *r) { SECP256K1_FE_VERIFY(r); } -#endif /* defined(VERIFY) */ +#endif /* defined(SECP256K1_VERIFY) */ #endif /* SECP256K1_FIELD_IMPL_H */ diff --git a/src/group.h b/src/group.h index ee3ebbbefe..f02019ffef 100644 --- a/src/group.h +++ b/src/group.h @@ -207,11 +207,11 @@ static void secp256k1_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *d */ static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge* ge); -/** Check invariants on an affine group element (no-op unless VERIFY is enabled). */ +/** Check invariants on an affine group element (no-op unless SECP256K1_VERIFY is enabled). */ static void secp256k1_ge_verify(const secp256k1_ge *a); #define SECP256K1_GE_VERIFY(a) secp256k1_ge_verify(a) -/** Check invariants on a Jacobian group element (no-op unless VERIFY is enabled). */ +/** Check invariants on a Jacobian group element (no-op unless SECP256K1_VERIFY is enabled). */ static void secp256k1_gej_verify(const secp256k1_gej *a); #define SECP256K1_GEJ_VERIFY(a) secp256k1_gej_verify(a) diff --git a/src/group_impl.h b/src/group_impl.h index f5169650a1..5963814e25 100644 --- a/src/group_impl.h +++ b/src/group_impl.h @@ -48,18 +48,18 @@ * - The subgroup has size less than 1000 to permit exhaustive testing. * - The subgroup admits an endomorphism of the form lambda*(x,y) == (beta*x,y). */ -#if defined(EXHAUSTIVE_TEST_ORDER) -# if EXHAUSTIVE_TEST_ORDER == 7 +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) +# if SECP256K1_EXHAUSTIVE_TEST_ORDER == 7 static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_7; #define SECP256K1_B 6 -# elif EXHAUSTIVE_TEST_ORDER == 13 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 13 static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_13; #define SECP256K1_B 2 -# elif EXHAUSTIVE_TEST_ORDER == 199 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 199 static const secp256k1_ge secp256k1_ge_const_g = SECP256K1_G_ORDER_199; #define SECP256K1_B 4 @@ -198,7 +198,7 @@ static void secp256k1_ge_set_gej_var(secp256k1_ge *r, secp256k1_gej *a) { static void secp256k1_ge_set_all_gej(secp256k1_ge *r, const secp256k1_gej *a, size_t len) { secp256k1_fe u; size_t i; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY for (i = 0; i < len; i++) { SECP256K1_GEJ_VERIFY(&a[i]); VERIFY_CHECK(!secp256k1_gej_is_infinity(&a[i])); @@ -226,7 +226,7 @@ static void secp256k1_ge_set_all_gej(secp256k1_ge *r, const secp256k1_gej *a, si secp256k1_ge_set_gej_zinv(&r[i], &a[i], &r[i].x); } -#ifdef VERIFY +#ifdef SECP256K1_VERIFY for (i = 0; i < len; i++) { SECP256K1_GE_VERIFY(&r[i]); } @@ -237,7 +237,7 @@ static void secp256k1_ge_set_all_gej_var(secp256k1_ge *r, const secp256k1_gej *a secp256k1_fe u; size_t i; size_t last_i = SIZE_MAX; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY for (i = 0; i < len; i++) { SECP256K1_GEJ_VERIFY(&a[i]); } @@ -279,7 +279,7 @@ static void secp256k1_ge_set_all_gej_var(secp256k1_ge *r, const secp256k1_gej *a } } -#ifdef VERIFY +#ifdef SECP256K1_VERIFY for (i = 0; i < len; i++) { SECP256K1_GE_VERIFY(&r[i]); } @@ -289,7 +289,7 @@ static void secp256k1_ge_set_all_gej_var(secp256k1_ge *r, const secp256k1_gej *a static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr) { size_t i; secp256k1_fe zs; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY for (i = 0; i < len; i++) { SECP256K1_GE_VERIFY(&a[i]); SECP256K1_FE_VERIFY(&zr[i]); @@ -312,7 +312,7 @@ static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const se } } -#ifdef VERIFY +#ifdef SECP256K1_VERIFY for (i = 0; i < len; i++) { SECP256K1_GE_VERIFY(&a[i]); } @@ -924,7 +924,7 @@ static void secp256k1_ge_mul_lambda(secp256k1_ge *r, const secp256k1_ge *a) { } static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge* ge) { -#ifdef EXHAUSTIVE_TEST_ORDER +#ifdef SECP256K1_EXHAUSTIVE_TEST_ORDER secp256k1_gej out; int i; SECP256K1_GE_VERIFY(ge); @@ -933,7 +933,7 @@ static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge* ge) { secp256k1_gej_set_infinity(&out); for (i = 0; i < 32; ++i) { secp256k1_gej_double_var(&out, &out, NULL); - if ((((uint32_t)EXHAUSTIVE_TEST_ORDER) >> (31 - i)) & 1) { + if ((((uint32_t)SECP256K1_EXHAUSTIVE_TEST_ORDER) >> (31 - i)) & 1) { secp256k1_gej_add_ge_var(&out, &out, ge, NULL); } } diff --git a/src/modinv32_impl.h b/src/modinv32_impl.h index 981d2abc6d..58178a1cdb 100644 --- a/src/modinv32_impl.h +++ b/src/modinv32_impl.h @@ -20,7 +20,7 @@ * implementation for N=30, using 30-bit signed limbs represented as int32_t. */ -#ifdef VERIFY +#ifdef SECP256K1_VERIFY static const secp256k1_modinv32_signed30 SECP256K1_SIGNED30_ONE = {{1}}; /* Compute a*factor and put it in r. All but the top limb in r will be in range [0,2^30). */ @@ -66,7 +66,7 @@ static void secp256k1_modinv32_normalize_30(secp256k1_modinv32_signed30 *r, int3 r5 = r->v[5], r6 = r->v[6], r7 = r->v[7], r8 = r->v[8]; volatile int32_t cond_add, cond_negate; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* Verify that all limbs are in range (-2^30,2^30). */ int i; for (i = 0; i < 9; ++i) { @@ -584,7 +584,7 @@ static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256 secp256k1_modinv32_signed30 e = {{1, 0, 0, 0, 0, 0, 0, 0, 0}}; secp256k1_modinv32_signed30 f = modinfo->modulus; secp256k1_modinv32_signed30 g = *x; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY int i = 0; #endif int j, len = 9; @@ -655,8 +655,8 @@ static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256 } /* Do up to 50 iterations of 30 posdivsteps (up to 1500 steps; more is extremely rare) each until f=1. - * In VERIFY mode use a lower number of iterations (750, close to the median 756), so failure actually occurs. */ -#ifdef VERIFY + * In SECP256K1_VERIFY mode use a lower number of iterations (750, close to the median 756), so failure actually occurs. */ +#ifdef SECP256K1_VERIFY #define JACOBI32_ITERATIONS 25 #else #define JACOBI32_ITERATIONS 50 diff --git a/src/modinv64_impl.h b/src/modinv64_impl.h index 548787bedf..bbb17ae025 100644 --- a/src/modinv64_impl.h +++ b/src/modinv64_impl.h @@ -26,7 +26,7 @@ typedef struct { int64_t u, v, q, r; } secp256k1_modinv64_trans2x2; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* Helper function to compute the absolute value of an int64_t. * (we don't use abs/labs/llabs as it depends on the int sizes). */ static int64_t secp256k1_modinv64_abs(int64_t v) { @@ -90,7 +90,7 @@ static void secp256k1_modinv64_normalize_62(secp256k1_modinv64_signed62 *r, int6 int64_t r0 = r->v[0], r1 = r->v[1], r2 = r->v[2], r3 = r->v[3], r4 = r->v[4]; volatile int64_t cond_add, cond_negate; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* Verify that all limbs are in range (-2^62,2^62). */ int i; for (i = 0; i < 5; ++i) { @@ -640,7 +640,7 @@ static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256 secp256k1_modinv64_signed62 e = {{1, 0, 0, 0, 0}}; secp256k1_modinv64_signed62 f = modinfo->modulus; secp256k1_modinv64_signed62 g = *x; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY int i = 0; #endif int j, len = 5; @@ -710,8 +710,8 @@ static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256 } /* Do up to 25 iterations of 62 posdivsteps (up to 1550 steps; more is extremely rare) each until f=1. - * In VERIFY mode use a lower number of iterations (744, close to the median 756), so failure actually occurs. */ -#ifdef VERIFY + * In SECP256K1_VERIFY mode use a lower number of iterations (744, close to the median 756), so failure actually occurs. */ +#ifdef SECP256K1_VERIFY #define JACOBI64_ITERATIONS 12 #else #define JACOBI64_ITERATIONS 25 diff --git a/src/modules/ellswift/main_impl.h b/src/modules/ellswift/main_impl.h index f9ef0ac86c..3ec529f3f7 100644 --- a/src/modules/ellswift/main_impl.h +++ b/src/modules/ellswift/main_impl.h @@ -267,7 +267,7 @@ static int secp256k1_ellswift_xswiftec_inv_var(secp256k1_fe *t, const secp256k1_ secp256k1_fe_negate(&q, &q, 1); /* q = -s*(4*(u^3+7)+3*u^2*s) */ if (!secp256k1_fe_is_square_var(&q)) return 0; ret = secp256k1_fe_sqrt(&r, &q); /* r = sqrt(-s*(4*(u^3+7)+3*u^2*s)) */ -#ifdef VERIFY +#ifdef SECP256K1_VERIFY VERIFY_CHECK(ret); #else (void)ret; @@ -310,7 +310,7 @@ static int secp256k1_ellswift_xswiftec_inv_var(secp256k1_fe *t, const secp256k1_ static void secp256k1_ellswift_prng(unsigned char* out32, const secp256k1_sha256 *hasher, uint32_t cnt) { secp256k1_sha256 hash = *hasher; unsigned char buf4[4]; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY size_t blocks = hash.bytes >> 6; #endif buf4[0] = cnt; diff --git a/src/modules/ellswift/tests_exhaustive_impl.h b/src/modules/ellswift/tests_exhaustive_impl.h index 839c24aee4..1e8f3fbd91 100644 --- a/src/modules/ellswift/tests_exhaustive_impl.h +++ b/src/modules/ellswift/tests_exhaustive_impl.h @@ -17,7 +17,7 @@ static void test_exhaustive_ellswift(const secp256k1_context *ctx, const secp256 * a tiny subgroup. In that sense it can't be really seen as exhaustive as * it doesn't (and for computational reasons obviously cannot) test the * entire domain ellswift operates under. */ - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_scalar scalar_i; unsigned char sec32[32]; unsigned char ell64[64]; diff --git a/src/modules/extrakeys/tests_exhaustive_impl.h b/src/modules/extrakeys/tests_exhaustive_impl.h index 645bae2d47..6e5ff06ea7 100644 --- a/src/modules/extrakeys/tests_exhaustive_impl.h +++ b/src/modules/extrakeys/tests_exhaustive_impl.h @@ -11,14 +11,14 @@ #include "main_impl.h" static void test_exhaustive_extrakeys(const secp256k1_context *ctx, const secp256k1_ge* group) { - secp256k1_keypair keypair[EXHAUSTIVE_TEST_ORDER - 1]; - secp256k1_pubkey pubkey[EXHAUSTIVE_TEST_ORDER - 1]; - secp256k1_xonly_pubkey xonly_pubkey[EXHAUSTIVE_TEST_ORDER - 1]; - int parities[EXHAUSTIVE_TEST_ORDER - 1]; - unsigned char xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - 1][32]; + secp256k1_keypair keypair[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1]; + secp256k1_pubkey pubkey[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1]; + secp256k1_xonly_pubkey xonly_pubkey[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1]; + int parities[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1]; + unsigned char xonly_pubkey_bytes[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1][32]; int i; - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_fe fe; secp256k1_scalar scalar_i; unsigned char buf[33]; @@ -56,9 +56,9 @@ static void test_exhaustive_extrakeys(const secp256k1_context *ctx, const secp25 CHECK(secp256k1_fe_is_odd(&fe) == parities[i - 1]); /* Verify that the higher half is identical to the lower half mirrored. */ - if (i > EXHAUSTIVE_TEST_ORDER / 2) { - CHECK(secp256k1_memcmp_var(xonly_pubkey_bytes[i - 1], xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - i - 1], 32) == 0); - CHECK(parities[i - 1] == 1 - parities[EXHAUSTIVE_TEST_ORDER - i - 1]); + if (i > SECP256K1_EXHAUSTIVE_TEST_ORDER / 2) { + CHECK(secp256k1_memcmp_var(xonly_pubkey_bytes[i - 1], xonly_pubkey_bytes[SECP256K1_EXHAUSTIVE_TEST_ORDER - i - 1], 32) == 0); + CHECK(parities[i - 1] == 1 - parities[SECP256K1_EXHAUSTIVE_TEST_ORDER - i - 1]); } } diff --git a/src/modules/musig/keyagg_impl.h b/src/modules/musig/keyagg_impl.h index 4eb48ddc87..a1abe90b4a 100644 --- a/src/modules/musig/keyagg_impl.h +++ b/src/modules/musig/keyagg_impl.h @@ -142,7 +142,7 @@ static int secp256k1_musig_pubkey_agg_callback(secp256k1_scalar *sc, secp256k1_g secp256k1_musig_pubkey_agg_ecmult_data *ctx = (secp256k1_musig_pubkey_agg_ecmult_data *) data; int ret; ret = secp256k1_pubkey_load(ctx->ctx, pt, ctx->pks[idx]); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* pubkey_load can't fail because the same pks have already been loaded in * `musig_compute_pks_hash` (and we test this). */ VERIFY_CHECK(ret); diff --git a/src/modules/musig/session_impl.h b/src/modules/musig/session_impl.h index 42fcd81e12..84302c4b0b 100644 --- a/src/modules/musig/session_impl.h +++ b/src/modules/musig/session_impl.h @@ -479,7 +479,7 @@ int secp256k1_musig_nonce_gen_counter(const secp256k1_context* ctx, secp256k1_mu VERIFY_CHECK(ret); ret = secp256k1_keypair_pub(ctx, &pubkey, keypair); VERIFY_CHECK(ret); -#ifndef VERIFY +#ifndef SECP256K1_VERIFY (void) ret; #endif diff --git a/src/modules/recovery/tests_exhaustive_impl.h b/src/modules/recovery/tests_exhaustive_impl.h index 6bbc02b9a8..b0b829a5fc 100644 --- a/src/modules/recovery/tests_exhaustive_impl.h +++ b/src/modules/recovery/tests_exhaustive_impl.h @@ -15,10 +15,10 @@ static void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const se uint64_t iter = 0; /* Loop */ - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { /* message */ - for (j = 1; j < EXHAUSTIVE_TEST_ORDER; j++) { /* key */ + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { /* message */ + for (j = 1; j < SECP256K1_EXHAUSTIVE_TEST_ORDER; j++) { /* key */ if (skip_section(&iter)) continue; - for (k = 1; k < EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */ + for (k = 1; k < SECP256K1_EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */ const int starting_k = k; secp256k1_fe r_dot_y_normalized; secp256k1_ecdsa_recoverable_signature rsig; @@ -39,8 +39,8 @@ static void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const se secp256k1_ecdsa_recoverable_signature_load(ctx, &r, &s, &recid, &rsig); r_from_k(&expected_r, group, k, &overflow); CHECK(r == expected_r); - CHECK((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER || - (k * (EXHAUSTIVE_TEST_ORDER - s)) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER); + CHECK((k * s) % SECP256K1_EXHAUSTIVE_TEST_ORDER == (i + r * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER || + (k * (SECP256K1_EXHAUSTIVE_TEST_ORDER - s)) % SECP256K1_EXHAUSTIVE_TEST_ORDER == (i + r * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER); /* The recid's second bit is for conveying overflow (R.x value >= group order). * In the actual secp256k1 this is an astronomically unlikely event, but in the * small group used here, it will almost certainly be the case for all points. @@ -51,7 +51,7 @@ static void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const se r_dot_y_normalized = group[k].y; secp256k1_fe_normalize(&r_dot_y_normalized); /* Also the recovery id is flipped depending if we hit the low-s branch */ - if ((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER) { + if ((k * s) % SECP256K1_EXHAUSTIVE_TEST_ORDER == (i + r * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER) { expected_recid |= secp256k1_fe_is_odd(&r_dot_y_normalized); } else { expected_recid |= !secp256k1_fe_is_odd(&r_dot_y_normalized); @@ -66,8 +66,8 @@ static void test_exhaustive_recovery_sign(const secp256k1_context *ctx, const se * signing. */ r_from_k(&expected_r, group, k, NULL); CHECK(r == expected_r); - CHECK((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER || - (k * (EXHAUSTIVE_TEST_ORDER - s)) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER); + CHECK((k * s) % SECP256K1_EXHAUSTIVE_TEST_ORDER == (i + r * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER || + (k * (SECP256K1_EXHAUSTIVE_TEST_ORDER - s)) % SECP256K1_EXHAUSTIVE_TEST_ORDER == (i + r * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER); /* Overflow means we've tried every possible nonce */ if (k < starting_k) { @@ -82,10 +82,10 @@ static void test_exhaustive_recovery_verify(const secp256k1_context *ctx, const /* This is essentially a copy of test_exhaustive_verify, with recovery added */ int s, r, msg, key; uint64_t iter = 0; - for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) { - for (r = 1; r < EXHAUSTIVE_TEST_ORDER; r++) { - for (msg = 1; msg < EXHAUSTIVE_TEST_ORDER; msg++) { - for (key = 1; key < EXHAUSTIVE_TEST_ORDER; key++) { + for (s = 1; s < SECP256K1_EXHAUSTIVE_TEST_ORDER; s++) { + for (r = 1; r < SECP256K1_EXHAUSTIVE_TEST_ORDER; r++) { + for (msg = 1; msg < SECP256K1_EXHAUSTIVE_TEST_ORDER; msg++) { + for (key = 1; key < SECP256K1_EXHAUSTIVE_TEST_ORDER; key++) { secp256k1_ge nonconst_ge; secp256k1_ecdsa_recoverable_signature rsig; secp256k1_ecdsa_signature sig; @@ -108,7 +108,7 @@ static void test_exhaustive_recovery_verify(const secp256k1_context *ctx, const /* Run through every k value that gives us this r and check that *one* works. * Note there could be none, there could be multiple, ECDSA is weird. */ should_verify = 0; - for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) { + for (k = 0; k < SECP256K1_EXHAUSTIVE_TEST_ORDER; k++) { secp256k1_scalar check_x_s; r_from_k(&check_x_s, group, k, NULL); if (r_s == check_x_s) { diff --git a/src/modules/schnorrsig/tests_exhaustive_impl.h b/src/modules/schnorrsig/tests_exhaustive_impl.h index 4b97b58dc2..fca2262d4e 100644 --- a/src/modules/schnorrsig/tests_exhaustive_impl.h +++ b/src/modules/schnorrsig/tests_exhaustive_impl.h @@ -25,19 +25,19 @@ static const unsigned char invalid_pubkey_bytes[][32] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ((EXHAUSTIVE_TEST_ORDER + 0UL) >> 24) & 0xFF, - ((EXHAUSTIVE_TEST_ORDER + 0UL) >> 16) & 0xFF, - ((EXHAUSTIVE_TEST_ORDER + 0UL) >> 8) & 0xFF, - (EXHAUSTIVE_TEST_ORDER + 0UL) & 0xFF + ((SECP256K1_EXHAUSTIVE_TEST_ORDER + 0UL) >> 24) & 0xFF, + ((SECP256K1_EXHAUSTIVE_TEST_ORDER + 0UL) >> 16) & 0xFF, + ((SECP256K1_EXHAUSTIVE_TEST_ORDER + 0UL) >> 8) & 0xFF, + (SECP256K1_EXHAUSTIVE_TEST_ORDER + 0UL) & 0xFF }, /* order + 1 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ((EXHAUSTIVE_TEST_ORDER + 1UL) >> 24) & 0xFF, - ((EXHAUSTIVE_TEST_ORDER + 1UL) >> 16) & 0xFF, - ((EXHAUSTIVE_TEST_ORDER + 1UL) >> 8) & 0xFF, - (EXHAUSTIVE_TEST_ORDER + 1UL) & 0xFF + ((SECP256K1_EXHAUSTIVE_TEST_ORDER + 1UL) >> 24) & 0xFF, + ((SECP256K1_EXHAUSTIVE_TEST_ORDER + 1UL) >> 16) & 0xFF, + ((SECP256K1_EXHAUSTIVE_TEST_ORDER + 1UL) >> 8) & 0xFF, + (SECP256K1_EXHAUSTIVE_TEST_ORDER + 1UL) & 0xFF }, /* field size */ { @@ -80,28 +80,28 @@ static void test_exhaustive_schnorrsig_verify(const secp256k1_context *ctx, cons int d; uint64_t iter = 0; /* Iterate over the possible public keys to verify against (through their corresponding DL d). */ - for (d = 1; d <= EXHAUSTIVE_TEST_ORDER / 2; ++d) { + for (d = 1; d <= SECP256K1_EXHAUSTIVE_TEST_ORDER / 2; ++d) { int actual_d; unsigned k; unsigned char pk32[32]; memcpy(pk32, xonly_pubkey_bytes[d - 1], 32); - actual_d = parities[d - 1] ? EXHAUSTIVE_TEST_ORDER - d : d; + actual_d = parities[d - 1] ? SECP256K1_EXHAUSTIVE_TEST_ORDER - d : d; /* Iterate over the possible valid first 32 bytes in the signature, through their corresponding DL k. - Values above EXHAUSTIVE_TEST_ORDER/2 refer to the entries in invalid_pubkey_bytes. */ - for (k = 1; k <= EXHAUSTIVE_TEST_ORDER / 2 + NUM_INVALID_KEYS; ++k) { + Values above SECP256K1_EXHAUSTIVE_TEST_ORDER/2 refer to the entries in invalid_pubkey_bytes. */ + for (k = 1; k <= SECP256K1_EXHAUSTIVE_TEST_ORDER / 2 + NUM_INVALID_KEYS; ++k) { unsigned char sig64[64]; int actual_k = -1; - int e_done[EXHAUSTIVE_TEST_ORDER] = {0}; + int e_done[SECP256K1_EXHAUSTIVE_TEST_ORDER] = {0}; int e_count_done = 0; if (skip_section(&iter)) continue; - if (k <= EXHAUSTIVE_TEST_ORDER / 2) { + if (k <= SECP256K1_EXHAUSTIVE_TEST_ORDER / 2) { memcpy(sig64, xonly_pubkey_bytes[k - 1], 32); - actual_k = parities[k - 1] ? EXHAUSTIVE_TEST_ORDER - k : k; + actual_k = parities[k - 1] ? SECP256K1_EXHAUSTIVE_TEST_ORDER - k : k; } else { - memcpy(sig64, invalid_pubkey_bytes[k - 1 - EXHAUSTIVE_TEST_ORDER / 2], 32); + memcpy(sig64, invalid_pubkey_bytes[k - 1 - SECP256K1_EXHAUSTIVE_TEST_ORDER / 2], 32); } /* Randomly generate messages until all challenges have been hit. */ - while (e_count_done < EXHAUSTIVE_TEST_ORDER) { + while (e_count_done < SECP256K1_EXHAUSTIVE_TEST_ORDER) { secp256k1_scalar e; unsigned char msg32[32]; testrand256(msg32); @@ -112,13 +112,13 @@ static void test_exhaustive_schnorrsig_verify(const secp256k1_context *ctx, cons 0..order=that s value; order+1=random bytes */ int count_valid = 0; unsigned int s; - for (s = 0; s <= EXHAUSTIVE_TEST_ORDER + 1; ++s) { + for (s = 0; s <= SECP256K1_EXHAUSTIVE_TEST_ORDER + 1; ++s) { int expect_valid, valid; - if (s <= EXHAUSTIVE_TEST_ORDER) { + if (s <= SECP256K1_EXHAUSTIVE_TEST_ORDER) { memset(sig64 + 32, 0, 32); secp256k1_write_be32(sig64 + 60, s); - expect_valid = actual_k != -1 && s != EXHAUSTIVE_TEST_ORDER && - (s == (actual_k + actual_d * e) % EXHAUSTIVE_TEST_ORDER); + expect_valid = actual_k != -1 && s != SECP256K1_EXHAUSTIVE_TEST_ORDER && + (s == (actual_k + actual_d * e) % SECP256K1_EXHAUSTIVE_TEST_ORDER); } else { testrand256(sig64 + 32); expect_valid = 0; @@ -144,12 +144,12 @@ static void test_exhaustive_schnorrsig_sign(const secp256k1_context *ctx, unsign secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT; /* Loop over keys. */ - for (d = 1; d < EXHAUSTIVE_TEST_ORDER; ++d) { + for (d = 1; d < SECP256K1_EXHAUSTIVE_TEST_ORDER; ++d) { int actual_d = d; - if (parities[d - 1]) actual_d = EXHAUSTIVE_TEST_ORDER - d; + if (parities[d - 1]) actual_d = SECP256K1_EXHAUSTIVE_TEST_ORDER - d; /* Loop over nonces. */ - for (k = 1; k < EXHAUSTIVE_TEST_ORDER; ++k) { - int e_done[EXHAUSTIVE_TEST_ORDER] = {0}; + for (k = 1; k < SECP256K1_EXHAUSTIVE_TEST_ORDER; ++k) { + int e_done[SECP256K1_EXHAUSTIVE_TEST_ORDER] = {0}; int e_count_done = 0; unsigned char msg32[32]; unsigned char sig64[64]; @@ -157,15 +157,15 @@ static void test_exhaustive_schnorrsig_sign(const secp256k1_context *ctx, unsign if (skip_section(&iter)) continue; extraparams.noncefp = secp256k1_hardened_nonce_function_smallint; extraparams.ndata = &k; - if (parities[k - 1]) actual_k = EXHAUSTIVE_TEST_ORDER - k; + if (parities[k - 1]) actual_k = SECP256K1_EXHAUSTIVE_TEST_ORDER - k; /* Generate random messages until all challenges have been tried. */ - while (e_count_done < EXHAUSTIVE_TEST_ORDER) { + while (e_count_done < SECP256K1_EXHAUSTIVE_TEST_ORDER) { secp256k1_scalar e; testrand256(msg32); secp256k1_schnorrsig_challenge(&e, xonly_pubkey_bytes[k - 1], msg32, sizeof(msg32), xonly_pubkey_bytes[d - 1]); /* Only do work if we hit a challenge we haven't tried before. */ if (!e_done[e]) { - secp256k1_scalar expected_s = (actual_k + e * actual_d) % EXHAUSTIVE_TEST_ORDER; + secp256k1_scalar expected_s = (actual_k + e * actual_d) % SECP256K1_EXHAUSTIVE_TEST_ORDER; unsigned char expected_s_bytes[32]; secp256k1_scalar_get_b32(expected_s_bytes, &expected_s); /* Invoke the real function to construct a signature. */ @@ -184,10 +184,10 @@ static void test_exhaustive_schnorrsig_sign(const secp256k1_context *ctx, unsign } static void test_exhaustive_schnorrsig(const secp256k1_context *ctx) { - secp256k1_keypair keypair[EXHAUSTIVE_TEST_ORDER - 1]; - secp256k1_xonly_pubkey xonly_pubkey[EXHAUSTIVE_TEST_ORDER - 1]; - int parity[EXHAUSTIVE_TEST_ORDER - 1]; - unsigned char xonly_pubkey_bytes[EXHAUSTIVE_TEST_ORDER - 1][32]; + secp256k1_keypair keypair[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1]; + secp256k1_xonly_pubkey xonly_pubkey[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1]; + int parity[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1]; + unsigned char xonly_pubkey_bytes[SECP256K1_EXHAUSTIVE_TEST_ORDER - 1][32]; unsigned i; /* Verify that all invalid_pubkey_bytes are actually invalid. */ @@ -197,7 +197,7 @@ static void test_exhaustive_schnorrsig(const secp256k1_context *ctx) { } /* Construct keypairs and xonly-pubkeys for the entire group. */ - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; ++i) { + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; ++i) { secp256k1_scalar scalar_i; unsigned char buf[32]; secp256k1_scalar_set_int(&scalar_i, i); diff --git a/src/precompute_ecmult.c b/src/precompute_ecmult.c index 8579c85f22..4fbceef5e7 100644 --- a/src/precompute_ecmult.c +++ b/src/precompute_ecmult.c @@ -56,7 +56,7 @@ static void print_two_tables(FILE *fp, int window_g) { int main(void) { /* Always compute all tables for window sizes up to 15. */ - int window_g = (ECMULT_WINDOW_SIZE < 15) ? 15 : ECMULT_WINDOW_SIZE; + int window_g = (SECP256K1_ECMULT_WINDOW_SIZE < 15) ? 15 : SECP256K1_ECMULT_WINDOW_SIZE; const char outfile[] = "src/precomputed_ecmult.c"; FILE* fp; @@ -74,13 +74,13 @@ int main(void) { fprintf(fp, "#include \"ecmult.h\"\n"); fprintf(fp, "#include \"precomputed_ecmult.h\"\n"); fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n"); - fprintf(fp, "#if ECMULT_WINDOW_SIZE > %d\n", window_g); - fprintf(fp, " #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build.\n"); + fprintf(fp, "#if SECP256K1_ECMULT_WINDOW_SIZE > %d\n", window_g); + fprintf(fp, " #error configuration mismatch, invalid SECP256K1_ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build.\n"); fprintf(fp, "#endif\n"); - fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n"); + fprintf(fp, "#ifdef SECP256K1_EXHAUSTIVE_TEST_ORDER\n"); fprintf(fp, "# error Cannot compile precomputed_ecmult.c in exhaustive test mode\n"); - fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n"); - fprintf(fp, "#define WINDOW_G ECMULT_WINDOW_SIZE\n"); + fprintf(fp, "#endif /* SECP256K1_EXHAUSTIVE_TEST_ORDER */\n"); + fprintf(fp, "#define WINDOW_G SECP256K1_ECMULT_WINDOW_SIZE\n"); print_two_tables(fp, window_g); diff --git a/src/precompute_ecmult_gen.c b/src/precompute_ecmult_gen.c index a03abdb548..231209bc94 100644 --- a/src/precompute_ecmult_gen.c +++ b/src/precompute_ecmult_gen.c @@ -33,7 +33,7 @@ static void print_table(FILE* fp, int blocks, int teeth) { secp256k1_ge_storage* table = checked_malloc(&default_error_callback, blocks * points * sizeof(secp256k1_ge_storage)); secp256k1_ecmult_gen_compute_table(table, &secp256k1_ge_const_g, blocks, teeth, spacing); - fprintf(fp, "#elif (COMB_BLOCKS == %d) && (COMB_TEETH == %d) && (COMB_SPACING == %d)\n", blocks, teeth, spacing); + fprintf(fp, "#elif (SECP256K1_COMB_BLOCKS == %d) && (SECP256K1_COMB_TEETH == %d) && (COMB_SPACING == %d)\n", blocks, teeth, spacing); for (outer = 0; outer != blocks; outer++) { fprintf(fp,"{"); for (inner = 0; inner != points; inner++) { @@ -73,21 +73,21 @@ int main(int argc, char **argv) { fprintf(fp, "#include \"group.h\"\n"); fprintf(fp, "#include \"ecmult_gen.h\"\n"); fprintf(fp, "#include \"precomputed_ecmult_gen.h\"\n"); - fprintf(fp, "#ifdef EXHAUSTIVE_TEST_ORDER\n"); + fprintf(fp, "#ifdef SECP256K1_EXHAUSTIVE_TEST_ORDER\n"); fprintf(fp, "# error Cannot compile precomputed_ecmult_gen.c in exhaustive test mode\n"); - fprintf(fp, "#endif /* EXHAUSTIVE_TEST_ORDER */\n"); + fprintf(fp, "#endif /* SECP256K1_EXHAUSTIVE_TEST_ORDER */\n"); fprintf(fp, "#define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u)\n"); - fprintf(fp, "const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS] = {\n"); + fprintf(fp, "const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[SECP256K1_COMB_BLOCKS][COMB_POINTS] = {\n"); fprintf(fp, "#if 0\n"); for (config = 0; config < ARRAY_SIZE(CONFIGS); ++config) { print_table(fp, CONFIGS[config][0], CONFIGS[config][1]); - if (CONFIGS[config][0] == COMB_BLOCKS && CONFIGS[config][1] == COMB_TEETH) { + if (CONFIGS[config][0] == SECP256K1_COMB_BLOCKS && CONFIGS[config][1] == SECP256K1_COMB_TEETH) { did_current_config = 1; } } if (!did_current_config) { - print_table(fp, COMB_BLOCKS, COMB_TEETH); + print_table(fp, SECP256K1_COMB_BLOCKS, SECP256K1_COMB_TEETH); } fprintf(fp, "#else\n"); fprintf(fp, "# error Configuration mismatch, invalid COMB_* parameters. Try deleting precomputed_ecmult_gen.c before the build.\n"); diff --git a/src/precomputed_ecmult.c b/src/precomputed_ecmult.c index cbd030ce50..1a63eff8ed 100644 --- a/src/precomputed_ecmult.c +++ b/src/precomputed_ecmult.c @@ -6,13 +6,13 @@ #include "ecmult.h" #include "precomputed_ecmult.h" #define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u) -#if ECMULT_WINDOW_SIZE > 15 - #error configuration mismatch, invalid ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build. +#if SECP256K1_ECMULT_WINDOW_SIZE > 15 + #error configuration mismatch, invalid SECP256K1_ECMULT_WINDOW_SIZE. Try deleting precomputed_ecmult.c before the build. #endif -#ifdef EXHAUSTIVE_TEST_ORDER +#ifdef SECP256K1_EXHAUSTIVE_TEST_ORDER # error Cannot compile precomputed_ecmult.c in exhaustive test mode -#endif /* EXHAUSTIVE_TEST_ORDER */ -#define WINDOW_G ECMULT_WINDOW_SIZE +#endif /* SECP256K1_EXHAUSTIVE_TEST_ORDER */ +#define WINDOW_G SECP256K1_ECMULT_WINDOW_SIZE const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)] = { S(79be667e,f9dcbbac,55a06295,ce870b07,29bfcdb,2dce28d9,59f2815b,16f81798,483ada77,26a3c465,5da4fbfc,e1108a8,fd17b448,a6855419,9c47d08f,fb10d4b8) #if WINDOW_G > 2 diff --git a/src/precomputed_ecmult.h b/src/precomputed_ecmult.h index e5a85f684f..1d60a620d6 100644 --- a/src/precomputed_ecmult.h +++ b/src/precomputed_ecmult.h @@ -15,23 +15,23 @@ extern "C" { #include "group.h" #include "util_local_visibility.h" -#if defined(EXHAUSTIVE_TEST_ORDER) -# if EXHAUSTIVE_TEST_ORDER == 7 +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) +# if SECP256K1_EXHAUSTIVE_TEST_ORDER == 7 # define WINDOW_G 3 -# elif EXHAUSTIVE_TEST_ORDER == 13 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 13 # define WINDOW_G 4 -# elif EXHAUSTIVE_TEST_ORDER == 199 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 199 # define WINDOW_G 8 # else # error No known generator for the specified exhaustive test group order. # endif static secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)]; static secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)]; -#else /* !defined(EXHAUSTIVE_TEST_ORDER) */ -# define WINDOW_G ECMULT_WINDOW_SIZE +#else /* !defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) */ +# define WINDOW_G SECP256K1_ECMULT_WINDOW_SIZE SECP256K1_LOCAL_VAR const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)]; SECP256K1_LOCAL_VAR const secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)]; -#endif /* defined(EXHAUSTIVE_TEST_ORDER) */ +#endif /* defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) */ #ifdef __cplusplus } diff --git a/src/precomputed_ecmult_gen.c b/src/precomputed_ecmult_gen.c index 248fb077e5..0b2ade2454 100644 --- a/src/precomputed_ecmult_gen.c +++ b/src/precomputed_ecmult_gen.c @@ -3,13 +3,13 @@ #include "group.h" #include "ecmult_gen.h" #include "precomputed_ecmult_gen.h" -#ifdef EXHAUSTIVE_TEST_ORDER +#ifdef SECP256K1_EXHAUSTIVE_TEST_ORDER # error Cannot compile precomputed_ecmult_gen.c in exhaustive test mode -#endif /* EXHAUSTIVE_TEST_ORDER */ +#endif /* SECP256K1_EXHAUSTIVE_TEST_ORDER */ #define S(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) SECP256K1_GE_STORAGE_CONST(0x##a##u,0x##b##u,0x##c##u,0x##d##u,0x##e##u,0x##f##u,0x##g##u,0x##h##u,0x##i##u,0x##j##u,0x##k##u,0x##l##u,0x##m##u,0x##n##u,0x##o##u,0x##p##u) -const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS] = { +const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[SECP256K1_COMB_BLOCKS][COMB_POINTS] = { #if 0 -#elif (COMB_BLOCKS == 2) && (COMB_TEETH == 5) && (COMB_SPACING == 26) +#elif (SECP256K1_COMB_BLOCKS == 2) && (SECP256K1_COMB_TEETH == 5) && (COMB_SPACING == 26) {S(7081b567,8cb87d01,99c9c76e,d1e0a5e0,1d784be9,27f6b135,161e0fd0,3f39b473,ad5222ac,f062cb39,21b234a7,15b626ae,f780b307,9b5122d1,53210f42,d9369242), S(228af17e,df90d1cc,a40173e9,478fa445,9780dacd,c3f15b90,fda5d00e,1faa1b51,8ff47c4d,a4ba636a,f656da9,12a81f79,6252496d,1e519886,b2c2b073,25be2b4a), S(b515ebe0,f48fb34e,9e01824c,d90553af,db116579,96667847,5ebaa700,242fd722,4cf08191,510fbf0,51f9e19a,198f11f6,ea31268c,2a6d384c,60557250,f0553c50), @@ -42,7 +42,7 @@ S(f7738800,b7fdf237,dc7f03fc,43724011,8b53aea4,4d7953d4,276f3b4d,bf5c0ff8,c1de79 S(5cb07874,ac4ffb86,2da619be,4c8fa38b,e8b261ec,3ec73a12,cd4cf8fc,4f8d5dae,549d1896,4931dabf,ba4553a2,461f2660,87733454,ea8eec6b,f671e3de,60c70340), S(5cc85d41,7b2ae9ac,dedb1b44,ce78d8a7,8f56b878,1a4b3af6,635a55c1,fead3be7,66a48c79,301e57d4,54cc8644,d2e778a8,45d85762,2c10eb98,d77eb873,e58bbeca), S(f27211c9,a067b01c,7fe7fbf7,7b5d9b0,eb0f2475,9d541457,6eb24ba4,19fd3db8,e26d28eb,89f7b518,e9ae0b88,fadbfb9b,641d3a44,c59c6f93,ec28a541,486e041e)} -#elif (COMB_BLOCKS == 11) && (COMB_TEETH == 6) && (COMB_SPACING == 4) +#elif (SECP256K1_COMB_BLOCKS == 11) && (SECP256K1_COMB_TEETH == 6) && (COMB_SPACING == 4) {S(629bee58,a391595f,eb20c534,4933937a,cdb2eba1,86d49f8b,845c1b5f,4ca87182,8dae4162,73c6c068,2e2aede4,76efa86b,7612c07e,f72070d0,dc4486f1,47e95085), S(6fd5e13c,a94b874b,28cd574b,726efdbf,143ab108,1089b846,7b5b2ebe,6c6a3c8f,4a4db306,52c9772a,868b2859,57c5a005,d83f6afa,6e65d87c,700da998,ce651396), S(609b6576,191514f4,83f5b428,500cfbaf,96871b8b,3348fe5c,1a131768,bb266b6f,90abb9c1,1bf184d2,8dbc424a,bbf74eb8,de4e0582,2ea5dd93,7d1e8b30,e5f695e7), @@ -395,7 +395,7 @@ S(96ca6bb4,bf74c748,75703386,ae02dc29,13329d9e,a5395892,df1c6f57,4a84fa4a,fcb510 S(36a066ae,694f2645,25cba884,956ebd46,ae568acf,11664965,63cee00d,a32f2199,5d1e975a,856ebd1a,cb1fe254,101e89ab,ea089e8a,b38bbd0f,1100e914,709fd965), S(4922879f,800234c9,63f4b572,d236843,4c4da5c8,ff741982,c3d1e341,841d1309,9b259470,24b5f4cb,97c68d18,f7f8dfca,1e57f7de,63208765,2ce15770,98f35494), S(ee27e2b,acf95f6d,dbb5ebae,bbf181bb,43322a3d,6db87e78,14e57a3d,41b581e0,3d6a18a,daf69ae4,88ecc9d8,7d6b1bf2,c8d65544,3f4b45b4,c5a0ac51,7b1dc3ca)} -#elif (COMB_BLOCKS == 43) && (COMB_TEETH == 6) && (COMB_SPACING == 1) +#elif (SECP256K1_COMB_BLOCKS == 43) && (SECP256K1_COMB_TEETH == 6) && (COMB_SPACING == 1) {S(e3adcb1a,fe947e6e,7cc4f5a2,df78310a,b235e2c3,bcd75eba,1904de80,c8814c50,e0b27ead,c4bbb9d2,37dad580,6e366674,4a9f9c3d,e024f2bd,1edb11d2,fafc0a22), S(612c2ec6,f0e9c4ec,c2200d23,ddca77eb,d003be35,61e52b1,890bf846,3bb53ea5,9e944d7b,dfc7a952,c1c5ee15,485d7199,dda19551,2d729628,c215a9e0,285f656a), S(42053dc0,9f90a7f7,86feca60,d68a5c3c,789e44d2,3479aa13,2d1a427c,621373a3,b338f891,f3930ec7,738669bb,3a29ae2d,637be08a,954f2a8c,acb661af,a660bd22), diff --git a/src/precomputed_ecmult_gen.h b/src/precomputed_ecmult_gen.h index 00ddce108b..53809415fb 100644 --- a/src/precomputed_ecmult_gen.h +++ b/src/precomputed_ecmult_gen.h @@ -15,11 +15,11 @@ extern "C" { #include "ecmult_gen.h" #include "util_local_visibility.h" -#ifdef EXHAUSTIVE_TEST_ORDER -static secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS]; +#ifdef SECP256K1_EXHAUSTIVE_TEST_ORDER +static secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[SECP256K1_COMB_BLOCKS][COMB_POINTS]; #else -SECP256K1_LOCAL_VAR const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS]; -#endif /* defined(EXHAUSTIVE_TEST_ORDER) */ +SECP256K1_LOCAL_VAR const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[SECP256K1_COMB_BLOCKS][COMB_POINTS]; +#endif /* defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) */ #ifdef __cplusplus } diff --git a/src/scalar.h b/src/scalar.h index 40d67191ac..ba0e2c5649 100644 --- a/src/scalar.h +++ b/src/scalar.h @@ -9,7 +9,7 @@ #include "util.h" -#if defined(EXHAUSTIVE_TEST_ORDER) +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) #include "scalar_low.h" #elif defined(SECP256K1_WIDEMUL_INT128) #include "scalar_4x64.h" @@ -98,7 +98,7 @@ static void secp256k1_scalar_mul_shift_var(secp256k1_scalar *r, const secp256k1_ /** If flag is 1, set *r equal to *a; if flag is 0, leave it. Constant-time. Both *r and *a must be initialized. Flag must be 0 or 1. */ static void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag); -/** Check invariants on a scalar (no-op unless VERIFY is enabled). */ +/** Check invariants on a scalar (no-op unless SECP256K1_VERIFY is enabled). */ static void secp256k1_scalar_verify(const secp256k1_scalar *r); #define SECP256K1_SCALAR_VERIFY(r) secp256k1_scalar_verify(r) diff --git a/src/scalar_4x64_impl.h b/src/scalar_4x64_impl.h index a5bf18feb9..0b0ceaaea9 100644 --- a/src/scalar_4x64_impl.h +++ b/src/scalar_4x64_impl.h @@ -221,7 +221,7 @@ static void secp256k1_scalar_half(secp256k1_scalar *r, const secp256k1_scalar *a secp256k1_u128_accum_u64(&t, SECP256K1_N_H_2 & mask); r->d[2] = secp256k1_u128_to_u64(&t); secp256k1_u128_rshift(&t, 64); r->d[3] = secp256k1_u128_to_u64(&t) + (a->d[3] >> 1) + (SECP256K1_N_H_3 & mask); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* The line above only computed the bottom 64 bits of r->d[3]; redo the computation * in full 128 bits to make sure the top 64 bits are indeed zero. */ secp256k1_u128_accum_u64(&t, a->d[3] >> 1); @@ -347,7 +347,7 @@ static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) { } static void secp256k1_scalar_reduce_512(secp256k1_scalar *r, const uint64_t *l) { -#ifdef USE_ASM_X86_64 +#ifdef SECP256K1_USE_ASM_X86_64 /* Reduce 512 bits into 385. */ uint64_t m0, m1, m2, m3, m4, m5, m6; uint64_t p0, p1, p2, p3, p4; @@ -678,7 +678,7 @@ static void secp256k1_scalar_reduce_512(secp256k1_scalar *r, const uint64_t *l) } static void secp256k1_scalar_mul_512(uint64_t *l8, const secp256k1_scalar *a, const secp256k1_scalar *b) { -#ifdef USE_ASM_X86_64 +#ifdef SECP256K1_USE_ASM_X86_64 const uint64_t *pb = b->d; __asm__ __volatile__( /* Preload */ @@ -966,7 +966,7 @@ static const secp256k1_modinv64_modinfo secp256k1_const_modinfo_scalar = { static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *x) { secp256k1_modinv64_signed62 s; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY int zero_in = secp256k1_scalar_is_zero(x); #endif SECP256K1_SCALAR_VERIFY(x); @@ -981,7 +981,7 @@ static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *x) { secp256k1_modinv64_signed62 s; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY int zero_in = secp256k1_scalar_is_zero(x); #endif SECP256K1_SCALAR_VERIFY(x); diff --git a/src/scalar_8x32_impl.h b/src/scalar_8x32_impl.h index aa87b1d3d1..f7445f70d6 100644 --- a/src/scalar_8x32_impl.h +++ b/src/scalar_8x32_impl.h @@ -782,7 +782,7 @@ static const secp256k1_modinv32_modinfo secp256k1_const_modinfo_scalar = { static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *x) { secp256k1_modinv32_signed30 s; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY int zero_in = secp256k1_scalar_is_zero(x); #endif SECP256K1_SCALAR_VERIFY(x); @@ -797,7 +797,7 @@ static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_scalar *x) { secp256k1_modinv32_signed30 s; -#ifdef VERIFY +#ifdef SECP256K1_VERIFY int zero_in = secp256k1_scalar_is_zero(x); #endif SECP256K1_SCALAR_VERIFY(x); diff --git a/src/scalar_impl.h b/src/scalar_impl.h index 9965c2bab9..4a30a5c1b2 100644 --- a/src/scalar_impl.h +++ b/src/scalar_impl.h @@ -7,14 +7,14 @@ #ifndef SECP256K1_SCALAR_IMPL_H #define SECP256K1_SCALAR_IMPL_H -#ifdef VERIFY +#ifdef SECP256K1_VERIFY #include #endif #include "scalar.h" #include "util.h" -#if defined(EXHAUSTIVE_TEST_ORDER) +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) #include "scalar_low_impl.h" #elif defined(SECP256K1_WIDEMUL_INT128) #include "scalar_4x64_impl.h" @@ -45,13 +45,13 @@ static void secp256k1_scalar_verify(const secp256k1_scalar *r) { (void)r; } -#if defined(EXHAUSTIVE_TEST_ORDER) +#if defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) /* Begin of section generated by sage/gen_exhaustive_groups.sage. */ -# if EXHAUSTIVE_TEST_ORDER == 7 +# if SECP256K1_EXHAUSTIVE_TEST_ORDER == 7 # define EXHAUSTIVE_TEST_LAMBDA 2 -# elif EXHAUSTIVE_TEST_ORDER == 13 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 13 # define EXHAUSTIVE_TEST_LAMBDA 9 -# elif EXHAUSTIVE_TEST_ORDER == 199 +# elif SECP256K1_EXHAUSTIVE_TEST_ORDER == 199 # define EXHAUSTIVE_TEST_LAMBDA 92 # else # error No known lambda for the specified exhaustive test group order. @@ -70,8 +70,8 @@ static void secp256k1_scalar_split_lambda(secp256k1_scalar * SECP256K1_RESTRICT VERIFY_CHECK(r2 != k); VERIFY_CHECK(r1 != r2); - *r2 = (*k + 5) % EXHAUSTIVE_TEST_ORDER; - *r1 = (*k + (EXHAUSTIVE_TEST_ORDER - *r2) * EXHAUSTIVE_TEST_LAMBDA) % EXHAUSTIVE_TEST_ORDER; + *r2 = (*k + 5) % SECP256K1_EXHAUSTIVE_TEST_ORDER; + *r1 = (*k + (SECP256K1_EXHAUSTIVE_TEST_ORDER - *r2) * EXHAUSTIVE_TEST_LAMBDA) % SECP256K1_EXHAUSTIVE_TEST_ORDER; SECP256K1_SCALAR_VERIFY(r1); SECP256K1_SCALAR_VERIFY(r2); @@ -85,7 +85,7 @@ static const secp256k1_scalar secp256k1_const_lambda = SECP256K1_SCALAR_CONST( 0x122E22EAUL, 0x20816678UL, 0xDF02967CUL, 0x1B23BD72UL ); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY static void secp256k1_scalar_split_lambda_verify(const secp256k1_scalar *r1, const secp256k1_scalar *r2, const secp256k1_scalar *k); #endif @@ -174,12 +174,12 @@ static void secp256k1_scalar_split_lambda(secp256k1_scalar * SECP256K1_RESTRICT SECP256K1_SCALAR_VERIFY(r1); SECP256K1_SCALAR_VERIFY(r2); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY secp256k1_scalar_split_lambda_verify(r1, r2, k); #endif } -#ifdef VERIFY +#ifdef SECP256K1_VERIFY /* * Proof for secp256k1_scalar_split_lambda's bounds. * @@ -315,7 +315,7 @@ static void secp256k1_scalar_split_lambda_verify(const secp256k1_scalar *r1, con secp256k1_scalar_get_b32(buf2, &s); VERIFY_CHECK(secp256k1_memcmp_var(buf1, k2_bound, 32) < 0 || secp256k1_memcmp_var(buf2, k2_bound, 32) < 0); } -#endif /* VERIFY */ -#endif /* !defined(EXHAUSTIVE_TEST_ORDER) */ +#endif /* SECP256K1_VERIFY */ +#endif /* !defined(SECP256K1_EXHAUSTIVE_TEST_ORDER) */ #endif /* SECP256K1_SCALAR_IMPL_H */ diff --git a/src/scalar_low.h b/src/scalar_low.h index 2711eb932d..9927d8a526 100644 --- a/src/scalar_low.h +++ b/src/scalar_low.h @@ -13,10 +13,10 @@ typedef uint32_t secp256k1_scalar; /* A compile-time constant equal to 2^32 (modulo order). */ -#define SCALAR_2P32 ((0xffffffffUL % EXHAUSTIVE_TEST_ORDER) + 1U) +#define SCALAR_2P32 ((0xffffffffUL % SECP256K1_EXHAUSTIVE_TEST_ORDER) + 1U) /* Compute a*2^32 + b (modulo order). */ -#define SCALAR_HORNER(a, b) (((uint64_t)(a) * SCALAR_2P32 + (b)) % EXHAUSTIVE_TEST_ORDER) +#define SCALAR_HORNER(a, b) (((uint64_t)(a) * SCALAR_2P32 + (b)) % SECP256K1_EXHAUSTIVE_TEST_ORDER) /* Evaluates to the provided 256-bit constant reduced modulo order. */ #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER((d7), (d6)), (d5)), (d4)), (d3)), (d2)), (d1)), (d0)) diff --git a/src/scalar_low_impl.h b/src/scalar_low_impl.h index 628bfd33e8..0793ebdfe0 100644 --- a/src/scalar_low_impl.h +++ b/src/scalar_low_impl.h @@ -20,7 +20,7 @@ SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a) } SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) { - *r = v % EXHAUSTIVE_TEST_ORDER; + *r = v % SECP256K1_EXHAUSTIVE_TEST_ORDER; SECP256K1_SCALAR_VERIFY(r); } @@ -42,13 +42,13 @@ SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_s return secp256k1_scalar_get_bits_limb32(a, offset, count); } -SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) { return *a >= EXHAUSTIVE_TEST_ORDER; } +SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) { return *a >= SECP256K1_EXHAUSTIVE_TEST_ORDER; } static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b) { SECP256K1_SCALAR_VERIFY(a); SECP256K1_SCALAR_VERIFY(b); - *r = (*a + *b) % EXHAUSTIVE_TEST_ORDER; + *r = (*a + *b) % SECP256K1_EXHAUSTIVE_TEST_ORDER; SECP256K1_SCALAR_VERIFY(r); return *r < *b; @@ -64,7 +64,7 @@ static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int SECP256K1_SCALAR_VERIFY(r); VERIFY_CHECK(bit < 32); /* Verify that adding (1 << bit) will not overflow any in-range scalar *r by overflowing the underlying uint32_t. */ - VERIFY_CHECK(((uint32_t)1 << bit) - 1 <= UINT32_MAX - EXHAUSTIVE_TEST_ORDER); + VERIFY_CHECK(((uint32_t)1 << bit) - 1 <= UINT32_MAX - SECP256K1_EXHAUSTIVE_TEST_ORDER); } static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *b32, int *overflow) { @@ -73,9 +73,9 @@ static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *b *r = 0; for (i = 0; i < 32; i++) { *r = (*r * 0x100) + b32[i]; - if (*r >= EXHAUSTIVE_TEST_ORDER) { + if (*r >= SECP256K1_EXHAUSTIVE_TEST_ORDER) { over = 1; - *r %= EXHAUSTIVE_TEST_ORDER; + *r %= SECP256K1_EXHAUSTIVE_TEST_ORDER; } } if (overflow) *overflow = over; @@ -102,7 +102,7 @@ static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar if (*a == 0) { *r = 0; } else { - *r = EXHAUSTIVE_TEST_ORDER - *a; + *r = SECP256K1_EXHAUSTIVE_TEST_ORDER - *a; } SECP256K1_SCALAR_VERIFY(r); @@ -117,7 +117,7 @@ SECP256K1_INLINE static int secp256k1_scalar_is_one(const secp256k1_scalar *a) { static int secp256k1_scalar_is_high(const secp256k1_scalar *a) { SECP256K1_SCALAR_VERIFY(a); - return *a > EXHAUSTIVE_TEST_ORDER / 2; + return *a > SECP256K1_EXHAUSTIVE_TEST_ORDER / 2; } static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) { @@ -134,7 +134,7 @@ static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, SECP256K1_SCALAR_VERIFY(a); SECP256K1_SCALAR_VERIFY(b); - *r = (*a * *b) % EXHAUSTIVE_TEST_ORDER; + *r = (*a * *b) % SECP256K1_EXHAUSTIVE_TEST_ORDER; SECP256K1_SCALAR_VERIFY(r); } @@ -175,8 +175,8 @@ static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar uint32_t res = 0; SECP256K1_SCALAR_VERIFY(x); - for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { - if ((i * *x) % EXHAUSTIVE_TEST_ORDER == 1) { + for (i = 0; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { + if ((i * *x) % SECP256K1_EXHAUSTIVE_TEST_ORDER == 1) { res = i; break; } @@ -201,7 +201,7 @@ static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_sc static void secp256k1_scalar_half(secp256k1_scalar *r, const secp256k1_scalar *a) { SECP256K1_SCALAR_VERIFY(a); - *r = (*a + ((-(uint32_t)(*a & 1)) & EXHAUSTIVE_TEST_ORDER)) >> 1; + *r = (*a + ((-(uint32_t)(*a & 1)) & SECP256K1_EXHAUSTIVE_TEST_ORDER)) >> 1; SECP256K1_SCALAR_VERIFY(r); } diff --git a/src/secp256k1.c b/src/secp256k1.c index 218ceafb31..9336444526 100644 --- a/src/secp256k1.c +++ b/src/secp256k1.c @@ -802,26 +802,26 @@ int secp256k1_tagged_sha256(const secp256k1_context* ctx, unsigned char *hash32, return 1; } -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH # include "modules/ecdh/main_impl.h" #endif -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY # include "modules/recovery/main_impl.h" #endif -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS # include "modules/extrakeys/main_impl.h" #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG # include "modules/schnorrsig/main_impl.h" #endif -#ifdef ENABLE_MODULE_MUSIG +#ifdef SECP256K1_ENABLE_MODULE_MUSIG # include "modules/musig/main_impl.h" #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT # include "modules/ellswift/main_impl.h" #endif diff --git a/src/tests.c b/src/tests.c index 7265d0df1d..55120fdf3b 100644 --- a/src/tests.c +++ b/src/tests.c @@ -10,12 +10,12 @@ #include -#ifdef USE_EXTERNAL_DEFAULT_CALLBACKS +#ifdef SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS #pragma message("Ignoring USE_EXTERNAL_CALLBACKS in tests.") - #undef USE_EXTERNAL_DEFAULT_CALLBACKS + #undef SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS #endif -#if defined(VERIFY) && defined(COVERAGE) - #pragma message("Defining VERIFY for tests being built for coverage analysis support is meaningless.") +#if defined(SECP256K1_VERIFY) && defined(SECP256K1_COVERAGE) + #pragma message("Defining SECP256K1_VERIFY for tests being built for coverage analysis support is meaningless.") #endif #include "secp256k1.c" @@ -3021,7 +3021,7 @@ static void run_field_half(void) { /* Check magnitude 0 input */ secp256k1_fe_get_bounds(&t, 0); secp256k1_fe_half(&t); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(t.magnitude == 1); CHECK(t.normalized == 0); #endif @@ -3034,7 +3034,7 @@ static void run_field_half(void) { u = t; secp256k1_fe_half(&u); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(u.magnitude == (m >> 1) + 1); CHECK(u.normalized == 0); #endif @@ -3053,7 +3053,7 @@ static void run_field_half(void) { u = t; secp256k1_fe_half(&u); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(u.magnitude == (m >> 1) + 1); CHECK(u.normalized == 0); #endif @@ -3095,7 +3095,7 @@ static void run_field_misc(void) { /* Test fe conditional move; z is not normalized here. */ q = x; secp256k1_fe_cmov(&x, &z, 0); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(!x.normalized); CHECK((x.magnitude == q.magnitude) || (x.magnitude == z.magnitude)); CHECK((x.magnitude >= q.magnitude) && (x.magnitude >= z.magnitude)); @@ -3105,7 +3105,7 @@ static void run_field_misc(void) { CHECK(!fe_identical(&x, &z)); CHECK(fe_identical(&x, &q)); secp256k1_fe_cmov(&q, &z, 1); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(!q.normalized); CHECK((q.magnitude == x.magnitude) || (q.magnitude == z.magnitude)); CHECK((q.magnitude >= x.magnitude) && (q.magnitude >= z.magnitude)); @@ -3117,14 +3117,14 @@ static void run_field_misc(void) { CHECK(!secp256k1_fe_equal(&x, &z)); secp256k1_fe_normalize_var(&q); secp256k1_fe_cmov(&q, &z, (i&1)); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(q.normalized && q.magnitude == 1); #endif for (j = 0; j < 6; j++) { secp256k1_fe_negate_unchecked(&z, &z, j+1); secp256k1_fe_normalize_var(&q); secp256k1_fe_cmov(&q, &z, (j&1)); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(!q.normalized && q.magnitude == z.magnitude); #endif } @@ -7497,27 +7497,27 @@ static void run_ecdsa_wycheproof(void) { test_ecdsa_wycheproof(); } -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH # include "modules/ecdh/tests_impl.h" #endif -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY # include "modules/recovery/tests_impl.h" #endif -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS # include "modules/extrakeys/tests_impl.h" #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG # include "modules/schnorrsig/tests_impl.h" #endif -#ifdef ENABLE_MODULE_MUSIG +#ifdef SECP256K1_ENABLE_MODULE_MUSIG # include "modules/musig/tests_impl.h" #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT # include "modules/ellswift/tests_impl.h" #endif @@ -7836,24 +7836,24 @@ static const struct tf_test_module registry_modules[] = { MAKE_TEST_MODULE(group), MAKE_TEST_MODULE(ecmult), MAKE_TEST_MODULE(ec), -#ifdef ENABLE_MODULE_ECDH +#ifdef SECP256K1_ENABLE_MODULE_ECDH MAKE_TEST_MODULE(ecdh), #endif MAKE_TEST_MODULE(ecdsa), -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY /* ECDSA pubkey recovery tests */ MAKE_TEST_MODULE(recovery), #endif -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS MAKE_TEST_MODULE(extrakeys), #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG MAKE_TEST_MODULE(schnorrsig), #endif -#ifdef ENABLE_MODULE_MUSIG +#ifdef SECP256K1_ENABLE_MODULE_MUSIG MAKE_TEST_MODULE(musig), #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT MAKE_TEST_MODULE(ellswift), #endif MAKE_TEST_MODULE(utils), diff --git a/src/tests_exhaustive.c b/src/tests_exhaustive.c index 68d4bec3f0..7f62900153 100644 --- a/src/tests_exhaustive.c +++ b/src/tests_exhaustive.c @@ -8,17 +8,17 @@ #include #include -#ifndef EXHAUSTIVE_TEST_ORDER +#ifndef SECP256K1_EXHAUSTIVE_TEST_ORDER /* see group_impl.h for allowable values */ -#define EXHAUSTIVE_TEST_ORDER 13 +#define SECP256K1_EXHAUSTIVE_TEST_ORDER 13 #endif /* These values of B are all values in [1, 8] that result in a curve with even order. */ #define EXHAUSTIVE_TEST_CURVE_HAS_EVEN_ORDER (SECP256K1_B == 1 || SECP256K1_B == 6 || SECP256K1_B == 8) -#ifdef USE_EXTERNAL_DEFAULT_CALLBACKS +#ifdef SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS #pragma message("Ignoring USE_EXTERNAL_CALLBACKS in exhaustive_tests.") - #undef USE_EXTERNAL_DEFAULT_CALLBACKS + #undef SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS #endif #include "secp256k1.c" @@ -55,7 +55,7 @@ static int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsig * function with an increased `attempt`. So if attempt > 0 this means we * need to change the nonce to avoid an infinite loop. */ if (attempt > 0) { - *idata = (*idata + 1) % EXHAUSTIVE_TEST_ORDER; + *idata = (*idata + 1) % SECP256K1_EXHAUSTIVE_TEST_ORDER; } secp256k1_scalar_set_int(&s, *idata); secp256k1_scalar_get_b32(nonce32, &s); @@ -64,10 +64,10 @@ static int secp256k1_nonce_function_smallint(unsigned char *nonce32, const unsig static void test_exhaustive_endomorphism(const secp256k1_ge *group) { int i; - for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 0; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_ge res; secp256k1_ge_mul_lambda(&res, &group[i]); - CHECK(secp256k1_ge_eq_var(&group[i * EXHAUSTIVE_TEST_LAMBDA % EXHAUSTIVE_TEST_ORDER], &res)); + CHECK(secp256k1_ge_eq_var(&group[i * EXHAUSTIVE_TEST_LAMBDA % SECP256K1_EXHAUSTIVE_TEST_ORDER], &res)); } } @@ -78,30 +78,30 @@ static void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_ /* Sanity-check (and check infinity functions) */ CHECK(secp256k1_ge_is_infinity(&group[0])); CHECK(secp256k1_gej_is_infinity(&groupj[0])); - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { CHECK(!secp256k1_ge_is_infinity(&group[i])); CHECK(!secp256k1_gej_is_infinity(&groupj[i])); } /* Check all addition formulae */ - for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { + for (j = 0; j < SECP256K1_EXHAUSTIVE_TEST_ORDER; j++) { secp256k1_fe fe_inv; if (skip_section(&iter)) continue; secp256k1_fe_inv(&fe_inv, &groupj[j].z); - for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 0; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_ge zless_gej; secp256k1_gej tmp; /* add_var */ secp256k1_gej_add_var(&tmp, &groupj[i], &groupj[j], NULL); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); /* add_ge */ if (j > 0) { secp256k1_gej_add_ge(&tmp, &groupj[i], &group[j]); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); } /* add_ge_var */ secp256k1_gej_add_ge_var(&tmp, &groupj[i], &group[j], NULL); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); /* add_zinv_var */ if (secp256k1_gej_is_infinity(&groupj[j])) { secp256k1_ge_set_infinity(&zless_gej); @@ -109,50 +109,50 @@ static void test_exhaustive_addition(const secp256k1_ge *group, const secp256k1_ secp256k1_ge_set_xy(&zless_gej, &groupj[j].x, &groupj[j].y); } secp256k1_gej_add_zinv_var(&tmp, &groupj[i], &zless_gej, &fe_inv); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i + j) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); } } /* Check doubling */ - for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 0; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_gej tmp; secp256k1_gej_double(&tmp, &groupj[i]); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(2 * i) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(2 * i) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); secp256k1_gej_double_var(&tmp, &groupj[i], NULL); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(2 * i) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(2 * i) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); } /* Check negation */ - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_ge tmp; secp256k1_gej tmpj; secp256k1_ge_neg(&tmp, &group[i]); - CHECK(secp256k1_ge_eq_var(&tmp, &group[EXHAUSTIVE_TEST_ORDER - i])); + CHECK(secp256k1_ge_eq_var(&tmp, &group[SECP256K1_EXHAUSTIVE_TEST_ORDER - i])); secp256k1_gej_neg(&tmpj, &groupj[i]); - CHECK(secp256k1_gej_eq_ge_var(&tmpj, &group[EXHAUSTIVE_TEST_ORDER - i])); + CHECK(secp256k1_gej_eq_ge_var(&tmpj, &group[SECP256K1_EXHAUSTIVE_TEST_ORDER - i])); } } static void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_gej *groupj) { int i, j, r_log; uint64_t iter = 0; - for (r_log = 1; r_log < EXHAUSTIVE_TEST_ORDER; r_log++) { - for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { + for (r_log = 1; r_log < SECP256K1_EXHAUSTIVE_TEST_ORDER; r_log++) { + for (j = 0; j < SECP256K1_EXHAUSTIVE_TEST_ORDER; j++) { if (skip_section(&iter)) continue; - for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 0; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_gej tmp; secp256k1_scalar na, ng; secp256k1_scalar_set_int(&na, i); secp256k1_scalar_set_int(&ng, j); secp256k1_ecmult(&tmp, &groupj[r_log], &na, &ng); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i * r_log + j) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i * r_log + j) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); } } } - for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { - for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (j = 0; j < SECP256K1_EXHAUSTIVE_TEST_ORDER; j++) { + for (i = 0; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { int ret; secp256k1_gej tmp; secp256k1_fe xn, xd, tmpf; @@ -164,20 +164,20 @@ static void test_exhaustive_ecmult(const secp256k1_ge *group, const secp256k1_ge /* Test secp256k1_ecmult_const. */ secp256k1_ecmult_const(&tmp, &group[i], &ng); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i * j) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); if (i != 0 && j != 0) { /* Test secp256k1_ecmult_const_xonly with all curve X coordinates, and xd=NULL. */ ret = secp256k1_ecmult_const_xonly(&tmpf, &group[i].x, NULL, &ng, 0); CHECK(ret); - CHECK(secp256k1_fe_equal(&tmpf, &group[(i * j) % EXHAUSTIVE_TEST_ORDER].x)); + CHECK(secp256k1_fe_equal(&tmpf, &group[(i * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER].x)); /* Test secp256k1_ecmult_const_xonly with all curve X coordinates, with random xd. */ testutil_random_fe_non_zero(&xd); secp256k1_fe_mul(&xn, &xd, &group[i].x); ret = secp256k1_ecmult_const_xonly(&tmpf, &xn, &xd, &ng, 0); CHECK(ret); - CHECK(secp256k1_fe_equal(&tmpf, &group[(i * j) % EXHAUSTIVE_TEST_ORDER].x)); + CHECK(secp256k1_fe_equal(&tmpf, &group[(i * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER].x)); } } } @@ -199,12 +199,12 @@ static void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const sec int i, j, k, x, y; uint64_t iter = 0; secp256k1_scratch *scratch = secp256k1_scratch_create(&ctx->error_callback, 4096); - for (i = 0; i < EXHAUSTIVE_TEST_ORDER; i++) { - for (j = 0; j < EXHAUSTIVE_TEST_ORDER; j++) { - for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) { - for (x = 0; x < EXHAUSTIVE_TEST_ORDER; x++) { + for (i = 0; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { + for (j = 0; j < SECP256K1_EXHAUSTIVE_TEST_ORDER; j++) { + for (k = 0; k < SECP256K1_EXHAUSTIVE_TEST_ORDER; k++) { + for (x = 0; x < SECP256K1_EXHAUSTIVE_TEST_ORDER; x++) { if (skip_section(&iter)) continue; - for (y = 0; y < EXHAUSTIVE_TEST_ORDER; y++) { + for (y = 0; y < SECP256K1_EXHAUSTIVE_TEST_ORDER; y++) { secp256k1_gej tmp; secp256k1_scalar g_sc; ecmult_multi_data data; @@ -216,7 +216,7 @@ static void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const sec data.pt[1] = group[y]; secp256k1_ecmult_multi_var(&ctx->error_callback, scratch, &tmp, &g_sc, ecmult_multi_callback, &data, 2); - CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i * x + j * y + k) % EXHAUSTIVE_TEST_ORDER])); + CHECK(secp256k1_gej_eq_ge_var(&tmp, &group[(i * x + j * y + k) % SECP256K1_EXHAUSTIVE_TEST_ORDER])); } } } @@ -228,7 +228,7 @@ static void test_exhaustive_ecmult_multi(const secp256k1_context *ctx, const sec static void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* overflow) { secp256k1_fe x; unsigned char x_bin[32]; - k %= EXHAUSTIVE_TEST_ORDER; + k %= SECP256K1_EXHAUSTIVE_TEST_ORDER; x = group[k].x; secp256k1_fe_normalize(&x); secp256k1_fe_get_b32(x_bin, &x); @@ -238,10 +238,10 @@ static void r_from_k(secp256k1_scalar *r, const secp256k1_ge *group, int k, int* static void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1_ge *group) { int s, r, msg, key; uint64_t iter = 0; - for (s = 1; s < EXHAUSTIVE_TEST_ORDER; s++) { - for (r = 1; r < EXHAUSTIVE_TEST_ORDER; r++) { - for (msg = 1; msg < EXHAUSTIVE_TEST_ORDER; msg++) { - for (key = 1; key < EXHAUSTIVE_TEST_ORDER; key++) { + for (s = 1; s < SECP256K1_EXHAUSTIVE_TEST_ORDER; s++) { + for (r = 1; r < SECP256K1_EXHAUSTIVE_TEST_ORDER; r++) { + for (msg = 1; msg < SECP256K1_EXHAUSTIVE_TEST_ORDER; msg++) { + for (key = 1; key < SECP256K1_EXHAUSTIVE_TEST_ORDER; key++) { secp256k1_ge nonconst_ge; secp256k1_ecdsa_signature sig; secp256k1_pubkey pk; @@ -261,7 +261,7 @@ static void test_exhaustive_verify(const secp256k1_context *ctx, const secp256k1 /* Run through every k value that gives us this r and check that *one* works. * Note there could be none, there could be multiple, ECDSA is weird. */ should_verify = 0; - for (k = 0; k < EXHAUSTIVE_TEST_ORDER; k++) { + for (k = 0; k < SECP256K1_EXHAUSTIVE_TEST_ORDER; k++) { secp256k1_scalar check_x_s; r_from_k(&check_x_s, group, k, NULL); if (r_s == check_x_s) { @@ -293,10 +293,10 @@ static void test_exhaustive_sign(const secp256k1_context *ctx, const secp256k1_g uint64_t iter = 0; /* Loop */ - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { /* message */ - for (j = 1; j < EXHAUSTIVE_TEST_ORDER; j++) { /* key */ + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { /* message */ + for (j = 1; j < SECP256K1_EXHAUSTIVE_TEST_ORDER; j++) { /* key */ if (skip_section(&iter)) continue; - for (k = 1; k < EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */ + for (k = 1; k < SECP256K1_EXHAUSTIVE_TEST_ORDER; k++) { /* nonce */ const int starting_k = k; int ret; secp256k1_ecdsa_signature sig; @@ -316,8 +316,8 @@ static void test_exhaustive_sign(const secp256k1_context *ctx, const secp256k1_g * signing. */ r_from_k(&expected_r, group, k, NULL); CHECK(r == expected_r); - CHECK((k * s) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER || - (k * (EXHAUSTIVE_TEST_ORDER - s)) % EXHAUSTIVE_TEST_ORDER == (i + r * j) % EXHAUSTIVE_TEST_ORDER); + CHECK((k * s) % SECP256K1_EXHAUSTIVE_TEST_ORDER == (i + r * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER || + (k * (SECP256K1_EXHAUSTIVE_TEST_ORDER - s)) % SECP256K1_EXHAUSTIVE_TEST_ORDER == (i + r * j) % SECP256K1_EXHAUSTIVE_TEST_ORDER); /* Overflow means we've tried every possible nonce */ if (k < starting_k) { @@ -337,26 +337,26 @@ static void test_exhaustive_sign(const secp256k1_context *ctx, const secp256k1_g */ } -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY #include "modules/recovery/tests_exhaustive_impl.h" #endif -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS #include "modules/extrakeys/tests_exhaustive_impl.h" #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG #include "modules/schnorrsig/tests_exhaustive_impl.h" #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT #include "modules/ellswift/tests_exhaustive_impl.h" #endif int main(int argc, char** argv) { int i; - secp256k1_gej groupj[EXHAUSTIVE_TEST_ORDER]; - secp256k1_ge group[EXHAUSTIVE_TEST_ORDER]; + secp256k1_gej groupj[SECP256K1_EXHAUSTIVE_TEST_ORDER]; + secp256k1_ge group[SECP256K1_EXHAUSTIVE_TEST_ORDER]; unsigned char rand32[32]; secp256k1_context *ctx; @@ -368,7 +368,7 @@ int main(int argc, char** argv) { * unbuffered on all systems. */ setbuf(stderr, NULL); - printf("Exhaustive tests for order %lu\n", (unsigned long)EXHAUSTIVE_TEST_ORDER); + printf("Exhaustive tests for order %lu\n", (unsigned long)SECP256K1_EXHAUSTIVE_TEST_ORDER); /* find iteration count */ if (argc > 1) { @@ -390,8 +390,8 @@ int main(int argc, char** argv) { printf("running tests for core %lu (out of [0..%lu])\n", (unsigned long)this_core, (unsigned long)num_cores - 1); } - /* Recreate the ecmult{,_gen} tables using the right generator (as selected via EXHAUSTIVE_TEST_ORDER) */ - secp256k1_ecmult_gen_compute_table(&secp256k1_ecmult_gen_prec_table[0][0], &secp256k1_ge_const_g, COMB_BLOCKS, COMB_TEETH, COMB_SPACING); + /* Recreate the ecmult{,_gen} tables using the right generator (as selected via SECP256K1_EXHAUSTIVE_TEST_ORDER) */ + secp256k1_ecmult_gen_compute_table(&secp256k1_ecmult_gen_prec_table[0][0], &secp256k1_ge_const_g, SECP256K1_COMB_BLOCKS, SECP256K1_COMB_TEETH, COMB_SPACING); secp256k1_ecmult_compute_two_tables(secp256k1_pre_g, secp256k1_pre_g_128, WINDOW_G, &secp256k1_ge_const_g); while (count--) { @@ -403,7 +403,7 @@ int main(int argc, char** argv) { /* Generate the entire group */ secp256k1_gej_set_infinity(&groupj[0]); secp256k1_ge_set_gej(&group[0], &groupj[0]); - for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) { + for (i = 1; i < SECP256K1_EXHAUSTIVE_TEST_ORDER; i++) { secp256k1_gej_add_ge(&groupj[i], &groupj[i - 1], &secp256k1_ge_const_g); secp256k1_ge_set_gej(&group[i], &groupj[i]); if (count != 0) { @@ -437,16 +437,16 @@ int main(int argc, char** argv) { test_exhaustive_sign(ctx, group); test_exhaustive_verify(ctx, group); -#ifdef ENABLE_MODULE_RECOVERY +#ifdef SECP256K1_ENABLE_MODULE_RECOVERY test_exhaustive_recovery(ctx, group); #endif -#ifdef ENABLE_MODULE_EXTRAKEYS +#ifdef SECP256K1_ENABLE_MODULE_EXTRAKEYS test_exhaustive_extrakeys(ctx, group); #endif -#ifdef ENABLE_MODULE_SCHNORRSIG +#ifdef SECP256K1_ENABLE_MODULE_SCHNORRSIG test_exhaustive_schnorrsig(ctx); #endif -#ifdef ENABLE_MODULE_ELLSWIFT +#ifdef SECP256K1_ENABLE_MODULE_ELLSWIFT /* The ellswift algorithm does have additional edge cases when operating on * curves of even order, which are not included in the code as secp256k1 is * of odd order. Skip the ellswift tests if the used exhaustive tests curve diff --git a/src/testutil.h b/src/testutil.h index 93ee3d58b5..16b3da0ec0 100644 --- a/src/testutil.h +++ b/src/testutil.h @@ -46,7 +46,7 @@ static void testutil_random_fe_magnitude(secp256k1_fe *fe, int m) { secp256k1_fe_negate(&zero, &zero, 0); secp256k1_fe_mul_int_unchecked(&zero, n - 1); secp256k1_fe_add(fe, &zero); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY CHECK(fe->magnitude == n); #endif } diff --git a/src/unit_test.c b/src/unit_test.c index a1858a117a..580a7bfac8 100644 --- a/src/unit_test.c +++ b/src/unit_test.c @@ -7,7 +7,7 @@ #include #include -#if defined(SUPPORTS_CONCURRENCY) +#if defined(SECP256K1_SUPPORTS_CONCURRENCY) #include #include #include @@ -277,7 +277,7 @@ static int run_sequential(struct tf_framework* tf) { return EXIT_SUCCESS; } -#if defined(SUPPORTS_CONCURRENCY) +#if defined(SECP256K1_SUPPORTS_CONCURRENCY) static const int MAX_TARGETS = 255; /* Process tests in parallel */ @@ -463,7 +463,7 @@ static int tf_run(struct tf_framework* tf) { if (tf->args.num_processes <= 1) { status = run_sequential(tf); } else { -#if defined(SUPPORTS_CONCURRENCY) +#if defined(SECP256K1_SUPPORTS_CONCURRENCY) status = run_concurrent(tf); #else fputs("Parallel execution not supported on your system. Running sequentially...\n", stderr); diff --git a/src/util.h b/src/util.h index 5d03e4c76d..4ffab1da12 100644 --- a/src/util.h +++ b/src/util.h @@ -22,7 +22,7 @@ #define STR_(x) #x #define STR(x) STR_(x) -#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x +#define DEBUG_CONFIG_MSG(x) "SECP256K1_DEBUG_CONFIG: " x #define DEBUG_CONFIG_DEF(x) DEBUG_CONFIG_MSG(#x "=" STR(x)) /* Debug helper for printing arrays of unsigned char. */ @@ -93,7 +93,7 @@ static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback * cb->fn(text, (void*)cb->data); } -#ifndef USE_EXTERNAL_DEFAULT_CALLBACKS +#ifndef SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS static void secp256k1_default_illegal_callback_fn(const char* str, void* data) { (void)data; fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str); @@ -120,7 +120,7 @@ static const secp256k1_callback default_error_callback = { }; -#ifdef DETERMINISTIC +#ifdef SECP256K1_DETERMINISTIC #define TEST_FAILURE(msg) do { \ fprintf(stderr, "%s\n", msg); \ abort(); \ @@ -138,7 +138,7 @@ static const secp256k1_callback default_error_callback = { #define EXPECT(x,c) (x) #endif -#ifdef DETERMINISTIC +#ifdef SECP256K1_DETERMINISTIC #define CHECK(cond) do { \ if (EXPECT(!(cond), 0)) { \ TEST_FAILURE("test condition failed"); \ @@ -152,8 +152,8 @@ static const secp256k1_callback default_error_callback = { } while(0) #endif -/* Like assert(), but when VERIFY is defined. */ -#if defined(VERIFY) +/* Like assert(), but when SECP256K1_VERIFY is defined. */ +#if defined(SECP256K1_VERIFY) #define VERIFY_CHECK CHECK #else #define VERIFY_CHECK(cond) @@ -183,8 +183,8 @@ static SECP256K1_INLINE void *checked_malloc(const secp256k1_callback* cb, size_ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -/* Macro for restrict, when available and not in a VERIFY build. */ -#if defined(SECP256K1_BUILD) && defined(VERIFY) +/* Macro for restrict, when available and not in a SECP256K1_VERIFY build. */ +#if defined(SECP256K1_BUILD) && defined(SECP256K1_VERIFY) # define SECP256K1_RESTRICT #else # if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) @@ -251,14 +251,14 @@ static SECP256K1_INLINE void secp256k1_memzero_explicit(void *ptr, size_t len) { * The state of the memory after this call is unspecified so callers must not * make any assumptions about its contents. * - * In VERIFY builds, it has the side effect of marking the memory as undefined. + * In SECP256K1_VERIFY builds, it has the side effect of marking the memory as undefined. * This helps to detect use-after-clear bugs where code incorrectly reads from * cleansed memory during testing. */ static SECP256K1_INLINE void secp256k1_memclear_explicit(void *ptr, size_t len) { /* The current implementation zeroes, but callers must not rely on this */ secp256k1_memzero_explicit(ptr, len); -#ifdef VERIFY +#ifdef SECP256K1_VERIFY SECP256K1_CHECKMEM_UNDEFINE(ptr, len); #endif } @@ -318,16 +318,16 @@ static SECP256K1_INLINE void secp256k1_int_cmov(int *r, const int *a, int flag) *r = (int)(r_masked | a_masked); } -#if defined(USE_FORCE_WIDEMUL_INT128_STRUCT) -/* If USE_FORCE_WIDEMUL_INT128_STRUCT is set, use int128_struct. */ +#if defined(SECP256K1_USE_FORCE_WIDEMUL_INT128_STRUCT) +/* If SECP256K1_USE_FORCE_WIDEMUL_INT128_STRUCT is set, use int128_struct. */ # define SECP256K1_WIDEMUL_INT128 1 # define SECP256K1_INT128_STRUCT 1 -#elif defined(USE_FORCE_WIDEMUL_INT128) -/* If USE_FORCE_WIDEMUL_INT128 is set, use int128. */ +#elif defined(SECP256K1_USE_FORCE_WIDEMUL_INT128) +/* If SECP256K1_USE_FORCE_WIDEMUL_INT128 is set, use int128. */ # define SECP256K1_WIDEMUL_INT128 1 # define SECP256K1_INT128_NATIVE 1 -#elif defined(USE_FORCE_WIDEMUL_INT64) -/* If USE_FORCE_WIDEMUL_INT64 is set, use int64. */ +#elif defined(SECP256K1_USE_FORCE_WIDEMUL_INT64) +/* If SECP256K1_USE_FORCE_WIDEMUL_INT64 is set, use int64. */ # define SECP256K1_WIDEMUL_INT64 1 #elif defined(UINT128_MAX) || defined(__SIZEOF_INT128__) /* If a native 128-bit integer type exists, use int128. */