Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[secp256k1] Update secp256k1 from 2017 to 2022 #25398

Merged
merged 18 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions ports/secp256k1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,84 @@ cmake_minimum_required(VERSION 3.8)
project(secp256k1 C)

option(INSTALL_HEADERS "Install header files" ON)
option(BUILD_TOOLS "Build tools" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)

add_definitions(
-DENABLE_MODULE_ECDH
-DENABLE_MODULE_RECOVERY
-DHAVE_CONFIG_H
-DENABLE_MODULE_EXTRAKEYS
-DENABLE_MODULE_SCHNORRSIG
)

file(GLOB SOURCES src/secp256k1.c)
add_library(secp256k1 ${SOURCES})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(secp256k1 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/src> $<INSTALL_INTERFACE:include>)

target_include_directories(secp256k1 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>)
file(GLOB SOURCES_PRECOMP src/precomputed_ecmult.c src/precomputed_ecmult_gen.c)
add_library(secp256k1_precomputed ${SOURCES_PRECOMP})

target_include_directories(secp256k1_precomputed PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)

if (BUILD_TOOLS)
add_executable(bench src/bench.c)
target_link_libraries(bench PRIVATE secp256k1 secp256k1_precomputed)

add_executable(bench_internal src/bench_internal.c)
target_link_libraries(bench_internal PRIVATE secp256k1_precomputed)

add_executable(bench_ecmult src/bench_ecmult.c)
target_link_libraries(bench_ecmult PRIVATE secp256k1_precomputed)

install(TARGETS bench bench_internal bench_ecmult RUNTIME DESTINATION bin)
endif()

if (BUILD_EXAMPLES)
add_executable(ecdsa_example examples/ecdsa.c)
target_include_directories(ecdsa_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(ecdsa_example PRIVATE secp256k1 secp256k1_precomputed)
if (WIN32)
target_link_libraries(ecdsa_example PRIVATE Bcrypt)
endif()

add_executable(ecdh_example examples/ecdh.c)
target_include_directories(ecdh_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(ecdh_example PRIVATE secp256k1 secp256k1_precomputed)
if (WIN32)
target_link_libraries(ecdh_example PRIVATE Bcrypt)
endif()

add_executable(schnorr_example examples/schnorr.c)
target_include_directories(schnorr_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(schnorr_example PRIVATE secp256k1 secp256k1_precomputed)
if (WIN32)
target_link_libraries(schnorr_example PRIVATE Bcrypt)
endif()

install(TARGETS ecdsa_example ecdh_example schnorr_example RUNTIME DESTINATION bin)
endif()

if(INSTALL_HEADERS)
file(GLOB HEADERS include/*.h)
install(FILES ${HEADERS} DESTINATION include)
endif()

install(TARGETS secp256k1 EXPORT unofficial-secp256k1-targets
install(TARGETS secp256k1 EXPORT unofficial-secp256k1-config
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

install(TARGETS secp256k1_precomputed EXPORT unofficial-secp256k1-config
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

install(
EXPORT unofficial-secp256k1-targets
FILE unofficial-secp256k1-targets.cmake
EXPORT unofficial-secp256k1-config
FILE unofficial-secp256k1-config.cmake
NAMESPACE unofficial::
DESTINATION share/unofficial-secp256k1
)
)
29 changes: 0 additions & 29 deletions ports/secp256k1/libsecp256k1-config.h

This file was deleted.

47 changes: 34 additions & 13 deletions ports/secp256k1/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,45 @@ vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO "bitcoin-core/secp256k1"
REF "0b7024185045a49a1a6a4c5615bf31c94f63d9c4"
SHA512 54e0c446ae63105800dfaf23dc934734f196c91f275db0455e58a36926c29ecc51a13d9b1eb2e45bc86199120c3c472ec7b39086787a49ce388a4df462a870bc
REPO bitcoin-core/secp256k1
REF 3efeb9da21368c02cad58435b2ccdf6eb4b359c3
SHA512 6d792943f9277a1b4c36dad62389cb38e0b93efb570b6af6c41afdb936d10ca30d4c2e4e743fc0f113d1f9785891d1e9d1fe224d7b8abd4197a9f5febf0febd6
)

file(COPY ${CURRENT_PORT_DIR}/libsecp256k1-config.h DESTINATION ${SOURCE_PATH})
file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS_DEBUG
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
tools BUILD_TOOLS
examples BUILD_EXAMPLES
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
OPTIONS_DEBUG
-DINSTALL_HEADERS=OFF
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-${PORT} TARGET_PATH share/unofficial-${PORT})
vcpkg_cmake_install()
vcpkg_copy_pdbs()

vcpkg_cmake_config_fixup(CONFIG_PATH "share/unofficial-${PORT}" PACKAGE_NAME unofficial-${PORT})

if (BUILD_TOOLS OR BUILD_EXAMPLES)
set(SECP256K1_TOOLS "")
if (BUILD_TOOLS)
list(APPEND SECP256K1_TOOLS bench bench_internal bench_ecmult)
endif()

if (BUILD_EXAMPLES)
list(APPEND SECP256K1_TOOLS ecdsa_example ecdh_example schnorr_example)
endif()

vcpkg_copy_tools(TOOL_NAMES ${SECP256K1_TOOLS} AUTO_CLEAN)
endif()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
configure_file(${CMAKE_CURRENT_LIST_DIR}/secp256k1-config.cmake ${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-secp256k1-config.cmake @ONLY)
file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
1 change: 0 additions & 1 deletion ports/secp256k1/secp256k1-config.cmake

This file was deleted.

24 changes: 21 additions & 3 deletions ports/secp256k1/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
{
"name": "secp256k1",
"version-string": "2017-19-10",
"port-version": 4,
"version-date": "2022-07-11",
"description": "Optimized C library for EC operations on curve",
"homepage": "https://github.com/bitcoin-core/secp256k1"
"homepage": "https://github.com/bitcoin-core/secp256k1",
"license": "MIT",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"examples": {
"description": "Build examples"
},
"tools": {
"description": "Build tools"
}
}
}
4 changes: 2 additions & 2 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6477,8 +6477,8 @@
"port-version": 3
},
"secp256k1": {
"baseline": "2017-19-10",
"port-version": 4
"baseline": "2022-07-11",
"port-version": 0
},
"selene": {
"baseline": "0.3.1",
Expand Down
5 changes: 5 additions & 0 deletions versions/s-/secp256k1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "31de2b5d2286595ff7771a30dee3c68d04e78082",
"version-date": "2022-07-11",
"port-version": 0
},
{
"git-tree": "a0ba39af9284d60d41166c4f546975e9f2b2d9df",
"version-string": "2017-19-10",
Expand Down