format with astyle (step 5)

This commit is contained in:
Francois Perrad 2017-08-30 19:15:27 +02:00
parent a20d9b102c
commit f89cda034b
18 changed files with 838 additions and 838 deletions

View File

@ -29,7 +29,7 @@ int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
/* can we use the fast multiplier? */ /* can we use the fast multiplier? */
if (((digs) < MP_WARRAY) && if (((digs) < MP_WARRAY) &&
(MIN (a->used, b->used) < (MIN(a->used, b->used) <
(1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) { (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
return fast_s_mp_mul_digs(a, b, c, digs); return fast_s_mp_mul_digs(a, b, c, digs);
} }
@ -66,10 +66,10 @@ int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
(mp_word)u; (mp_word)u;
/* the new column is the lower part of the result */ /* the new column is the lower part of the result */
*tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK)); *tmpt++ = (mp_digit)(r & ((mp_word) MP_MASK));
/* get the carry word from the result */ /* get the carry word from the result */
u = (mp_digit) (r >> ((mp_word) DIGIT_BIT)); u = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
} }
/* set carry if it is placed below digs */ /* set carry if it is placed below digs */
if ((ix + iy) < digs) { if ((ix + iy) < digs) {

View File

@ -38,7 +38,7 @@ int s_mp_sqr(mp_int *a, mp_int *b)
((mp_word)a->dp[ix] * (mp_word)a->dp[ix]); ((mp_word)a->dp[ix] * (mp_word)a->dp[ix]);
/* store lower part in result */ /* store lower part in result */
t.dp[ix+ix] = (mp_digit) (r & ((mp_word)MP_MASK)); t.dp[ix+ix] = (mp_digit)(r & ((mp_word)MP_MASK));
/* get the carry */ /* get the carry */
u = (mp_digit)(r >> ((mp_word)DIGIT_BIT)); u = (mp_digit)(r >> ((mp_word)DIGIT_BIT));

View File

@ -47,45 +47,45 @@ extern "C" {
* [any size beyond that is ok provided it doesn't overflow the data type] * [any size beyond that is ok provided it doesn't overflow the data type]
*/ */
#ifdef MP_8BIT #ifdef MP_8BIT
typedef uint8_t mp_digit; typedef uint8_t mp_digit;
typedef uint16_t mp_word; typedef uint16_t mp_word;
# define MP_SIZEOF_MP_DIGIT 1 # define MP_SIZEOF_MP_DIGIT 1
# ifdef DIGIT_BIT # ifdef DIGIT_BIT
# error You must not define DIGIT_BIT when using MP_8BIT # error You must not define DIGIT_BIT when using MP_8BIT
# endif # endif
#elif defined(MP_16BIT) #elif defined(MP_16BIT)
typedef uint16_t mp_digit; typedef uint16_t mp_digit;
typedef uint32_t mp_word; typedef uint32_t mp_word;
# define MP_SIZEOF_MP_DIGIT 2 # define MP_SIZEOF_MP_DIGIT 2
# ifdef DIGIT_BIT # ifdef DIGIT_BIT
# error You must not define DIGIT_BIT when using MP_16BIT # error You must not define DIGIT_BIT when using MP_16BIT
# endif # endif
#elif defined(MP_64BIT) #elif defined(MP_64BIT)
/* for GCC only on supported platforms */ /* for GCC only on supported platforms */
typedef uint64_t mp_digit; typedef uint64_t mp_digit;
# if defined(_WIN32) # if defined(_WIN32)
typedef unsigned __int128 mp_word; typedef unsigned __int128 mp_word;
# elif defined(__GNUC__) # elif defined(__GNUC__)
typedef unsigned long mp_word __attribute__ ((mode(TI))); typedef unsigned long mp_word __attribute__((mode(TI)));
# else # else
/* it seems you have a problem /* it seems you have a problem
* but we assume you can somewhere define your own uint128_t */ * but we assume you can somewhere define your own uint128_t */
typedef uint128_t mp_word; typedef uint128_t mp_word;
# endif # endif
# define DIGIT_BIT 60 # define DIGIT_BIT 60
#else #else
/* this is the default case, 28-bit digits */ /* this is the default case, 28-bit digits */
/* this is to make porting into LibTomCrypt easier :-) */ /* this is to make porting into LibTomCrypt easier :-) */
typedef uint32_t mp_digit; typedef uint32_t mp_digit;
typedef uint64_t mp_word; typedef uint64_t mp_word;
# ifdef MP_31BIT # ifdef MP_31BIT
/* this is an extension that uses 31-bit digits */ /* this is an extension that uses 31-bit digits */
# define DIGIT_BIT 31 # define DIGIT_BIT 31
# else # else
/* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */ /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
# define DIGIT_BIT 28 # define DIGIT_BIT 28
# define MP_28BIT # define MP_28BIT
# endif # endif
@ -94,9 +94,9 @@ extern "C" {
/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ /* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
#ifndef DIGIT_BIT #ifndef DIGIT_BIT
# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ # define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
typedef uint_least32_t mp_min_u32; typedef uint_least32_t mp_min_u32;
#else #else
typedef mp_digit mp_min_u32; typedef mp_digit mp_min_u32;
#endif #endif
/* use arc4random on platforms that support it */ /* use arc4random on platforms that support it */
@ -223,19 +223,19 @@ int mp_set_long(mp_int *a, unsigned long b);
int mp_set_long_long(mp_int *a, unsigned long long b); int mp_set_long_long(mp_int *a, unsigned long long b);
/* get a 32-bit value */ /* get a 32-bit value */
unsigned long mp_get_int(mp_int * a); unsigned long mp_get_int(mp_int *a);
/* get a platform dependent unsigned long value */ /* get a platform dependent unsigned long value */
unsigned long mp_get_long(mp_int * a); unsigned long mp_get_long(mp_int *a);
/* get a platform dependent unsigned long long value */ /* get a platform dependent unsigned long long value */
unsigned long long mp_get_long_long(mp_int * a); unsigned long long mp_get_long_long(mp_int *a);
/* initialize and set a digit */ /* initialize and set a digit */
int mp_init_set (mp_int * a, mp_digit b); int mp_init_set(mp_int *a, mp_digit b);
/* initialize and set 32-bit value */ /* initialize and set 32-bit value */
int mp_init_set_int (mp_int * a, unsigned long b); int mp_init_set_int(mp_int *a, unsigned long b);
/* copy, b = a */ /* copy, b = a */
int mp_copy(mp_int *a, mp_int *b); int mp_copy(mp_int *a, mp_int *b);
@ -247,10 +247,10 @@ int mp_init_copy(mp_int *a, mp_int *b);
void mp_clamp(mp_int *a); void mp_clamp(mp_int *a);
/* import binary data */ /* import binary data */
int mp_import(mp_int* rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op); int mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op);
/* export binary data */ /* export binary data */
int mp_export(void* rop, size_t* countp, int order, size_t size, int endian, size_t nails, mp_int* op); int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int *op);
/* ---> digit manipulation <--- */ /* ---> digit manipulation <--- */
@ -350,7 +350,7 @@ int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
/* c = a**b */ /* c = a**b */
int mp_expt_d(mp_int *a, mp_digit b, mp_int *c); int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast); int mp_expt_d_ex(mp_int *a, mp_digit b, mp_int *c, int fast);
/* c = a mod b, 0 <= c < b */ /* c = a mod b, 0 <= c < b */
int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c); int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
@ -386,7 +386,7 @@ int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
* returns error if a < 0 and b is even * returns error if a < 0 and b is even
*/ */
int mp_n_root(mp_int *a, mp_digit b, mp_int *c); int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast); int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast);
/* special sqrt algo */ /* special sqrt algo */
int mp_sqrt(mp_int *arg, mp_int *ret); int mp_sqrt(mp_int *arg, mp_int *ret);
@ -529,16 +529,16 @@ int mp_count_bits(mp_int *a);
int mp_unsigned_bin_size(mp_int *a); int mp_unsigned_bin_size(mp_int *a);
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c); int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
int mp_to_unsigned_bin(mp_int *a, unsigned char *b); int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen); int mp_to_unsigned_bin_n(mp_int *a, unsigned char *b, unsigned long *outlen);
int mp_signed_bin_size(mp_int *a); int mp_signed_bin_size(mp_int *a);
int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c); int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
int mp_to_signed_bin(mp_int *a, unsigned char *b); int mp_to_signed_bin(mp_int *a, unsigned char *b);
int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen); int mp_to_signed_bin_n(mp_int *a, unsigned char *b, unsigned long *outlen);
int mp_read_radix(mp_int *a, const char *str, int radix); int mp_read_radix(mp_int *a, const char *str, int radix);
int mp_toradix(mp_int *a, char *str, int radix); int mp_toradix(mp_int *a, char *str, int radix);
int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen); int mp_toradix_n(mp_int *a, char *str, int radix, int maxlen);
int mp_radix_size(mp_int *a, int radix, int *size); int mp_radix_size(mp_int *a, int radix, int *size);
#ifndef LTM_NO_FILE #ifndef LTM_NO_FILE
@ -559,7 +559,7 @@ int mp_fwrite(mp_int *a, int radix, FILE *stream);
#define mp_tohex(M, S) mp_toradix((M), (S), 16) #define mp_tohex(M, S) mp_toradix((M), (S), 16)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@ -19,11 +19,11 @@
#include <ctype.h> #include <ctype.h>
#ifndef MIN #ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif #endif
#ifndef MAX #ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@ -41,17 +41,17 @@ extern "C" {
/* define heap macros */ /* define heap macros */
#ifndef XMALLOC #ifndef XMALLOC
/* default to libc stuff */ /* default to libc stuff */
# define XMALLOC malloc # define XMALLOC malloc
# define XFREE free # define XFREE free
# define XREALLOC realloc # define XREALLOC realloc
# define XCALLOC calloc # define XCALLOC calloc
#else #else
/* prototypes for our heap functions */ /* prototypes for our heap functions */
extern void *XMALLOC(size_t n); extern void *XMALLOC(size_t n);
extern void *XREALLOC(void *p, size_t n); extern void *XREALLOC(void *p, size_t n);
extern void *XCALLOC(size_t n, size_t s); extern void *XCALLOC(size_t n, size_t s);
extern void XFREE(void *p); extern void XFREE(void *p);
#endif #endif
/* lowlevel functions, do not call! */ /* lowlevel functions, do not call! */
@ -69,10 +69,10 @@ int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
int mp_karatsuba_sqr(mp_int *a, mp_int *b); int mp_karatsuba_sqr(mp_int *a, mp_int *b);
int mp_toom_sqr(mp_int *a, mp_int *b); int mp_toom_sqr(mp_int *a, mp_int *b);
int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c); int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c); int mp_invmod_slow(mp_int *a, mp_int *b, mp_int *c);
int fast_mp_montgomery_reduce(mp_int *x, mp_int *n, mp_digit rho); int fast_mp_montgomery_reduce(mp_int *x, mp_int *n, mp_digit rho);
int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int redmode); int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int redmode);
int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode); int s_mp_exptmod(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int redmode);
void bn_reverse(unsigned char *s, int len); void bn_reverse(unsigned char *s, int len);
extern const char *mp_s_rmap; extern const char *mp_s_rmap;
@ -112,7 +112,7 @@ int func_name (mp_int * a, type b) \
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@ -33,10 +33,10 @@
# define BN_REVERSE_C # define BN_REVERSE_C
# define BN_PRIME_TAB_C # define BN_PRIME_TAB_C
/* other modifiers */ /* other modifiers */
# define BN_MP_DIV_SMALL /* Slower division, not critical */ # define BN_MP_DIV_SMALL /* Slower division, not critical */
/* here we are on the last pass so we turn things off. The functions classes are still there /* here we are on the last pass so we turn things off. The functions classes are still there
* but we remove them specifically from the build. This also invokes tweaks in functions * but we remove them specifically from the build. This also invokes tweaks in functions
* like removing support for even moduli, etc... * like removing support for even moduli, etc...
*/ */
@ -59,7 +59,7 @@
# undef BN_FAST_S_MP_MUL_HIGH_DIGS_C # undef BN_FAST_S_MP_MUL_HIGH_DIGS_C
# undef BN_FAST_MP_INVMOD_C # undef BN_FAST_MP_INVMOD_C
/* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold /* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold
* which is roughly 255 digits [7140 bits for 32-bit machines, 15300 bits for 64-bit machines] * which is roughly 255 digits [7140 bits for 32-bit machines, 15300 bits for 64-bit machines]
* which means roughly speaking you can handle upto 2536-bit RSA keys with these defined without * which means roughly speaking you can handle upto 2536-bit RSA keys with these defined without
* trouble. * trouble.