Home | History | Annotate | Download | only in bn

Lines Matching defs:ri

181 	int al,nl,max,i,x,ri;
184 /* mont->ri is the size of mont->N in bits (rounded up
186 al=ri=mont->ri/BN_BITS2;
244 /* mont->ri will be a multiple of the word size and below code
245 * is kind of BN_rshift(ret,r,mont->ri) equivalent */
246 if (r->top <= ri)
251 al=r->top-ri;
255 if (bn_wexpand(ret,ri) == NULL) return(0);
256 x=0-(((al-ri)>>(sizeof(al)*8-1))&1);
257 ret->top=x=(ri&~x)|(al&x); /* min(ri,al) */
261 ap=&(r->d[ri]);
266 v=bn_sub_words(rp,ap,np,ri);
267 /* this ----------------^^ works even in al<ri case
271 /* if (al==ri && !v) || al>ri) nrp=rp; else nrp=ap; */
275 m1=0-(size_t)(((al-ri)>>(sizeof(al)*8-1))&1); /* al<ri */
276 m2=0-(size_t)(((ri-al)>>(sizeof(al)*8-1))&1); /* al>ri */
277 m1|=m2; /* (al!=ri) */
278 m1|=(0-(size_t)v); /* (al!=ri || v) */
279 m1&=~m2; /* (al!=ri || v) && !al>ri */
283 /* 'i<ri' is chosen to eliminate dependency on input data, even
284 * though it results in redundant copy in al<ri case. */
285 for (i=0,ri-=4; i<ri; i+=4)
298 for (ri+=4; i<ri; i++)
308 ap=&(r->d[ri]);
358 BN_mask_bits(t1,mont->ri);
361 BN_mask_bits(t2,mont->ri);
365 if (!BN_rshift(ret,t2,mont->ri)) goto err;
393 ctx->ri=0;
416 BIGNUM *Ri,*R;
419 if((Ri = BN_CTX_get(ctx)) == NULL) goto err;
434 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
449 if ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)
451 if (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err; /* R*Ri */
452 if (!BN_is_zero(Ri))
454 if (!BN_sub_word(Ri,1)) goto err;
458 if (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)
460 /* Ri-- (mod double word size) */
461 Ri->neg=0;
462 Ri->d[0]=BN_MASK2;
463 Ri->d[1]=BN_MASK2;
464 Ri->top=2;
466 if (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;
467 /* Ni = (R*Ri-1)/N,
469 mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;
470 mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;
478 /* Ri = R^-1 mod N*/
479 if ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)
481 if (!BN_lshift(Ri,Ri,BN_BITS2)) goto err; /* R*Ri */
482 if (!BN_is_zero(Ri))
484 if (!BN_sub_word(Ri,1)) goto err;
488 if (!BN_set_word(Ri,BN_MASK2)) goto err; /* Ri-- (mod word size) */
490 if (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;
491 /* Ni = (R*Ri-1)/N,
493 mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;
499 mont->ri=BN_num_bits(&mont->N);
501 if (!BN_set_bit(R,mont->ri)) goto err; /* R = 2^ri */
502 /* Ri = R^-1 mod N*/
503 if ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)
505 if (!BN_lshift(Ri,Ri,mont->ri)) goto err; /* R*Ri */
506 if (!BN_sub_word(Ri,1)) goto err;
507 /* Ni = (R*Ri-1) / N */
508 if (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;
514 if (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;
530 to->ri=from->ri;