.
This commit is contained in:
parent
455cd5551b
commit
54a1bbd016
14 changed files with 94 additions and 268 deletions
|
@ -135,72 +135,6 @@ static uint64_t curve_b[NUM_ECC_DIGITS] = CONCAT(Curve_B_, ECC_CURVE);
|
|||
static EccPoint curve_G = CONCAT(Curve_G_, ECC_CURVE);
|
||||
static uint64_t curve_n[NUM_ECC_DIGITS] = CONCAT(Curve_N_, ECC_CURVE);
|
||||
|
||||
#if 0
|
||||
#if (defined(_WIN32) || defined(_WIN64))
|
||||
/* Windows */
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
static int getRandomNumber(uint64_t *p_vli)
|
||||
{
|
||||
HCRYPTPROV l_prov;
|
||||
if(!CryptAcquireContext(&l_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CryptGenRandom(l_prov, ECC_BYTES, (BYTE *)p_vli);
|
||||
CryptReleaseContext(l_prov, 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
||||
/* Assume that we are using a POSIX-like system with /dev/urandom or /dev/random. */
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
static int getRandomNumber(uint64_t *p_vli)
|
||||
{
|
||||
int l_fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
if(l_fd == -1)
|
||||
{
|
||||
l_fd = open("/dev/random", O_RDONLY | O_CLOEXEC);
|
||||
if(l_fd == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char *l_ptr = (char *)p_vli;
|
||||
size_t l_left = ECC_BYTES;
|
||||
while(l_left > 0)
|
||||
{
|
||||
int l_read = read(l_fd, l_ptr, l_left);
|
||||
if(l_read <= 0)
|
||||
{ // read failed
|
||||
close(l_fd);
|
||||
return 0;
|
||||
}
|
||||
l_left -= l_read;
|
||||
l_ptr += l_read;
|
||||
}
|
||||
|
||||
close(l_fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
#endif
|
||||
|
||||
// Use ZeroTier's secure PRNG
|
||||
static inline int getRandomNumber(uint64_t *p_vli)
|
||||
{
|
||||
|
@ -515,7 +449,6 @@ static inline void vli_square(uint64_t *p_result, uint64_t *p_left)
|
|||
|
||||
#endif /* SUPPORTS_INT128 */
|
||||
|
||||
|
||||
/* Computes p_result = (p_left + p_right) % p_mod.
|
||||
Assumes that p_left < p_mod and p_right < p_mod, p_result != p_mod. */
|
||||
static inline void vli_modAdd(uint64_t *p_result, uint64_t *p_left, uint64_t *p_right, uint64_t *p_mod)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue