OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #include "ecl-priv.h" | 5 #include "ecl-priv.h" |
6 | 6 |
7 /* Returns 2^e as an integer. This is meant to be used for small powers of | 7 /* Returns 2^e as an integer. This is meant to be used for small powers of |
8 * two. */ | 8 * two. */ |
9 int | 9 int |
10 ec_twoTo(int e) | 10 ec_twoTo(int e) |
(...skipping 30 matching lines...) Expand all Loading... |
41 /* Compute wNAF form */ | 41 /* Compute wNAF form */ |
42 while (mp_cmp_z(&k) > 0) { | 42 while (mp_cmp_z(&k) > 0) { |
43 if (mp_isodd(&k)) { | 43 if (mp_isodd(&k)) { |
44 out[i] = MP_DIGIT(&k, 0) & mask; | 44 out[i] = MP_DIGIT(&k, 0) & mask; |
45 if (out[i] >= twowm1) | 45 if (out[i] >= twowm1) |
46 out[i] -= 2 * twowm1; | 46 out[i] -= 2 * twowm1; |
47 | 47 |
48 /* Subtract off out[i]. Note mp_sub_d only works with | 48 /* Subtract off out[i]. Note mp_sub_d only works with |
49 * unsigned digits */ | 49 * unsigned digits */ |
50 if (out[i] >= 0) { | 50 if (out[i] >= 0) { |
51 » » » » mp_sub_d(&k, out[i], &k); | 51 » » » » MP_CHECKOK(mp_sub_d(&k, out[i], &k)); |
52 } else { | 52 } else { |
53 » » » » mp_add_d(&k, -(out[i]), &k); | 53 » » » » MP_CHECKOK(mp_add_d(&k, -(out[i]), &k)); |
54 } | 54 } |
55 } else { | 55 } else { |
56 out[i] = 0; | 56 out[i] = 0; |
57 } | 57 } |
58 » » mp_div_2(&k, &k); | 58 » » MP_CHECKOK(mp_div_2(&k, &k)); |
59 i++; | 59 i++; |
60 } | 60 } |
61 /* Zero out the remaining elements of the out array. */ | 61 /* Zero out the remaining elements of the out array. */ |
62 for (; i < bitsize + 1; i++) { | 62 for (; i < bitsize + 1; i++) { |
63 out[i] = 0; | 63 out[i] = 0; |
64 } | 64 } |
65 CLEANUP: | 65 CLEANUP: |
66 mp_clear(&k); | 66 mp_clear(&k); |
67 return res; | 67 return res; |
68 | 68 |
69 } | 69 } |
OLD | NEW |