Skip to content

Commit

Permalink
v0.3 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Sep 30, 2017
1 parent 5553ebf commit 3200859
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 30 deletions.
77 changes: 61 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,23 @@ if (NO_CONAN_AT_ALL)
endif()


# Inherit --enable-shared
#------------------------------------------------------------------------------
option(ENABLE_SHARED "" OFF)

# Implement POSITION_INDEPENDENT_CODE
#------------------------------------------------------------------------------
option(ENABLE_POSITION_INDEPENDENT_CODE "Enable POSITION_INDEPENDENT_CODE property" ON)


# TODO(Bitprim): This options are not reflected on code... Se old Makefiles
option(ENABLE_BENCHMARK "Compile benchmark." OFF)
option(ENABLE_TESTS "Compile tests." ON)
option(ENABLE_OPENSSL_TESTS "Enable OpenSSL tests, if OpenSSL is available" OFF)

option(ENABLE_EXPERIMENTAL "Alloc experimental configure options" OFF)
option(ENABLE_ENDOMORPHISM "Enable endomorphism" OFF)
option(ENABLE_ECMULT_STATIC_PRECOMPUTATION "Enable precomputed ecmult table for signing" ON)
option(ENABLE_ECMULT_STATIC_PRECOMPUTATION "Enable precomputed ecmult table for signing" OFF)
option(ENABLE_MODULE_ECDH "Enable ECDH shared secret computation (experimental)." OFF)
option(ENABLE_MODULE_SCHNORR "Enable Schnorr signature module (experimental)." OFF)
option(ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." ON)
Expand All @@ -61,7 +72,7 @@ set(WITH_FIELD "auto" CACHE STRING "Specify Field Implementation (64bit|32bit|au
set(WITH_SCALAR "auto" CACHE STRING "Specify scalar implementation (64bit|32bit|auto).")
set(WITH_BIGNUM "auto" CACHE STRING "Specify Bignum Implementation (gmp|mpir|no|auto).")

message(${WITH_BIGNUM})
# message(${WITH_BIGNUM})

if (NOT NO_CONAN_AT_ALL)
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
Expand All @@ -78,6 +89,17 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(Secp256k1Tools)


#------------------------------------------------------------------------------
if (ENABLE_ENDOMORPHISM)
add_definitions(-DUSE_ENDOMORPHISM)
endif()

if (ENABLE_ECMULT_STATIC_PRECOMPUTATION)
add_definitions(-DUSE_ECMULT_STATIC_PRECOMPUTATION)
endif()



# Implement --with-asm
#------------------------------------------------------------------------------
if (WITH_ASM STREQUAL "auto")
Expand Down Expand Up @@ -160,14 +182,25 @@ if (NO_CONAN_AT_ALL)
endif()


if (ENABLE_SHARED)
set(MODE SHARED)
else()
set(MODE STATIC)
endif()


# Build
#==============================================================================
add_library(secp256k1 STATIC
add_library(secp256k1 ${MODE}
include/secp256k1.h
src/secp256k1.c)

set_property(TARGET secp256k1 PROPERTY POSITION_INDEPENDENT_CODE ON)

if (ENABLE_POSITION_INDEPENDENT_CODE)
set_property(TARGET secp256k1 PROPERTY POSITION_INDEPENDENT_CODE ON)
endif(ENABLE_POSITION_INDEPENDENT_CODE)


target_include_directories(secp256k1 PRIVATE
${CMAKE_CURRENT_SOURCE_DIR})

Expand Down Expand Up @@ -199,20 +232,20 @@ elseif (WITH_SCALAR STREQUAL "32bit")
target_compile_definitions(secp256k1 PUBLIC -DUSE_SCALAR_8X32=1)
endif()

message("fer WITH_BIGNUM: ")
message(WITH_ASM)
message(WITH_FIELD)
message(WITH_SCALAR)
message(${WITH_BIGNUM})
# message("fer WITH_BIGNUM: ")
# message(WITH_ASM)
# message(WITH_FIELD)
# message(WITH_SCALAR)
# message(${WITH_BIGNUM})

if (${WITH_BIGNUM} STREQUAL "auto")
message("fer WITH_BIGNUM auto")
else()
message("fer WITH_BIGNUM auto - FALSE")
endif()
# if (${WITH_BIGNUM} STREQUAL "auto")
# message("fer WITH_BIGNUM auto")
# else()
# message("fer WITH_BIGNUM auto - FALSE")
# endif()

message("WITH_BIGNUM--FER-FER")
message(${WITH_BIGNUM})
# message("WITH_BIGNUM--FER-FER")
# message(${WITH_BIGNUM})

if (${WITH_BIGNUM} STREQUAL "gmp")
target_compile_definitions(secp256k1 PUBLIC -DHAVE_LIBGMP=1)
Expand Down Expand Up @@ -251,9 +284,11 @@ endif()
if (ENABLE_MODULE_ECDH)
target_compile_definitions(secp256k1 PUBLIC -DENABLE_MODULE_ECDH=1)
endif()

if (ENABLE_MODULE_SCHNORR)
target_compile_definitions(secp256k1 PUBLIC -DENABLE_MODULE_SCHNORR=1)
endif()

if (ENABLE_MODULE_RECOVERY)
target_compile_definitions(secp256k1 PUBLIC -DENABLE_MODULE_RECOVERY=1)
endif()
Expand All @@ -267,6 +302,12 @@ if (ENABLE_BENCHMARK)
target_link_libraries(bench_verify secp256k1)
set_target_properties(bench_verify PROPERTIES FOLDER "secp256k1")

if (ENABLE_OPENSSL_TESTS)
target_compile_definitions(bench_verify PRIVATE -DENABLE_OPENSSL_TESTS)
endif()



add_executable(bench_sign src/bench_sign.c)
target_link_libraries(bench_sign secp256k1)
set_target_properties(bench_sign PROPERTIES FOLDER "secp256k1")
Expand Down Expand Up @@ -300,6 +341,10 @@ if (ENABLE_TESTS)
add_executable(tests
src/tests.c)

if (ENABLE_OPENSSL_TESTS)
target_compile_definitions(tests PRIVATE -DENABLE_OPENSSL_TESTS)
endif()

target_compile_definitions(tests PRIVATE -DVERIFY)
target_include_directories(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
39 changes: 25 additions & 14 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class Secp256k1Conan(ConanFile):

options = {"shared": [True, False],
"fPIC": [True, False],
"enable_benchmark": [True, False],
"enable_tests": [True, False],
"enable_openssl_tests": [True, False],
"enable_experimental": [True, False],
"enable_endomorphism": [True, False],
"enable_ecmult_static_precomputation": [True, False],
"enable_module_ecdh": [True, False],
"enable_module_schnorr": [True, False],
"enable_module_recovery": [True, False],

# "enable_benchmark": [True, False],
# "enable_tests": [True, False],
# "enable_openssl_tests": [True, False],
# "with_asm": ['x86_64', 'arm', 'no', 'auto'],
# "with_field": ['64bit', '32bit', 'auto'],
# "with_scalar": ['64bit', '32bit', 'auto'],
Expand All @@ -58,16 +58,16 @@ class Secp256k1Conan(ConanFile):

default_options = "shared=False", \
"fPIC=True", \
"enable_benchmark=False", \
"enable_tests=False", \
"enable_openssl_tests=False", \
"enable_experimental=False", \
"enable_endomorphism=False", \
"enable_ecmult_static_precomputation=True", \
"enable_ecmult_static_precomputation=False", \
"enable_module_ecdh=False", \
"enable_module_schnorr=False", \
"enable_module_recovery=True"

# "enable_benchmark=False", \
# "enable_tests=False", \
# "enable_openssl_tests=False", \
# "with_asm='auto'", \
# "with_field='auto'", \
# "with_scalar='auto'"
Expand All @@ -77,6 +77,11 @@ class Secp256k1Conan(ConanFile):
build_policy = "missing"
exports_sources = "src/*", "include/*", "CMakeLists.txt", "cmake/*", "secp256k1Config.cmake.in", "contrib/*", "test/*"


enable_benchmark = False
enable_tests = False
enable_openssl_tests = False

def requirements(self):
# if self.settings.os == "Linux" or self.settings.os == "Macos":
# self.requires("gmp/6.1.2@bitprim/stable")
Expand All @@ -92,14 +97,20 @@ def requirements(self):
def build(self):
cmake = CMake(self)

cmake.definitions["USE_CONAN"] = "ON"
cmake.definitions["NO_CONAN_AT_ALL"] = "OFF"
cmake.definitions["CMAKE_VERBOSE_MAKEFILE"] = "ON"
cmake.definitions["USE_CONAN"] = option_on_off(True)
cmake.definitions["NO_CONAN_AT_ALL"] = option_on_off(False)
cmake.definitions["CMAKE_VERBOSE_MAKEFILE"] = option_on_off(False)

cmake.definitions["ENABLE_SHARED"] = option_on_off(self.options.shared)
cmake.definitions["ENABLE_POSITION_INDEPENDENT_CODE"] = option_on_off(self.options.fPIC)
cmake.definitions["ENABLE_BENCHMARK"] = option_on_off(self.options.enable_benchmark)
cmake.definitions["ENABLE_TESTS"] = option_on_off(self.options.enable_tests)
cmake.definitions["ENABLE_OPENSSL_TESTS"] = option_on_off(self.options.enable_openssl_tests)

# cmake.definitions["ENABLE_BENCHMARK"] = option_on_off(self.options.enable_benchmark)
# cmake.definitions["ENABLE_TESTS"] = option_on_off(self.options.enable_tests)
# cmake.definitions["ENABLE_OPENSSL_TESTS"] = option_on_off(self.options.enable_openssl_tests)
cmake.definitions["ENABLE_BENCHMARK"] = option_on_off(self.enable_benchmark)
cmake.definitions["ENABLE_TESTS"] = option_on_off(self.enable_tests)
cmake.definitions["ENABLE_OPENSSL_TESTS"] = option_on_off(self.enable_openssl_tests)

cmake.definitions["ENABLE_EXPERIMENTAL"] = option_on_off(self.options.enable_experimental)
cmake.definitions["ENABLE_ENDOMORPHISM"] = option_on_off(self.options.enable_endomorphism)
cmake.definitions["ENABLE_ECMULT_STATIC_PRECOMPUTATION"] = option_on_off(self.options.enable_ecmult_static_precomputation)
Expand All @@ -112,7 +123,7 @@ def build(self):
cmake.definitions["WITH_BIGNUM"] = "mpir"

if self.settings.compiler == "Visual Studio" and (self.settings.compiler.version != 12):
cmake.definitions["ENABLE_TESTS"] = "OFF" #Workaround. test broke MSVC
cmake.definitions["ENABLE_TESTS"] = option_on_off(False) #Workaround. test broke MSVC
else:
cmake.definitions["WITH_BIGNUM"] = "gmp"

Expand Down

0 comments on commit 3200859

Please sign in to comment.