69 #if defined( INC_ALL )
85 if (tmp == NULL)
goto err;
90 if (!
BN_sqr(tmp,a,ctx))
goto err;
94 if (!
BN_mul(tmp,a,b,ctx))
goto err;
113 int al,nl,
max,i,x,ri;
127 if ((al == 0) || (nl == 0)) { r->
top=0;
return(1); }
140 for (i=r->
top; i<max; i++)
150 fprintf(stderr,
"word BN_from_montgomery %d * %d\n",nl,nl);
159 t1 = rp[0] * (n0 & 0177777);
162 t3 = rp[0] & 0177777;
172 if (((nrp[-1]+=v)&BN_MASK2) >= v)
176 if (((++nrp[0])&BN_MASK2) != 0)
continue;
177 if (((++nrp[1])&BN_MASK2) != 0)
continue;
178 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
197 for (i=0; i<al; i+=4)
220 if (t1 == NULL || t2 == NULL)
goto err;
225 if (!
BN_mul(t2,t1,&mont->
Ni,ctx))
goto err;
228 if (!
BN_mul(t1,t2,&mont->
N,ctx))
goto err;
229 if (!
BN_add(t2,a,t1))
goto err;
235 if (!
BN_usub(ret,ret,&(mont->
N)))
goto err;
286 if (!
BN_copy(&(mont->
N),mod))
goto err;
307 if (!
BN_lshift(Ri,Ri,BN_BITS2))
goto err;
316 if (!
BN_div(Ri,NULL,Ri,&tmod,ctx))
goto err;
319 mont->
n0 = (Ri->
top > 0) ? Ri->
d[0] : 0;
332 if (!
BN_div(&(mont->
Ni),NULL,Ri,&mont->
N,ctx))
goto err;
339 if (!
BN_mod(&(mont->
RR),&(mont->
RR),&(mont->
N),ctx))
goto err;
349 if (to == from)
return(to);
352 if (!
BN_copy(&(to->
N),&(from->
N)))
return NULL;