auto-format
by executing `make astyle`
This commit is contained in:
parent
05dea227be
commit
8b9f98baa1
30
bn_mp_rand.c
30
bn_mp_rand.c
@ -22,7 +22,7 @@
|
|||||||
#define MP_GEN_RANDOM_MAX 0xffffffffu
|
#define MP_GEN_RANDOM_MAX 0xffffffffu
|
||||||
#define MP_GEN_RANDOM_SHIFT 32
|
#define MP_GEN_RANDOM_SHIFT 32
|
||||||
|
|
||||||
static int s_read_arc4random(mp_digit* p)
|
static int s_read_arc4random(mp_digit *p)
|
||||||
{
|
{
|
||||||
mp_digit d = 0, msk = 0;
|
mp_digit d = 0, msk = 0;
|
||||||
do {
|
do {
|
||||||
@ -40,11 +40,11 @@ static int s_read_arc4random(mp_digit* p)
|
|||||||
#define MP_WIN_CSP
|
#define MP_WIN_CSP
|
||||||
|
|
||||||
#ifndef _WIN32_WINNT
|
#ifndef _WIN32_WINNT
|
||||||
#define _WIN32_WINNT 0x0400
|
#define _WIN32_WINNT 0x0400
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32_WCE
|
#ifdef _WIN32_WCE
|
||||||
#define UNDER_CE
|
#define UNDER_CE
|
||||||
#define ARM
|
#define ARM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
@ -59,20 +59,20 @@ static void s_cleanup_win_csp(void)
|
|||||||
hProv = 0;
|
hProv = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s_read_win_csp(mp_digit* p)
|
static int s_read_win_csp(mp_digit *p)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if (hProv == 0) {
|
if (hProv == 0) {
|
||||||
if (!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
|
if (!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
|
||||||
(CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) &&
|
(CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) &&
|
||||||
!CryptAcquireContext (&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
|
!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL,
|
||||||
CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET)) {
|
CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET | CRYPT_NEWKEYSET)) {
|
||||||
hProv = 0;
|
hProv = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
atexit(s_cleanup_win_csp);
|
atexit(s_cleanup_win_csp);
|
||||||
}
|
}
|
||||||
if (CryptGenRandom(hProv, sizeof(*p), (void*)p) == TRUE) {
|
if (CryptGenRandom(hProv, sizeof(*p), (void *)p) == TRUE) {
|
||||||
ret = MP_OKAY;
|
ret = MP_OKAY;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -85,12 +85,12 @@ static int s_read_win_csp(mp_digit* p)
|
|||||||
#include <sys/random.h>
|
#include <sys/random.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static int s_read_getrandom(mp_digit* p)
|
static int s_read_getrandom(mp_digit *p)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
do {
|
do {
|
||||||
ret = getrandom(p, sizeof(*p), 0);
|
ret = getrandom(p, sizeof(*p), 0);
|
||||||
} while((ret == -1) && (errno == EINTR));
|
} while ((ret == -1) && (errno == EINTR));
|
||||||
if (ret == sizeof(*p)) return MP_OKAY;
|
if (ret == sizeof(*p)) return MP_OKAY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -108,17 +108,17 @@ static int s_read_getrandom(mp_digit* p)
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static int s_read_dev_urandom(mp_digit* p)
|
static int s_read_dev_urandom(mp_digit *p)
|
||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
int fd;
|
int fd;
|
||||||
do {
|
do {
|
||||||
fd = open(MP_DEV_URANDOM, O_RDONLY);
|
fd = open(MP_DEV_URANDOM, O_RDONLY);
|
||||||
} while((fd == -1) && (errno == EINTR));
|
} while ((fd == -1) && (errno == EINTR));
|
||||||
if (fd == -1) return -1;
|
if (fd == -1) return -1;
|
||||||
do {
|
do {
|
||||||
r = read(fd, p, sizeof(*p));
|
r = read(fd, p, sizeof(*p));
|
||||||
} while((r == -1) && (errno == EINTR));
|
} while ((r == -1) && (errno == EINTR));
|
||||||
close(fd);
|
close(fd);
|
||||||
if (r != sizeof(*p)) return -1;
|
if (r != sizeof(*p)) return -1;
|
||||||
return MP_OKAY;
|
return MP_OKAY;
|
||||||
@ -129,17 +129,17 @@ static int s_read_dev_urandom(mp_digit* p)
|
|||||||
unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
|
unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
|
||||||
void (*ltm_rng_callback)(void);
|
void (*ltm_rng_callback)(void);
|
||||||
|
|
||||||
static int s_read_ltm_rng(mp_digit* p)
|
static int s_read_ltm_rng(mp_digit *p)
|
||||||
{
|
{
|
||||||
unsigned long ret;
|
unsigned long ret;
|
||||||
if (ltm_rng == NULL) return -1;
|
if (ltm_rng == NULL) return -1;
|
||||||
ret = ltm_rng((void*)p, sizeof(*p), ltm_rng_callback);
|
ret = ltm_rng((void *)p, sizeof(*p), ltm_rng_callback);
|
||||||
if (ret != sizeof(*p)) return -1;
|
if (ret != sizeof(*p)) return -1;
|
||||||
return MP_OKAY;
|
return MP_OKAY;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int s_rand_digit(mp_digit* p)
|
static int s_rand_digit(mp_digit *p)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
@ -16,18 +16,18 @@
|
|||||||
/* two complement right shift */
|
/* two complement right shift */
|
||||||
int mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
|
int mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
if (mp_isneg(a) == MP_NO) {
|
if (mp_isneg(a) == MP_NO) {
|
||||||
return mp_div_2d(a, b, c, NULL);
|
return mp_div_2d(a, b, c, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = mp_add_d(a, 1uL, c);
|
res = mp_add_d(a, 1uL, c);
|
||||||
if (res != MP_OKAY) {
|
if (res != MP_OKAY) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = mp_div_2d(c, b, c, NULL);
|
res = mp_div_2d(c, b, c, NULL);
|
||||||
return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res;
|
return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ extern "C" {
|
|||||||
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
|
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
|
||||||
# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
|
# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
|
||||||
# if defined(__GNUC__)
|
# if defined(__GNUC__)
|
||||||
/* we support 128bit integers only via: __attribute__((mode(TI))) */
|
/* we support 128bit integers only via: __attribute__((mode(TI))) */
|
||||||
# define MP_64BIT
|
# define MP_64BIT
|
||||||
# else
|
# else
|
||||||
/* otherwise we fall back to MP_32BIT even on 64bit platforms */
|
/* otherwise we fall back to MP_32BIT even on 64bit platforms */
|
||||||
# define MP_32BIT
|
# define MP_32BIT
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user