comparison libtommath/bn_mp_exptmod_fast.c @ 608:4fbf9a7556ed

Use mp_init_size() to avoid some mp_grow()s
author Matt Johnston <matt@ucc.asn.au>
date Fri, 18 Mar 2011 14:31:07 +0000
parents 5ff8218bcee9
children 60fc6476e044
comparison
equal deleted inserted replaced
607:aa2f51a6b81d 608:4fbf9a7556ed
65 } 65 }
66 #endif 66 #endif
67 67
68 /* init M array */ 68 /* init M array */
69 /* init first cell */ 69 /* init first cell */
70 if ((err = mp_init(&M[1])) != MP_OKAY) { 70 if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) {
71 return err; 71 return err;
72 } 72 }
73 73
74 /* now init the second half of the array */ 74 /* now init the second half of the array */
75 for (x = 1<<(winsize-1); x < (1 << winsize); x++) { 75 for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
76 if ((err = mp_init(&M[x])) != MP_OKAY) { 76 if ((err = mp_init_size(&M[x], P->alloc)) != MP_OKAY) {
77 for (y = 1<<(winsize-1); y < x; y++) { 77 for (y = 1<<(winsize-1); y < x; y++) {
78 mp_clear (&M[y]); 78 mp_clear (&M[y]);
79 } 79 }
80 mp_clear(&M[1]); 80 mp_clear(&M[1]);
81 return err; 81 return err;
131 goto LBL_M; 131 goto LBL_M;
132 #endif 132 #endif
133 } 133 }
134 134
135 /* setup result */ 135 /* setup result */
136 if ((err = mp_init (&res)) != MP_OKAY) { 136 if ((err = mp_init_size (&res, P->alloc)) != MP_OKAY) {
137 goto LBL_M; 137 goto LBL_M;
138 } 138 }
139 139
140 /* create M table 140 /* create M table
141 * 141 *