Mercurial > dropbear
comparison libtommath/bn_mp_div_2d.c @ 1478:3a933956437e coverity
update coverity
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 23:49:22 +0800 |
parents | 8bba51a55704 |
children | f52919ffd3b1 |
comparison
equal
deleted
inserted
replaced
1439:8d24733026c5 | 1478:3a933956437e |
---|---|
18 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ | 18 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ |
19 int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) | 19 int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) |
20 { | 20 { |
21 mp_digit D, r, rr; | 21 mp_digit D, r, rr; |
22 int x, res; | 22 int x, res; |
23 mp_int t; | |
24 | |
25 | 23 |
26 /* if the shift count is <= 0 then we do no work */ | 24 /* if the shift count is <= 0 then we do no work */ |
27 if (b <= 0) { | 25 if (b <= 0) { |
28 res = mp_copy (a, c); | 26 res = mp_copy (a, c); |
29 if (d != NULL) { | 27 if (d != NULL) { |
30 mp_zero (d); | 28 mp_zero (d); |
31 } | 29 } |
32 return res; | 30 return res; |
33 } | 31 } |
34 | 32 |
35 if ((res = mp_init (&t)) != MP_OKAY) { | 33 /* copy */ |
34 if ((res = mp_copy (a, c)) != MP_OKAY) { | |
36 return res; | 35 return res; |
37 } | 36 } |
37 /* 'a' should not be used after here - it might be the same as d */ | |
38 | 38 |
39 /* get the remainder */ | 39 /* get the remainder */ |
40 if (d != NULL) { | 40 if (d != NULL) { |
41 if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) { | 41 if ((res = mp_mod_2d (a, b, d)) != MP_OKAY) { |
42 mp_clear (&t); | |
43 return res; | 42 return res; |
44 } | 43 } |
45 } | |
46 | |
47 /* copy */ | |
48 if ((res = mp_copy (a, c)) != MP_OKAY) { | |
49 mp_clear (&t); | |
50 return res; | |
51 } | 44 } |
52 | 45 |
53 /* shift by as many digits in the bit count */ | 46 /* shift by as many digits in the bit count */ |
54 if (b >= (int)DIGIT_BIT) { | 47 if (b >= (int)DIGIT_BIT) { |
55 mp_rshd (c, b / DIGIT_BIT); | 48 mp_rshd (c, b / DIGIT_BIT); |
82 /* set the carry to the carry bits of the current word found above */ | 75 /* set the carry to the carry bits of the current word found above */ |
83 r = rr; | 76 r = rr; |
84 } | 77 } |
85 } | 78 } |
86 mp_clamp (c); | 79 mp_clamp (c); |
87 if (d != NULL) { | |
88 mp_exch (&t, d); | |
89 } | |
90 mp_clear (&t); | |
91 return MP_OKAY; | 80 return MP_OKAY; |
92 } | 81 } |
93 #endif | 82 #endif |
94 | 83 |
95 /* $Source$ */ | 84 /* ref: $Format:%D$ */ |
96 /* $Revision$ */ | 85 /* git commit: $Format:%H$ */ |
97 /* $Date$ */ | 86 /* commit time: $Format:%ai$ */ |