aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/ports/libtommath
diff options
context:
space:
mode:
authorEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
committerEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
commit54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch)
treed915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/libtommath
move to own git serverHEADmaster
Diffstat (limited to 'vcpkg/ports/libtommath')
-rw-r--r--vcpkg/ports/libtommath/bcrypt.patch67
-rw-r--r--vcpkg/ports/libtommath/has-set-double.patch14
-rw-r--r--vcpkg/ports/libtommath/import-lib.patch12
-rw-r--r--vcpkg/ports/libtommath/msvc-dce.patch21
-rw-r--r--vcpkg/ports/libtommath/portfile.cmake25
-rw-r--r--vcpkg/ports/libtommath/usage9
-rw-r--r--vcpkg/ports/libtommath/vcpkg.json17
7 files changed, 165 insertions, 0 deletions
diff --git a/vcpkg/ports/libtommath/bcrypt.patch b/vcpkg/ports/libtommath/bcrypt.patch
new file mode 100644
index 0000000..dc59d79
--- /dev/null
+++ b/vcpkg/ports/libtommath/bcrypt.patch
@@ -0,0 +1,67 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -22,8 +22,10 @@
+ #-----------------------------------------------------------------------------
+ include(GNUInstallDirs)
+ include(CheckIPOSupported)
+ include(CMakePackageConfigHelpers)
++include(CMakePushCheckState)
++include(CheckSymbolExists)
+ # default is "No tests"
+ option(BUILD_TESTING "" OFF)
+ include(CTest)
+ include(sources.cmake)
+@@ -118,8 +120,19 @@
+ target_link_options(${PROJECT_NAME} BEFORE PRIVATE
+ ${LTM_LD_FLAGS}
+ )
+
++if(MSVC)
++ cmake_push_check_state()
++ set(CMAKE_REQUIRED_LIBRARIES bcrypt)
++ check_symbol_exists(BCryptGenRandom "Windows.h;bcrypt.h" BCRYPT_AVAILABLE)
++ cmake_pop_check_state()
++ if(BCRYPT_AVAILABLE)
++ target_compile_definitions(${PROJECT_NAME} PRIVATE LTM_WIN32_BCRYPT)
++ target_link_libraries(${PROJECT_NAME} PRIVATE bcrypt)
++ endif()
++endif()
++
+ set(PUBLIC_HEADERS tommath.h)
+ set(C89 False CACHE BOOL "(Usually maintained automatically) Enable when the library is in c89 mode to package the correct header files on install")
+ if(C89)
+ list(APPEND PUBLIC_HEADERS tommath_c89.h)
+diff --git a/bn_s_mp_rand_platform.c b/bn_s_mp_rand_platform.c
+--- a/bn_s_mp_rand_platform.c
++++ b/bn_s_mp_rand_platform.c
+@@ -28,8 +28,19 @@
+ #endif
+
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
++
++#ifdef LTM_WIN32_BCRYPT
++#include <bcrypt.h>
++#pragma comment(lib, "bcrypt")
++
++static mp_err s_read_wincsp(void *p, size_t n)
++{
++ return BCRYPT_SUCCESS(BCryptGenRandom(NULL, (PUCHAR)p, (ULONG)n,
++ BCRYPT_USE_SYSTEM_PREFERRED_RNG)) ? MP_OKAY : MP_ERR;
++}
++#else
+ #include <wincrypt.h>
+
+ static mp_err s_read_wincsp(void *p, size_t n)
+ {
+@@ -45,8 +56,9 @@
+ hProv = h;
+ }
+ return CryptGenRandom(hProv, (DWORD)n, (BYTE *)p) == TRUE ? MP_OKAY : MP_ERR;
+ }
++#endif
+ #endif /* WIN32 */
+
+ #if !defined(BN_S_READ_WINCSP_C) && defined(__linux__) && defined(__GLIBC_PREREQ)
+ #if __GLIBC_PREREQ(2, 25)
diff --git a/vcpkg/ports/libtommath/has-set-double.patch b/vcpkg/ports/libtommath/has-set-double.patch
new file mode 100644
index 0000000..6e275d7
--- /dev/null
+++ b/vcpkg/ports/libtommath/has-set-double.patch
@@ -0,0 +1,14 @@
+diff --git a/bn_mp_set_double.c b/bn_mp_set_double.c
+--- a/bn_mp_set_double.c
++++ b/bn_mp_set_double.c
+@@ -2,9 +2,9 @@
+ #ifdef BN_MP_SET_DOUBLE_C
+ /* LibTomMath, multiple-precision integer library -- Tom St Denis */
+ /* SPDX-License-Identifier: Unlicense */
+
+-#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
++#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) || defined(_MSC_VER)
+ mp_err mp_set_double(mp_int *a, double b)
+ {
+ uint64_t frac;
+ int exp;
diff --git a/vcpkg/ports/libtommath/import-lib.patch b/vcpkg/ports/libtommath/import-lib.patch
new file mode 100644
index 0000000..ebce1c3
--- /dev/null
+++ b/vcpkg/ports/libtommath/import-lib.patch
@@ -0,0 +1,12 @@
+diff --git a/sources.cmake b/sources.cmake
+--- a/sources.cmake
++++ b/sources.cmake
+@@ -171,4 +171,8 @@
+ tommath_cutoffs.h
+ tommath_private.h
+ tommath_superclass.h
+ )
++
++if(WIN32)
++ list(APPEND SOURCES tommath.def)
++endif()
diff --git a/vcpkg/ports/libtommath/msvc-dce.patch b/vcpkg/ports/libtommath/msvc-dce.patch
new file mode 100644
index 0000000..342c012
--- /dev/null
+++ b/vcpkg/ports/libtommath/msvc-dce.patch
@@ -0,0 +1,21 @@
+diff --git a/bn_s_mp_rand_platform.c b/bn_s_mp_rand_platform.c
+--- a/bn_s_mp_rand_platform.c
++++ b/bn_s_mp_rand_platform.c
+@@ -136,13 +136,17 @@
+
+ mp_err s_mp_rand_platform(void *p, size_t n)
+ {
+ mp_err err = MP_ERR;
++ #ifndef _MSC_VER
+ if ((err != MP_OKAY) && MP_HAS(S_READ_ARC4RANDOM)) err = s_read_arc4random(p, n);
++ #endif
+ if ((err != MP_OKAY) && MP_HAS(S_READ_WINCSP)) err = s_read_wincsp(p, n);
++ #ifndef _MSC_VER
+ if ((err != MP_OKAY) && MP_HAS(S_READ_GETRANDOM)) err = s_read_getrandom(p, n);
+ if ((err != MP_OKAY) && MP_HAS(S_READ_URANDOM)) err = s_read_urandom(p, n);
+ if ((err != MP_OKAY) && MP_HAS(S_READ_LTM_RNG)) err = s_read_ltm_rng(p, n);
++ #endif
+ return err;
+ }
+
+ #endif
diff --git a/vcpkg/ports/libtommath/portfile.cmake b/vcpkg/ports/libtommath/portfile.cmake
new file mode 100644
index 0000000..6237e8a
--- /dev/null
+++ b/vcpkg/ports/libtommath/portfile.cmake
@@ -0,0 +1,25 @@
+vcpkg_from_github(
+ OUT_SOURCE_PATH SOURCE_PATH
+ REPO libtom/libtommath
+ REF "v${VERSION}"
+ SHA512 3dbd7053a670afa563a069a9785f1aa4cab14a210bcd05d8fc7db25bd3dcce36b10a3f4f54ca92d75a694f891226f01bdf6ac15bacafeb93a8be6b04c579beb3
+ HEAD_REF develop
+ PATCHES
+ bcrypt.patch
+ import-lib.patch
+ has-set-double.patch # Remove in next release.
+ msvc-dce.patch # This is a won't fix, see https://github.com/libtom/libtommath/blob/develop/s_mp_rand_platform.c#L120-L138
+)
+
+vcpkg_cmake_configure(
+ SOURCE_PATH "${SOURCE_PATH}"
+)
+vcpkg_cmake_install()
+vcpkg_copy_pdbs()
+vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/${PORT}")
+vcpkg_fixup_pkgconfig()
+vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
+
+file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
diff --git a/vcpkg/ports/libtommath/usage b/vcpkg/ports/libtommath/usage
new file mode 100644
index 0000000..e2028c1
--- /dev/null
+++ b/vcpkg/ports/libtommath/usage
@@ -0,0 +1,9 @@
+libtommath provides CMake targets:
+
+ find_package(libtommath CONFIG REQUIRED)
+ target_link_libraries(main PRIVATE libtommath)
+
+libtommath provides pkg-config modules:
+
+ # public domain library for manipulating large integer numbers
+ libtommath
diff --git a/vcpkg/ports/libtommath/vcpkg.json b/vcpkg/ports/libtommath/vcpkg.json
new file mode 100644
index 0000000..f0ab532
--- /dev/null
+++ b/vcpkg/ports/libtommath/vcpkg.json
@@ -0,0 +1,17 @@
+{
+ "name": "libtommath",
+ "version": "1.3.0",
+ "port-version": 2,
+ "description": "LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C.",
+ "homepage": "https://www.libtom.net/LibTomMath/",
+ "dependencies": [
+ {
+ "name": "vcpkg-cmake",
+ "host": true
+ },
+ {
+ "name": "vcpkg-cmake-config",
+ "host": true
+ }
+ ]
+}