format with astyle (step 1)
This commit is contained in:
		
							parent
							
								
									71266b3eb9
								
							
						
					
					
						commit
						45771cc91c
					
				
							
								
								
									
										27
									
								
								astylerc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								astylerc
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | |||||||
|  | # Artistic Style, see http://astyle.sourceforge.net/ | ||||||
|  | # full documentation, see: http://astyle.sourceforge.net/astyle.html | ||||||
|  | # | ||||||
|  | # usage: | ||||||
|  | #       astyle --options=astylerc *.[ch] | ||||||
|  | 
 | ||||||
|  | ## Bracket Style Options | ||||||
|  | style=kr | ||||||
|  | 
 | ||||||
|  | ## Tab Options | ||||||
|  | indent=spaces=3 | ||||||
|  | 
 | ||||||
|  | ## Bracket Modify Options | ||||||
|  | 
 | ||||||
|  | ## Indentation Options | ||||||
|  | min-conditional-indent=0 | ||||||
|  | 
 | ||||||
|  | ## Padding Options | ||||||
|  | pad-header | ||||||
|  | unpad-paren | ||||||
|  | align-pointer=name | ||||||
|  | 
 | ||||||
|  | ## Formatting Options | ||||||
|  | break-after-logical | ||||||
|  | max-code-length=120 | ||||||
|  | convert-tabs | ||||||
|  | mode=c | ||||||
| @ -21,7 +21,7 @@ | |||||||
|  * Based on slow invmod except this is optimized for the case where b is |  * Based on slow invmod except this is optimized for the case where b is | ||||||
|  * odd as per HAC Note 14.64 on pp. 610 |  * odd as per HAC Note 14.64 on pp. 610 | ||||||
|  */ |  */ | ||||||
| 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) | ||||||
| { | { | ||||||
|   mp_int  x, y, u, v, B, D; |   mp_int  x, y, u, v, B, D; | ||||||
|   int     res, neg; |   int     res, neg; | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ | |||||||
|  * |  * | ||||||
|  * Based on Algorithm 14.32 on pp.601 of HAC. |  * Based on Algorithm 14.32 on pp.601 of HAC. | ||||||
| */ | */ | ||||||
| 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     ix, res, olduse; |   int     ix, res, olduse; | ||||||
|   mp_word W[MP_WARRAY]; |   mp_word W[MP_WARRAY]; | ||||||
|  | |||||||
| @ -31,7 +31,7 @@ | |||||||
|  * Based on Algorithm 14.12 on pp.595 of HAC. |  * Based on Algorithm 14.12 on pp.595 of HAC. | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
| int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) | int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs) | ||||||
| { | { | ||||||
|   int     olduse, res, pa, ix, iz; |   int     olduse, res, pa, ix, iz; | ||||||
|   mp_digit W[MP_WARRAY]; |   mp_digit W[MP_WARRAY]; | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ | |||||||
|  * |  * | ||||||
|  * Based on Algorithm 14.12 on pp.595 of HAC. |  * Based on Algorithm 14.12 on pp.595 of HAC. | ||||||
|  */ |  */ | ||||||
| int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) | int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs) | ||||||
| { | { | ||||||
|   int     olduse, res, pa, ix, iz; |   int     olduse, res, pa, ix, iz; | ||||||
|   mp_digit W[MP_WARRAY]; |   mp_digit W[MP_WARRAY]; | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ | |||||||
| After that loop you do the squares and add them in. | After that loop you do the squares and add them in. | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| int fast_s_mp_sqr (mp_int * a, mp_int * b) | int fast_s_mp_sqr(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int       olduse, res, pa, ix, iz; |   int       olduse, res, pa, ix, iz; | ||||||
|   mp_digit   W[MP_WARRAY], *tmpx; |   mp_digit   W[MP_WARRAY], *tmpx; | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ | |||||||
|  * Simple algorithm which zeroes the int, grows it then just sets one bit |  * Simple algorithm which zeroes the int, grows it then just sets one bit | ||||||
|  * as required. |  * as required. | ||||||
|  */ |  */ | ||||||
| int mp_2expt (mp_int * a, int b) | int mp_2expt(mp_int *a, int b) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ | |||||||
|  * |  * | ||||||
|  * Simple function copies the input and fixes the sign to positive |  * Simple function copies the input and fixes the sign to positive | ||||||
|  */ |  */ | ||||||
| int mp_abs (mp_int * a, mp_int * b) | int mp_abs(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* high level addition (handles signs) */ | /* high level addition (handles signs) */ | ||||||
| int mp_add (mp_int * a, mp_int * b, mp_int * c) | int mp_add(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     sa, sb, res; |   int     sa, sb, res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* single digit addition */ | /* single digit addition */ | ||||||
| int mp_add_d (mp_int * a, mp_digit b, mp_int * c) | int mp_add_d(mp_int *a, mp_digit b, mp_int *c) | ||||||
| { | { | ||||||
|   int     res, ix, oldused; |   int     res, ix, oldused; | ||||||
|   mp_digit *tmpa, *tmpc, mu; |   mp_digit *tmpa, *tmpc, mu; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* d = a + b (mod c) */ | /* d = a + b (mod c) */ | ||||||
| int mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* AND two ints together */ | /* AND two ints together */ | ||||||
| int mp_and (mp_int * a, mp_int * b, mp_int * c) | int mp_and(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     res, ix, px; |   int     res, ix, px; | ||||||
|   mp_int  t, *x; |   mp_int  t, *x; | ||||||
|  | |||||||
| @ -22,7 +22,7 @@ | |||||||
|  * Typically very fast.  Also fixes the sign if there |  * Typically very fast.  Also fixes the sign if there | ||||||
|  * are no more leading digits |  * are no more leading digits | ||||||
|  */ |  */ | ||||||
| void mp_clamp (mp_int * a) | void mp_clamp(mp_int *a) | ||||||
| { | { | ||||||
|   /* decrease used while the most significant digit is
 |   /* decrease used while the most significant digit is
 | ||||||
|    * zero. |    * zero. | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* clear one (frees)  */ | /* clear one (frees)  */ | ||||||
| void mp_clear (mp_int * a) | void mp_clear(mp_int *a) | ||||||
| { | { | ||||||
|   int i; |   int i; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* compare two ints (signed)*/ | /* compare two ints (signed)*/ | ||||||
| int mp_cmp (mp_int * a, mp_int * b) | int mp_cmp(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   /* compare based on sign */ |   /* compare based on sign */ | ||||||
|   if (a->sign != b->sign) { |   if (a->sign != b->sign) { | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* compare a digit */ | /* compare a digit */ | ||||||
| int mp_cmp_d(mp_int * a, mp_digit b) | int mp_cmp_d(mp_int *a, mp_digit b) | ||||||
| { | { | ||||||
|   /* compare based on sign */ |   /* compare based on sign */ | ||||||
|   if (a->sign == MP_NEG) { |   if (a->sign == MP_NEG) { | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* compare maginitude of two ints (unsigned) */ | /* compare maginitude of two ints (unsigned) */ | ||||||
| int mp_cmp_mag (mp_int * a, mp_int * b) | int mp_cmp_mag(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     n; |   int     n; | ||||||
|   mp_digit *tmpa, *tmpb; |   mp_digit *tmpa, *tmpb; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* copy, b = a */ | /* copy, b = a */ | ||||||
| int mp_copy (mp_int * a, mp_int * b) | int mp_copy(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     res, n; |   int     res, n; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* returns the number of bits in an int */ | /* returns the number of bits in an int */ | ||||||
| int mp_count_bits (mp_int * a) | int mp_count_bits(mp_int *a) | ||||||
| { | { | ||||||
|   int     r; |   int     r; | ||||||
|   mp_digit q; |   mp_digit q; | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ | |||||||
| #ifdef BN_MP_DIV_SMALL | #ifdef BN_MP_DIV_SMALL | ||||||
| 
 | 
 | ||||||
| /* slower bit-bang division... also smaller */ | /* slower bit-bang division... also smaller */ | ||||||
| int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d) | int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d) | ||||||
| { | { | ||||||
|    mp_int ta, tb, tq, q; |    mp_int ta, tb, tq, q; | ||||||
|    int    res, n, n2; |    int    res, n, n2; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* b = a/2 */ | /* b = a/2 */ | ||||||
| int mp_div_2(mp_int * a, mp_int * b) | int mp_div_2(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     x, res, oldused; |   int     x, res, oldused; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ | /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ | ||||||
| int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) | int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d) | ||||||
| { | { | ||||||
|   mp_digit D, r, rr; |   mp_digit D, r, rr; | ||||||
|   int     x, res; |   int     x, res; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* divide by three (based on routine from MPI and the GMP manual) */ | /* divide by three (based on routine from MPI and the GMP manual) */ | ||||||
| int mp_div_3 (mp_int * a, mp_int *c, mp_digit * d) | int mp_div_3(mp_int *a, mp_int *c, mp_digit *d) | ||||||
| { | { | ||||||
|   mp_int   q; |   mp_int   q; | ||||||
|   mp_word  w, t; |   mp_word  w, t; | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ static int s_is_power_of_two(mp_digit b, int *p) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* single digit division (based on routine from MPI) */ | /* single digit division (based on routine from MPI) */ | ||||||
| int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d) | int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d) | ||||||
| { | { | ||||||
|   mp_int  q; |   mp_int  q; | ||||||
|   mp_word w; |   mp_word w; | ||||||
|  | |||||||
| @ -29,7 +29,7 @@ | |||||||
|  * |  * | ||||||
|  * Input x must be in the range 0 <= x <= (n-1)**2 |  * Input x must be in the range 0 <= x <= (n-1)**2 | ||||||
|  */ |  */ | ||||||
| int mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k) | int mp_dr_reduce(mp_int *x, mp_int *n, mp_digit k) | ||||||
| { | { | ||||||
|   int      err, i, m; |   int      err, i, m; | ||||||
|   mp_word  r; |   mp_word  r; | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ | |||||||
| /* swap the elements of two integers, for cases where you can't simply swap the
 | /* swap the elements of two integers, for cases where you can't simply swap the
 | ||||||
|  * mp_int pointers around |  * mp_int pointers around | ||||||
|  */ |  */ | ||||||
| void mp_exch (mp_int * a, mp_int * b) | void mp_exch(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -18,8 +18,9 @@ | |||||||
| /* based on gmp's mpz_export.
 | /* based on gmp's mpz_export.
 | ||||||
|  * see http://gmplib.org/manual/Integer-Import-and-Export.html
 |  * see http://gmplib.org/manual/Integer-Import-and-Export.html
 | ||||||
|  */ |  */ | ||||||
| int mp_export(void* rop, size_t* countp, int order, size_t size, | int mp_export(void *rop, size_t *countp, int order, size_t size, | ||||||
|                                 int endian, size_t nails, mp_int* op) { |               int endian, size_t nails, mp_int *op) | ||||||
|  | { | ||||||
|    int result; |    int result; | ||||||
|    size_t odd_nails, nail_bytes, i, j, bits, count; |    size_t odd_nails, nail_bytes, i, j, bits, count; | ||||||
|    unsigned char odd_nail_mask; |    unsigned char odd_nail_mask; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* wrapper function for mp_expt_d_ex() */ | /* wrapper function for mp_expt_d_ex() */ | ||||||
| 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) | ||||||
| { | { | ||||||
|   return mp_expt_d_ex(a, b, c, 0); |   return mp_expt_d_ex(a, b, c, 0); | ||||||
| } | } | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* calculate c = a**b  using a square-multiply algorithm */ | /* calculate c = a**b  using a square-multiply algorithm */ | ||||||
| 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) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   unsigned int x; |   unsigned int x; | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ | |||||||
|  * embedded in the normal function but that wasted alot of stack space |  * embedded in the normal function but that wasted alot of stack space | ||||||
|  * for nothing (since 99% of the time the Montgomery code would be called) |  * for nothing (since 99% of the time the Montgomery code would be called) | ||||||
|  */ |  */ | ||||||
| int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y) | int mp_exptmod(mp_int *G, mp_int *X, mp_int *P, mp_int *Y) | ||||||
| { | { | ||||||
|   int dr; |   int dr; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -29,7 +29,7 @@ | |||||||
| #   define TAB_SIZE 256 | #   define TAB_SIZE 256 | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 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) | ||||||
| { | { | ||||||
|   mp_int  M[TAB_SIZE], res; |   mp_int  M[TAB_SIZE], res; | ||||||
|   mp_digit buf, mp; |   mp_digit buf, mp; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* Greatest Common Divisor using the binary method */ | /* Greatest Common Divisor using the binary method */ | ||||||
| int mp_gcd (mp_int * a, mp_int * b, mp_int * c) | int mp_gcd(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   mp_int  u, v; |   mp_int  u, v; | ||||||
|   int     k, u_lsb, v_lsb, res; |   int     k, u_lsb, v_lsb, res; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* get the lower 32-bits of an mp_int */ | /* get the lower 32-bits of an mp_int */ | ||||||
| unsigned long mp_get_int(mp_int * a) | unsigned long mp_get_int(mp_int *a) | ||||||
| { | { | ||||||
|   int i; |   int i; | ||||||
|   mp_min_u32 res; |   mp_min_u32 res; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* get the lower unsigned long of an mp_int, platform dependent */ | /* get the lower unsigned long of an mp_int, platform dependent */ | ||||||
| unsigned long mp_get_long(mp_int * a) | unsigned long mp_get_long(mp_int *a) | ||||||
| { | { | ||||||
|   int i; |   int i; | ||||||
|   unsigned long res; |   unsigned long res; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* get the lower unsigned long long of an mp_int, platform dependent */ | /* get the lower unsigned long long of an mp_int, platform dependent */ | ||||||
| unsigned long long mp_get_long_long (mp_int * a) | unsigned long long mp_get_long_long(mp_int *a) | ||||||
| { | { | ||||||
|   int i; |   int i; | ||||||
|   unsigned long long res; |   unsigned long long res; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* grow as required */ | /* grow as required */ | ||||||
| int mp_grow (mp_int * a, int size) | int mp_grow(mp_int *a, int size) | ||||||
| { | { | ||||||
|   int     i; |   int     i; | ||||||
|   mp_digit *tmp; |   mp_digit *tmp; | ||||||
|  | |||||||
| @ -18,8 +18,9 @@ | |||||||
| /* based on gmp's mpz_import.
 | /* based on gmp's mpz_import.
 | ||||||
|  * see http://gmplib.org/manual/Integer-Import-and-Export.html
 |  * see http://gmplib.org/manual/Integer-Import-and-Export.html
 | ||||||
|  */ |  */ | ||||||
| int mp_import(mp_int* rop, size_t count, int order, size_t size, | int mp_import(mp_int *rop, size_t count, int order, size_t size, | ||||||
|                             int endian, size_t nails, const void* op) { |               int endian, size_t nails, const void *op) | ||||||
|  | { | ||||||
|    int result; |    int result; | ||||||
|    size_t odd_nails, nail_bytes, i, j; |    size_t odd_nails, nail_bytes, i, j; | ||||||
|    unsigned char odd_nail_mask; |    unsigned char odd_nail_mask; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* init a new mp_int */ | /* init a new mp_int */ | ||||||
| int mp_init (mp_int * a) | int mp_init(mp_int *a) | ||||||
| { | { | ||||||
|   int i; |   int i; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* creates "a" then copies b into it */ | /* creates "a" then copies b into it */ | ||||||
| int mp_init_copy (mp_int * a, mp_int * b) | int mp_init_copy(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* 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) | ||||||
| { | { | ||||||
|   int err; |   int err; | ||||||
|   if ((err = mp_init(a)) != MP_OKAY) { |   if ((err = mp_init(a)) != MP_OKAY) { | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* initialize and set a digit */ | /* initialize and set a digit */ | ||||||
| int mp_init_set_int (mp_int * a, unsigned long b) | int mp_init_set_int(mp_int *a, unsigned long b) | ||||||
| { | { | ||||||
|   int err; |   int err; | ||||||
|   if ((err = mp_init(a)) != MP_OKAY) { |   if ((err = mp_init(a)) != MP_OKAY) { | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* init an mp_init for a given size */ | /* init an mp_init for a given size */ | ||||||
| int mp_init_size (mp_int * a, int size) | int mp_init_size(mp_int *a, int size) | ||||||
| { | { | ||||||
|   int x; |   int x; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* hac 14.61, pp608 */ | /* hac 14.61, pp608 */ | ||||||
| int mp_invmod (mp_int * a, mp_int * b, mp_int * c) | int mp_invmod(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   /* b cannot be negative */ |   /* b cannot be negative */ | ||||||
|   if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) { |   if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) { | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* hac 14.61, pp608 */ | /* hac 14.61, pp608 */ | ||||||
| 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) | ||||||
| { | { | ||||||
|   mp_int  x, y, u, v, A, B, C, D; |   mp_int  x, y, u, v, A, B, C, D; | ||||||
|   int     res; |   int     res; | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ | |||||||
|  * HAC is wrong here, as the special case of (0 | 1) is not |  * HAC is wrong here, as the special case of (0 | 1) is not | ||||||
|  * handled correctly. |  * handled correctly. | ||||||
|  */ |  */ | ||||||
| int mp_jacobi (mp_int * a, mp_int * n, int *c) | int mp_jacobi(mp_int *a, mp_int *n, int *c) | ||||||
| { | { | ||||||
|   mp_int  a1, p1; |   mp_int  a1, p1; | ||||||
|   int     k, s, r, res; |   int     k, s, r, res; | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ | |||||||
|  * Generally though the overhead of this method doesn't pay off |  * Generally though the overhead of this method doesn't pay off | ||||||
|  * until a certain size (N ~ 80) is reached. |  * until a certain size (N ~ 80) is reached. | ||||||
|  */ |  */ | ||||||
| int mp_karatsuba_mul (mp_int * a, mp_int * b, mp_int * c) | int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   mp_int  x0, x1, y0, y1, t1, x0y0, x1y1; |   mp_int  x0, x1, y0, y1, t1, x0y0, x1y1; | ||||||
|   int     B, err; |   int     B, err; | ||||||
|  | |||||||
| @ -22,7 +22,7 @@ | |||||||
|  * is essentially the same algorithm but merely |  * is essentially the same algorithm but merely | ||||||
|  * tuned to perform recursive squarings. |  * tuned to perform recursive squarings. | ||||||
|  */ |  */ | ||||||
| int mp_karatsuba_sqr (mp_int * a, mp_int * b) | int mp_karatsuba_sqr(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   mp_int  x0, x1, t1, t2, x0x0, x1x1; |   mp_int  x0, x1, t1, t2, x0x0, x1x1; | ||||||
|   int     B, err; |   int     B, err; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* computes least common multiple as |a*b|/(a, b) */ | /* computes least common multiple as |a*b|/(a, b) */ | ||||||
| int mp_lcm (mp_int * a, mp_int * b, mp_int * c) | int mp_lcm(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   mp_int  t1, t2; |   mp_int  t1, t2; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* shift left a certain amount of digits */ | /* shift left a certain amount of digits */ | ||||||
| int mp_lshd (mp_int * a, int b) | int mp_lshd(mp_int *a, int b) | ||||||
| { | { | ||||||
|   int     x, res; |   int     x, res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */ | /* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */ | ||||||
| int mp_mod (mp_int * a, mp_int * b, mp_int * c) | int mp_mod(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|   int     res; |   int     res; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* calc a value mod 2**b */ | /* calc a value mod 2**b */ | ||||||
| int mp_mod_2d (mp_int * a, int b, mp_int * c) | int mp_mod_2d(mp_int *a, int b, mp_int *c) | ||||||
| { | { | ||||||
|   int     x, res; |   int     x, res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ | |||||||
|  * Tom St Denis, tstdenis82@gmail.com, http://libtom.org
 |  * Tom St Denis, tstdenis82@gmail.com, http://libtom.org
 | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| 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) | ||||||
| { | { | ||||||
|   return mp_div_d(a, b, NULL, c); |   return mp_div_d(a, b, NULL, c); | ||||||
| } | } | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ | |||||||
|  * The method is slightly modified to shift B unconditionally upto just under |  * The method is slightly modified to shift B unconditionally upto just under | ||||||
|  * the leading bit of b.  This saves alot of multiple precision shifting. |  * the leading bit of b.  This saves alot of multiple precision shifting. | ||||||
|  */ |  */ | ||||||
| int mp_montgomery_calc_normalization (mp_int * a, mp_int * b) | int mp_montgomery_calc_normalization(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     x, bits, res; |   int     x, bits, res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* computes xR**-1 == x (mod N) via Montgomery Reduction */ | /* computes xR**-1 == x (mod N) via Montgomery Reduction */ | ||||||
| int mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) | int mp_montgomery_reduce(mp_int *x, mp_int *n, mp_digit rho) | ||||||
| { | { | ||||||
|   int     ix, res, digs; |   int     ix, res, digs; | ||||||
|   mp_digit mu; |   mp_digit mu; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* setups the montgomery reduction stuff */ | /* setups the montgomery reduction stuff */ | ||||||
| int mp_montgomery_setup (mp_int * n, mp_digit * rho) | int mp_montgomery_setup(mp_int *n, mp_digit *rho) | ||||||
| { | { | ||||||
|   mp_digit x, b; |   mp_digit x, b; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* high level multiplication (handles sign) */ | /* high level multiplication (handles sign) */ | ||||||
| int mp_mul (mp_int * a, mp_int * b, mp_int * c) | int mp_mul(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     res, neg; |   int     res, neg; | ||||||
|   neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; |   neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* b = a*2 */ | /* b = a*2 */ | ||||||
| int mp_mul_2(mp_int * a, mp_int * b) | int mp_mul_2(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     x, res, oldused; |   int     x, res, oldused; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* shift left by a certain bit count */ | /* shift left by a certain bit count */ | ||||||
| int mp_mul_2d (mp_int * a, int b, mp_int * c) | int mp_mul_2d(mp_int *a, int b, mp_int *c) | ||||||
| { | { | ||||||
|   mp_digit d; |   mp_digit d; | ||||||
|   int      res; |   int      res; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* multiply by a digit */ | /* multiply by a digit */ | ||||||
| int mp_mul_d (mp_int * a, mp_digit b, mp_int * c) | int mp_mul_d(mp_int *a, mp_digit b, mp_int *c) | ||||||
| { | { | ||||||
|   mp_digit u, *tmpa, *tmpc; |   mp_digit u, *tmpa, *tmpc; | ||||||
|   mp_word  r; |   mp_word  r; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* d = a * b (mod c) */ | /* d = a * b (mod c) */ | ||||||
| int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ | |||||||
| /* wrapper function for mp_n_root_ex()
 | /* wrapper function for mp_n_root_ex()
 | ||||||
|  * computes c = (a)**(1/b) such that (c)**b <= a and (c+1)**b > a |  * computes c = (a)**(1/b) such that (c)**b <= a and (c+1)**b > a | ||||||
|  */ |  */ | ||||||
| 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) | ||||||
| { | { | ||||||
|   return mp_n_root_ex(a, b, c, 0); |   return mp_n_root_ex(a, b, c, 0); | ||||||
| } | } | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ | |||||||
|  * each step involves a fair bit.  This is not meant to |  * each step involves a fair bit.  This is not meant to | ||||||
|  * find huge roots [square and cube, etc]. |  * find huge roots [square and cube, etc]. | ||||||
|  */ |  */ | ||||||
| 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) | ||||||
| { | { | ||||||
|   mp_int  t1, t2, t3; |   mp_int  t1, t2, t3; | ||||||
|   int     res, neg; |   int     res, neg; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* b = -a */ | /* b = -a */ | ||||||
| int mp_neg (mp_int * a, mp_int * b) | int mp_neg(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   if (a != b) { |   if (a != b) { | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* OR two ints together */ | /* OR two ints together */ | ||||||
| int mp_or (mp_int * a, mp_int * b, mp_int * c) | int mp_or(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     res, ix, px; |   int     res, ix, px; | ||||||
|   mp_int  t, *x; |   mp_int  t, *x; | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ | |||||||
|  * |  * | ||||||
|  * Sets result to 1 if the congruence holds, or zero otherwise. |  * Sets result to 1 if the congruence holds, or zero otherwise. | ||||||
|  */ |  */ | ||||||
| int mp_prime_fermat (mp_int * a, mp_int * b, int *result) | int mp_prime_fermat(mp_int *a, mp_int *b, int *result) | ||||||
| { | { | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|   int     err; |   int     err; | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ | |||||||
|  * |  * | ||||||
|  * sets result to 0 if not, 1 if yes |  * sets result to 0 if not, 1 if yes | ||||||
|  */ |  */ | ||||||
| int mp_prime_is_divisible (mp_int * a, int *result) | int mp_prime_is_divisible(mp_int *a, int *result) | ||||||
| { | { | ||||||
|   int     err, ix; |   int     err, ix; | ||||||
|   mp_digit res; |   mp_digit res; | ||||||
|  | |||||||
| @ -22,7 +22,7 @@ | |||||||
|  * |  * | ||||||
|  * Sets result to 1 if probably prime, 0 otherwise |  * Sets result to 1 if probably prime, 0 otherwise | ||||||
|  */ |  */ | ||||||
| int mp_prime_is_prime (mp_int * a, int t, int *result) | int mp_prime_is_prime(mp_int *a, int t, int *result) | ||||||
| { | { | ||||||
|   mp_int  b; |   mp_int  b; | ||||||
|   int     ix, err, res; |   int     ix, err, res; | ||||||
|  | |||||||
| @ -22,7 +22,7 @@ | |||||||
|  * Randomly the chance of error is no more than 1/4 and often |  * Randomly the chance of error is no more than 1/4 and often | ||||||
|  * very much lower. |  * very much lower. | ||||||
|  */ |  */ | ||||||
| int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result) | int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result) | ||||||
| { | { | ||||||
|   mp_int  n1, y, r; |   mp_int  n1, y, r; | ||||||
|   int     s, j, err; |   int     s, j, err; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* returns size of ASCII reprensentation */ | /* returns size of ASCII reprensentation */ | ||||||
| int mp_radix_size (mp_int * a, int radix, int *size) | int mp_radix_size(mp_int *a, int radix, int *size) | ||||||
| { | { | ||||||
|   int     res, digs; |   int     res, digs; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -41,7 +41,7 @@ static mp_digit s_gen_random(void) | |||||||
|   return d; |   return d; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int mp_rand (mp_int * a, int digits) | int mp_rand(mp_int *a, int digits) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   mp_digit d; |   mp_digit d; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* read a string [ASCII] in a given radix */ | /* read a string [ASCII] in a given radix */ | ||||||
| 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     y, res, neg; |   int     y, res, neg; | ||||||
|   char    ch; |   char    ch; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* read signed bin, big endian, first byte is 0==positive or 1==negative */ | /* read signed bin, big endian, first byte is 0==positive or 1==negative */ | ||||||
| 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     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* reads a unsigned char array, assumes the msb is stored first [big endian] */ | /* reads a unsigned char array, assumes the msb is stored first [big endian] */ | ||||||
| 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     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ | |||||||
|  * precomputed via mp_reduce_setup. |  * precomputed via mp_reduce_setup. | ||||||
|  * From HAC pp.604 Algorithm 14.42 |  * From HAC pp.604 Algorithm 14.42 | ||||||
|  */ |  */ | ||||||
| int mp_reduce (mp_int * x, mp_int * m, mp_int * mu) | int mp_reduce(mp_int *x, mp_int *m, mp_int *mu) | ||||||
| { | { | ||||||
|   mp_int  q; |   mp_int  q; | ||||||
|   int     res, um = m->used; |   int     res, um = m->used; | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ | |||||||
| /* pre-calculate the value required for Barrett reduction
 | /* pre-calculate the value required for Barrett reduction
 | ||||||
|  * For a given modulus "b" it calulates the value required in "a" |  * For a given modulus "b" it calulates the value required in "a" | ||||||
|  */ |  */ | ||||||
| int mp_reduce_setup (mp_int * a, mp_int * b) | int mp_reduce_setup(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* shift right a certain amount of digits */ | /* shift right a certain amount of digits */ | ||||||
| void mp_rshd (mp_int * a, int b) | void mp_rshd(mp_int *a, int b) | ||||||
| { | { | ||||||
|   int     x; |   int     x; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* set to a digit */ | /* set to a digit */ | ||||||
| void mp_set (mp_int * a, mp_digit b) | void mp_set(mp_int *a, mp_digit b) | ||||||
| { | { | ||||||
|   mp_zero(a); |   mp_zero(a); | ||||||
|   a->dp[0] = b & MP_MASK; |   a->dp[0] = b & MP_MASK; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* set a 32-bit const */ | /* set a 32-bit const */ | ||||||
| int mp_set_int (mp_int * a, unsigned long b) | int mp_set_int(mp_int *a, unsigned long b) | ||||||
| { | { | ||||||
|   int     x, res; |   int     x, res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* shrink a bignum */ | /* shrink a bignum */ | ||||||
| int mp_shrink (mp_int * a) | int mp_shrink(mp_int *a) | ||||||
| { | { | ||||||
|   mp_digit *tmp; |   mp_digit *tmp; | ||||||
|   int used = 1; |   int used = 1; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* get the size for an signed equivalent */ | /* get the size for an signed equivalent */ | ||||||
| int mp_signed_bin_size (mp_int * a) | int mp_signed_bin_size(mp_int *a) | ||||||
| { | { | ||||||
|   return 1 + mp_unsigned_bin_size(a); |   return 1 + mp_unsigned_bin_size(a); | ||||||
| } | } | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* computes b = a*a */ | /* computes b = a*a */ | ||||||
| int mp_sqr (mp_int * a, mp_int * b) | int mp_sqr(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* c = a * a (mod b) */ | /* c = a * a (mod b) */ | ||||||
| int mp_sqrmod (mp_int * a, mp_int * b, mp_int * c) | int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* high level subtraction (handles signs) */ | /* high level subtraction (handles signs) */ | ||||||
| int mp_sub (mp_int * a, mp_int * b, mp_int * c) | int mp_sub(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     sa, sb, res; |   int     sa, sb, res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* single digit subtraction */ | /* single digit subtraction */ | ||||||
| int mp_sub_d (mp_int * a, mp_digit b, mp_int * c) | int mp_sub_d(mp_int *a, mp_digit b, mp_int *c) | ||||||
| { | { | ||||||
|   mp_digit *tmpa, *tmpc, mu; |   mp_digit *tmpa, *tmpc, mu; | ||||||
|   int       res, ix, oldused; |   int       res, ix, oldused; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* d = a - b (mod c) */ | /* d = a - b (mod c) */ | ||||||
| int mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* store in signed [big endian] format */ | /* store in signed [big endian] format */ | ||||||
| int mp_to_signed_bin (mp_int * a, unsigned char *b) | int mp_to_signed_bin(mp_int *a, unsigned char *b) | ||||||
| { | { | ||||||
|   int     res; |   int     res; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* store in signed [big endian] format */ | /* store in signed [big endian] format */ | ||||||
| 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) | ||||||
| { | { | ||||||
|    if (*outlen < (unsigned long)mp_signed_bin_size(a)) { |    if (*outlen < (unsigned long)mp_signed_bin_size(a)) { | ||||||
|       return MP_VAL; |       return MP_VAL; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* store in unsigned [big endian] format */ | /* store in unsigned [big endian] format */ | ||||||
| int mp_to_unsigned_bin (mp_int * a, unsigned char *b) | int mp_to_unsigned_bin(mp_int *a, unsigned char *b) | ||||||
| { | { | ||||||
|   int     x, res; |   int     x, res; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* store in unsigned [big endian] format */ | /* store in unsigned [big endian] format */ | ||||||
| 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) | ||||||
| { | { | ||||||
|    if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) { |    if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) { | ||||||
|       return MP_VAL; |       return MP_VAL; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* stores a bignum as a ASCII string in a given radix (2..64) */ | /* stores a bignum as a ASCII string in a given radix (2..64) */ | ||||||
| int mp_toradix (mp_int * a, char *str, int radix) | int mp_toradix(mp_int *a, char *str, int radix) | ||||||
| { | { | ||||||
|   int     res, digs; |   int     res, digs; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ | |||||||
|  * |  * | ||||||
|  * Stores upto maxlen-1 chars and always a NULL byte |  * Stores upto maxlen-1 chars and always a NULL byte | ||||||
|  */ |  */ | ||||||
| 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     res, digs; |   int     res, digs; | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* get the size for an unsigned equivalent */ | /* get the size for an unsigned equivalent */ | ||||||
| int mp_unsigned_bin_size (mp_int * a) | int mp_unsigned_bin_size(mp_int *a) | ||||||
| { | { | ||||||
|   int     size = mp_count_bits(a); |   int     size = mp_count_bits(a); | ||||||
|   return (size / 8) + (((size & 7) != 0) ? 1 : 0); |   return (size / 8) + (((size & 7) != 0) ? 1 : 0); | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* XOR two ints together */ | /* XOR two ints together */ | ||||||
| int mp_xor (mp_int * a, mp_int * b, mp_int * c) | int mp_xor(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   int     res, ix, px; |   int     res, ix, px; | ||||||
|   mp_int  t, *x; |   mp_int  t, *x; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* set to zero */ | /* set to zero */ | ||||||
| void mp_zero (mp_int * a) | void mp_zero(mp_int *a) | ||||||
| { | { | ||||||
|   int       n; |   int       n; | ||||||
|   mp_digit *tmp; |   mp_digit *tmp; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* reverse an array, used for radix code */ | /* reverse an array, used for radix code */ | ||||||
| void bn_reverse (unsigned char *s, int len) | void bn_reverse(unsigned char *s, int len) | ||||||
| { | { | ||||||
|   int     ix, iy; |   int     ix, iy; | ||||||
|   unsigned char t; |   unsigned char t; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* low level addition, based on HAC pp.594, Algorithm 14.7 */ | /* low level addition, based on HAC pp.594, Algorithm 14.7 */ | ||||||
| int s_mp_add (mp_int * a, mp_int * b, mp_int * c) | int s_mp_add(mp_int *a, mp_int *b, mp_int *c) | ||||||
| { | { | ||||||
|   mp_int *x; |   mp_int *x; | ||||||
|   int     olduse, res, min, max; |   int     olduse, res, min, max; | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ | |||||||
| #   define TAB_SIZE 256 | #   define TAB_SIZE 256 | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 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) | ||||||
| { | { | ||||||
|   mp_int  M[TAB_SIZE], res, mu; |   mp_int  M[TAB_SIZE], res, mu; | ||||||
|   mp_digit buf; |   mp_digit buf; | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ | |||||||
|  * HAC pp. 595, Algorithm 14.12  Modified so you can control how |  * HAC pp. 595, Algorithm 14.12  Modified so you can control how | ||||||
|  * many digits of output are created. |  * many digits of output are created. | ||||||
|  */ |  */ | ||||||
| int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) | int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs) | ||||||
| { | { | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|   int     res, pa, pb, ix, iy; |   int     res, pa, pb, ix, iy; | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ | |||||||
| /* multiplies |a| * |b| and does not compute the lower digs digits
 | /* multiplies |a| * |b| and does not compute the lower digs digits
 | ||||||
|  * [meant to get the higher part of the product] |  * [meant to get the higher part of the product] | ||||||
|  */ |  */ | ||||||
| int s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) | int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs) | ||||||
| { | { | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|   int     res, pa, pb, ix, iy; |   int     res, pa, pb, ix, iy; | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ | |||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */ | /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */ | ||||||
| int s_mp_sqr (mp_int * a, mp_int * b) | int s_mp_sqr(mp_int *a, mp_int *b) | ||||||
| { | { | ||||||
|   mp_int  t; |   mp_int  t; | ||||||
|   int     res, ix, iy, pa; |   int     res, ix, iy, pa; | ||||||
|  | |||||||
Some files were not shown because too many files have changed in this diff Show More
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user