134 #if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)
137 if (num>1 && a->
top==num && b->
top==num)
152 if (tmp == NULL)
goto err;
157 if (!
BN_sqr(tmp,a,ctx))
goto err;
161 if (!
BN_mul(tmp,a,b,ctx))
goto err;
165 if (!BN_from_montgomery_word(r,tmp,mont))
goto err;
180 BN_ULONG *ap,*np,*rp,n0,v,carry;
185 if (nl == 0) { ret->
top=0;
return(1); }
196 for (i=r->
top; i<max; i++)
199 memset(&(rp[r->
top]),0,(max-r->
top)*
sizeof(BN_ULONG));
206 fprintf(stderr,
"word BN_from_montgomery_word %d * %d\n",nl,nl);
208 for (carry=0, i=0; i<nl; i++, rp++)
215 t1 = rp[0] * (n0 & 0177777);
218 t3 = rp[0] & 0177777;
219 t2 = (t3 * t2) & BN_MASK2;
226 v = (v+carry+rp[nl])&BN_MASK2;
227 carry |= (v != rp[nl]);
228 carry &= (v <= rp[nl]);
239 #define BRANCH_FREE 1
252 for (i=0,nl-=4; i<nl; i+=4)
254 BN_ULONG t1,t2,t3,t4;
258 t3=nrp[i+2]; ap[i+0]=0;
259 t4=nrp[i+3]; ap[i+1]=0;
260 rp[i+0]=t1; ap[i+2]=0;
261 rp[i+1]=t2; ap[i+3]=0;
265 for (nl+=4; i<nl; i++)
266 rp[i]=nrp[i], ap[i]=0;
270 memcpy(rp,ap,nl*
sizeof(BN_ULONG));
289 retn = BN_from_montgomery_word(ret,t,mont);
297 if (t1 == NULL || t2 == NULL)
goto err;
302 if (!
BN_mul(t2,t1,&mont->
Ni,ctx))
goto err;
305 if (!
BN_mul(t1,t2,&mont->
N,ctx))
goto err;
306 if (!
BN_add(t2,a,t1))
goto err;
311 if (!
BN_usub(ret,ret,&(mont->
N)))
goto err;
339 ctx->
n0[0] = ctx->
n0[1] = 0;
363 if (!
BN_copy(&(mont->
N),mod))
goto err;
378 #if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)
388 if ((buf[0] = mod->
d[0])) tmod.
top=1;
389 if ((buf[1] = mod->
top>1 ? mod->
d[1] : 0)) tmod.
top=2;
393 if (!
BN_lshift(Ri,Ri,2*BN_BITS2))
goto err;
400 if (
bn_expand(Ri,(
int)
sizeof(BN_ULONG)*2) == NULL)
408 if (!
BN_div(Ri,NULL,Ri,&tmod,ctx))
goto err;
411 mont->
n0[0] = (Ri->
top > 0) ? Ri->
d[0] : 0;
412 mont->
n0[1] = (Ri->
top > 1) ? Ri->
d[1] : 0;
419 tmod.
top = buf[0] != 0 ? 1 : 0;
423 if (!
BN_lshift(Ri,Ri,BN_BITS2))
goto err;
432 if (!
BN_div(Ri,NULL,Ri,&tmod,ctx))
goto err;
435 mont->
n0[0] = (Ri->
top > 0) ? Ri->
d[0] : 0;
450 if (!
BN_div(&(mont->
Ni),NULL,Ri,&mont->
N,ctx))
goto err;
457 if (!
BN_mod(&(mont->
RR),&(mont->
RR),&(mont->
N),ctx))
goto err;
467 if (to == from)
return(to);
470 if (!
BN_copy(&(to->
N),&(from->
N)))
return NULL;
473 to->
n0[0]=from->
n0[0];
474 to->
n0[1]=from->
n0[1];
481 int got_write_lock = 0;