-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab42fb3
commit daa5010
Showing
7 changed files
with
135 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 | ||
@@ -32,20 +32,20 @@ | ||
#include <wincrypt.h> | ||
|
||
static mp_err s_read_wincsp(void *p, size_t n) | ||
{ | ||
- static HCRYPTPROV hProv = 0; | ||
- if (hProv == 0) { | ||
- HCRYPTPROV h = 0; | ||
- if (!CryptAcquireContext(&h, NULL, MS_DEF_PROV, PROV_RSA_FULL, | ||
- (CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) && | ||
- !CryptAcquireContext(&h, NULL, MS_DEF_PROV, PROV_RSA_FULL, | ||
- CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET)) { | ||
+ static BCRYPT_ALG_HANDLE hAlg = 0; | ||
+ if (hAlg == 0) { | ||
+ BCRYPT_ALG_HANDLE h = 0; | ||
+ NTSTATUS status = BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_RSA_ALGORITHM, NULL, | ||
+ BCRYPT_HASH_REUSABLE_FLAG); | ||
+ if(!BCRYPT_SUCCESS(status)) { | ||
return MP_ERR; | ||
} | ||
- hProv = h; | ||
+ hAlg = h; | ||
} | ||
- return CryptGenRandom(hProv, (DWORD)n, (BYTE *)p) == TRUE ? MP_OKAY : MP_ERR; | ||
+ NTSTATUS status = BCryptGenRandom(hAlg, (PUCHAR)p, (ULONG)n, 0); | ||
+ return BCRYPT_SUCCESS(status) ? MP_OKAY : MP_ERR; | ||
} | ||
#endif /* WIN32 */ | ||
|
||
#if !defined(BN_S_READ_WINCSP_C) && defined(__linux__) && defined(__GLIBC_PREREQ) | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -117,8 +117,13 @@ | ||
) | ||
target_link_options(${PROJECT_NAME} BEFORE PRIVATE | ||
${LTM_LD_FLAGS} | ||
) | ||
+if(WIN32) | ||
+ target_link_options(${PROJECT_NAME} PRIVATE | ||
+ bcrypt.lib | ||
+ ) | ||
+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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
{ | ||
"name": "libtommath", | ||
"version": "1.3.0", | ||
"port-version": 1, | ||
"description": "LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C.", | ||
"homepage": "https://www.libtom.net/LibTomMath/" | ||
"homepage": "https://www.libtom.net/LibTomMath/", | ||
"dependencies": [ | ||
{ | ||
"name": "vcpkg-cmake", | ||
"host": true | ||
}, | ||
{ | ||
"name": "vcpkg-cmake-config", | ||
"host": true | ||
} | ||
] | ||
} |