add parentheses for explicit operator association
This commit is contained in:
		
							parent
							
								
									99c84acc4c
								
							
						
					
					
						commit
						81d5f0e39a
					
				| @ -66,7 +66,7 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b) | |||||||
|        * we halve the distance since they approach at a rate of 2x |        * we halve the distance since they approach at a rate of 2x | ||||||
|        * and we have to round because odd cases need to be executed |        * and we have to round because odd cases need to be executed | ||||||
|        */ |        */ | ||||||
|       iy = MIN(iy, (ty-tx+1)>>1); |       iy = MIN(iy, ((ty-tx)+1)>>1); | ||||||
| 
 | 
 | ||||||
|       /* execute loop */ |       /* execute loop */ | ||||||
|       for (iz = 0; iz < iy; iz++) { |       for (iz = 0; iz < iy; iz++) { | ||||||
|  | |||||||
							
								
								
									
										18
									
								
								bn_mp_div.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								bn_mp_div.c
									
									
									
									
									
								
							| @ -190,7 +190,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | |||||||
|     /* step 3.1 if xi == yt then set q{i-t-1} to b-1,
 |     /* step 3.1 if xi == yt then set q{i-t-1} to b-1,
 | ||||||
|      * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */ |      * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */ | ||||||
|     if (x.dp[i] == y.dp[t]) { |     if (x.dp[i] == y.dp[t]) { | ||||||
|       q.dp[i - t - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1); |       q.dp[(i - t) - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1); | ||||||
|     } else { |     } else { | ||||||
|       mp_word tmp; |       mp_word tmp; | ||||||
|       tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT); |       tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT); | ||||||
| @ -199,7 +199,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | |||||||
|       if (tmp > (mp_word) MP_MASK) { |       if (tmp > (mp_word) MP_MASK) { | ||||||
|         tmp = MP_MASK; |         tmp = MP_MASK; | ||||||
|       } |       } | ||||||
|       q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK)); |       q.dp[(i - t) - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* while (q{i-t-1} * (yt * b + y{t-1})) >
 |     /* while (q{i-t-1} * (yt * b + y{t-1})) >
 | ||||||
| @ -207,16 +207,16 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | |||||||
| 
 | 
 | ||||||
|        do q{i-t-1} -= 1; |        do q{i-t-1} -= 1; | ||||||
|     */ |     */ | ||||||
|     q.dp[i - t - 1] = (q.dp[i - t - 1] + 1) & MP_MASK; |     q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] + 1) & MP_MASK; | ||||||
|     do { |     do { | ||||||
|       q.dp[i - t - 1] = (q.dp[i - t - 1] - 1) & MP_MASK; |       q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1) & MP_MASK; | ||||||
| 
 | 
 | ||||||
|       /* find left hand */ |       /* find left hand */ | ||||||
|       mp_zero (&t1); |       mp_zero (&t1); | ||||||
|       t1.dp[0] = ((t - 1) < 0) ? 0 : y.dp[t - 1]; |       t1.dp[0] = ((t - 1) < 0) ? 0 : y.dp[t - 1]; | ||||||
|       t1.dp[1] = y.dp[t]; |       t1.dp[1] = y.dp[t]; | ||||||
|       t1.used = 2; |       t1.used = 2; | ||||||
|       if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) { |       if ((res = mp_mul_d (&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) { | ||||||
|         goto LBL_Y; |         goto LBL_Y; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
| @ -228,11 +228,11 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | |||||||
|     } while (mp_cmp_mag(&t1, &t2) == MP_GT); |     } while (mp_cmp_mag(&t1, &t2) == MP_GT); | ||||||
| 
 | 
 | ||||||
|     /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */ |     /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */ | ||||||
|     if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) { |     if ((res = mp_mul_d (&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) { | ||||||
|       goto LBL_Y; |       goto LBL_Y; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) { |     if ((res = mp_lshd (&t1, (i - t) - 1)) != MP_OKAY) { | ||||||
|       goto LBL_Y; |       goto LBL_Y; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -245,14 +245,14 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) | |||||||
|       if ((res = mp_copy (&y, &t1)) != MP_OKAY) { |       if ((res = mp_copy (&y, &t1)) != MP_OKAY) { | ||||||
|         goto LBL_Y; |         goto LBL_Y; | ||||||
|       } |       } | ||||||
|       if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) { |       if ((res = mp_lshd (&t1, (i - t) - 1)) != MP_OKAY) { | ||||||
|         goto LBL_Y; |         goto LBL_Y; | ||||||
|       } |       } | ||||||
|       if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) { |       if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) { | ||||||
|         goto LBL_Y; |         goto LBL_Y; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK; |       q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1UL) & MP_MASK; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -54,8 +54,8 @@ int mp_export(void* rop, size_t* countp, int order, size_t size, | |||||||
| 		for (j = 0; j < size; ++j) { | 		for (j = 0; j < size; ++j) { | ||||||
| 			unsigned char* byte = ( | 			unsigned char* byte = ( | ||||||
| 				(unsigned char*)rop +  | 				(unsigned char*)rop +  | ||||||
| 				(((order == -1) ? i : (count - 1 - i)) * size) + | 				(((order == -1) ? i : ((count - 1) - i)) * size) + | ||||||
| 				((endian == -1) ? j : (size - 1 - j)) | 				((endian == -1) ? j : ((size - 1) - j)) | ||||||
| 			); | 			); | ||||||
| 
 | 
 | ||||||
| 			if (j >= (size - nail_bytes)) { | 			if (j >= (size - nail_bytes)) { | ||||||
| @ -63,9 +63,9 @@ int mp_export(void* rop, size_t* countp, int order, size_t size, | |||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			*byte = (unsigned char)((j == (size - nail_bytes - 1)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFF)); | 			*byte = (unsigned char)((j == ((size - nail_bytes) - 1)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFF)); | ||||||
| 
 | 
 | ||||||
| 			if ((result = mp_div_2d(&t, ((j == (size - nail_bytes - 1)) ? (8 - odd_nails) : 8), &t, NULL)) != MP_OKAY) { | 			if ((result = mp_div_2d(&t, ((j == ((size - nail_bytes) - 1)) ? (8 - odd_nails) : 8), &t, NULL)) != MP_OKAY) { | ||||||
| 				mp_clear(&t); | 				mp_clear(&t); | ||||||
| 				return result; | 				return result; | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -47,8 +47,8 @@ int mp_import(mp_int* rop, size_t count, int order, size_t size, | |||||||
| 		for (j = 0; j < (size - nail_bytes); ++j) { | 		for (j = 0; j < (size - nail_bytes); ++j) { | ||||||
| 			unsigned char byte = *( | 			unsigned char byte = *( | ||||||
| 					(unsigned char*)op +  | 					(unsigned char*)op +  | ||||||
| 					(((order == 1) ? i : (count - 1 - i)) * size) + | 					(((order == 1) ? i : ((count - 1) - i)) * size) + | ||||||
| 					((endian == 1) ? (j + nail_bytes) : (size - 1 - j - nail_bytes)) | 					((endian == 1) ? (j + nail_bytes) : (((size - 1) - j) - nail_bytes)) | ||||||
| 				); | 				); | ||||||
| 
 | 
 | ||||||
| 			if ( | 			if ( | ||||||
|  | |||||||
| @ -42,7 +42,7 @@ int mp_lshd (mp_int * a, int b) | |||||||
|     top = a->dp + a->used - 1; |     top = a->dp + a->used - 1; | ||||||
| 
 | 
 | ||||||
|     /* base */ |     /* base */ | ||||||
|     bottom = a->dp + a->used - 1 - b; |     bottom = (a->dp + a->used - 1) - b; | ||||||
| 
 | 
 | ||||||
|     /* much like mp_rshd this is implemented using a sliding window
 |     /* much like mp_rshd this is implemented using a sliding window
 | ||||||
|      * except the window goes the otherway around.  Copying from |      * except the window goes the otherway around.  Copying from | ||||||
|  | |||||||
| @ -38,7 +38,7 @@ mp_sqr (mp_int * a, mp_int * b) | |||||||
|     /* can we use the fast comba multiplier? */ |     /* can we use the fast comba multiplier? */ | ||||||
|     if ((((a->used * 2) + 1) < MP_WARRAY) && |     if ((((a->used * 2) + 1) < MP_WARRAY) && | ||||||
|          (a->used < |          (a->used < | ||||||
|          (1 << ((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT) - 1)))) { |          (1 << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) - 1)))) { | ||||||
|       res = fast_s_mp_sqr (a, b); |       res = fast_s_mp_sqr (a, b); | ||||||
|     } else |     } else | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ s_mp_sub (mp_int * a, mp_int * b, mp_int * c) | |||||||
|     u = 0; |     u = 0; | ||||||
|     for (i = 0; i < min; i++) { |     for (i = 0; i < min; i++) { | ||||||
|       /* T[i] = A[i] - B[i] - U */ |       /* T[i] = A[i] - B[i] - U */ | ||||||
|       *tmpc = *tmpa++ - *tmpb++ - u; |       *tmpc = (*tmpa++ - *tmpb++) - u; | ||||||
| 
 | 
 | ||||||
|       /* U = carry bit of T[i]
 |       /* U = carry bit of T[i]
 | ||||||
|        * Note this saves performing an AND operation since |        * Note this saves performing an AND operation since | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user