- i=exp->length_B-1;
- if(exp->wordv[i]!=1){
- for(j=1<<(GET_FBS(exp)-1); j>0; j>>=1){
- bigint_square(&tmp2, &tmp);
- bigint_reduce(&tmp2, r);
- if(exp->wordv[i]&j){
- bigint_mul_u(&tmp, &tmp2, &x);
- bigint_reduce(&tmp, r);
- }else{
- bigint_copy(&tmp, &tmp2);
+
+ bigint_t res, base;
+ uint8_t base_b[MAX(a->length_B,r->length_B*2)], res_b[r->length_B*2];
+ uint16_t i;
+ uint8_t j, t;
+ res.wordv = res_b;
+ base.wordv = base_b;
+ bigint_copy(&base, a);
+ bigint_reduce(&base, r);
+ res.wordv[0]=1;
+ res.length_B=1;
+ res.info = 0;
+ bigint_adjust(&res);
+ for(i=0; i+1<exp->length_B; ++i){
+ t=exp->wordv[i];
+ for(j=0; j<8; ++j){
+ if(t&1){
+ bigint_mul_u(&res, &res, &base);
+ bigint_reduce(&res, r);