| OLD | NEW |
| 1 /* | 1 /* |
| 2 * mpi.c | 2 * mpi.c |
| 3 * | 3 * |
| 4 * Arbitrary precision integer arithmetic library | 4 * Arbitrary precision integer arithmetic library |
| 5 * | 5 * |
| 6 * This Source Code Form is subject to the terms of the Mozilla Public | 6 * This Source Code Form is subject to the terms of the Mozilla Public |
| 7 * License, v. 2.0. If a copy of the MPL was not distributed with this | 7 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 9 | 9 |
| 10 #include "mpi-priv.h" | 10 #include "mpi-priv.h" |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 if(mp_cmp_z(&t) == MP_EQ) | 1329 if(mp_cmp_z(&t) == MP_EQ) |
| 1330 break; | 1330 break; |
| 1331 | 1331 |
| 1332 /* x = x - t */ | 1332 /* x = x - t */ |
| 1333 if((res = mp_sub(&x, &t, &x)) != MP_OKAY) | 1333 if((res = mp_sub(&x, &t, &x)) != MP_OKAY) |
| 1334 goto CLEANUP; | 1334 goto CLEANUP; |
| 1335 | 1335 |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 /* Copy result to output parameter */ | 1338 /* Copy result to output parameter */ |
| 1339 mp_sub_d(&x, 1, &x); | 1339 MP_CHECKOK(mp_sub_d(&x, 1, &x)); |
| 1340 s_mp_exch(&x, b); | 1340 s_mp_exch(&x, b); |
| 1341 | 1341 |
| 1342 CLEANUP: | 1342 CLEANUP: |
| 1343 mp_clear(&x); | 1343 mp_clear(&x); |
| 1344 X: | 1344 X: |
| 1345 mp_clear(&t); | 1345 mp_clear(&t); |
| 1346 | 1346 |
| 1347 return res; | 1347 return res; |
| 1348 | 1348 |
| 1349 } /* end mp_sqrt() */ | 1349 } /* end mp_sqrt() */ |
| (...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2952 { | 2952 { |
| 2953 mp_err res; | 2953 mp_err res; |
| 2954 mp_digit dshift, bshift; | 2954 mp_digit dshift, bshift; |
| 2955 mp_digit mask; | 2955 mp_digit mask; |
| 2956 | 2956 |
| 2957 ARGCHK(mp != NULL, MP_BADARG); | 2957 ARGCHK(mp != NULL, MP_BADARG); |
| 2958 | 2958 |
| 2959 dshift = d / MP_DIGIT_BIT; | 2959 dshift = d / MP_DIGIT_BIT; |
| 2960 bshift = d % MP_DIGIT_BIT; | 2960 bshift = d % MP_DIGIT_BIT; |
| 2961 /* bits to be shifted out of the top word */ | 2961 /* bits to be shifted out of the top word */ |
| 2962 mask = ((mp_digit)~0 << (MP_DIGIT_BIT - bshift)); | 2962 if (bshift) { |
| 2963 mask &= MP_DIGIT(mp, MP_USED(mp) - 1); | 2963 mask = (mp_digit)~0 << (MP_DIGIT_BIT - bshift); |
| 2964 mask &= MP_DIGIT(mp, MP_USED(mp) - 1); |
| 2965 } else { |
| 2966 mask = 0; |
| 2967 } |
| 2964 | 2968 |
| 2965 if (MP_OKAY != (res = s_mp_pad(mp, MP_USED(mp) + dshift + (mask != 0) ))) | 2969 if (MP_OKAY != (res = s_mp_pad(mp, MP_USED(mp) + dshift + (mask != 0) ))) |
| 2966 return res; | 2970 return res; |
| 2967 | 2971 |
| 2968 if (dshift && MP_OKAY != (res = s_mp_lshd(mp, dshift))) | 2972 if (dshift && MP_OKAY != (res = s_mp_lshd(mp, dshift))) |
| 2969 return res; | 2973 return res; |
| 2970 | 2974 |
| 2971 if (bshift) { | 2975 if (bshift) { |
| 2972 mp_digit *pa = MP_DIGITS(mp); | 2976 mp_digit *pa = MP_DIGITS(mp); |
| 2973 mp_digit *alim = pa + MP_USED(mp); | 2977 mp_digit *alim = pa + MP_USED(mp); |
| (...skipping 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4820 } | 4824 } |
| 4821 if (!pos) | 4825 if (!pos) |
| 4822 str[pos++] = 0; | 4826 str[pos++] = 0; |
| 4823 return MP_OKAY; | 4827 return MP_OKAY; |
| 4824 } /* end mp_to_fixlen_octets() */ | 4828 } /* end mp_to_fixlen_octets() */ |
| 4825 /* }}} */ | 4829 /* }}} */ |
| 4826 | 4830 |
| 4827 | 4831 |
| 4828 /*------------------------------------------------------------------------*/ | 4832 /*------------------------------------------------------------------------*/ |
| 4829 /* HERE THERE BE DRAGONS */ | 4833 /* HERE THERE BE DRAGONS */ |
| OLD | NEW |