void modg(giant d, giant n) /* n becomes n%d. n is arbitrary, but the denominator d must be positive! */ { if (cur_recip == NULL) { cur_recip = newgiant(current_max_size); cur_den = newgiant(current_max_size); gtog(d, cur_den); make_recip(d, cur_recip); } else if (gcompg(d, cur_den)) { gtog(d, cur_den); make_recip(d, cur_recip); } modg_via_recip(d, cur_recip, n); }
/* * This version is not normally used; it's for when the reciprocal of * curveOrder is not known and won't be used again. */ void curveOrderJustify(giant g, giant curveOrder) { giant recip; CKASSERT(!isZero(curveOrder)); recip = borrowGiant(2 * abs(g->sign)); make_recip(curveOrder, recip); curveOrderJustifyWithRecip(g, curveOrder, recip); returnGiant(recip); }
/* * Common code used by x1OrderPlusJustify() and x1OrderPlusMod() to generate * reciprocal of x1OrderPlus. * 8 Sep 1998 - also used by feeSigSign(). */ void calcX1OrderPlusRecip(curveParams *cp) { if(isZero(cp->x1OrderPlusRecip)) { if((cp->x1OrderPlus == lesserX1Order(cp)) && (!isZero(cp->lesserX1OrderRecip))) { /* * lesserX1Order happens to be x1OrderPlus, and we * have a reciprocal for lesserX1Order. Copy it over. */ recipLog(( "lesserX1OrderRecip --> x1OrderPlusRecip\n")); gtog(cp->lesserX1OrderRecip, cp->x1OrderPlusRecip); } else { /* Calculate the reciprocal. */ recipLog(("calc x1OrderPlusRecip\n")); make_recip(cp->x1OrderPlus, cp->x1OrderPlusRecip); } } else { recipLog(("using existing x1OrderPlusRecip\n")); } }
/* * curveOrderJustify routines with specific orders, using (and possibly * generating) associated reciprocals. */ void lesserX1OrderJustify(giant g, curveParams *cp) { /* * Note this is a pointer to a giant in *cp, not a newly * malloc'd giant! */ giant lesserX1Ord = lesserX1Order(cp); if(isZero(lesserX1Ord)) { return; } /* * Calculate reciprocal if we don't have it */ if(isZero(cp->lesserX1OrderRecip)) { if((lesserX1Ord == cp->x1OrderPlus) && (!isZero(cp->x1OrderPlusRecip))) { /* * lesserX1Ord happens to be x1OrderPlus, and we * have a reciprocal for x1OrderPlus. Copy it over. */ recipLog(( "x1OrderPlusRecip --> lesserX1OrderRecip\n")); gtog(cp->x1OrderPlusRecip, cp->lesserX1OrderRecip); } else { /* Calculate the reciprocal. */ recipLog(("calc lesserX1OrderRecip\n")); make_recip(lesserX1Ord, cp->lesserX1OrderRecip); } } else { recipLog(("using existing lesserX1OrderRecip\n")); } curveOrderJustifyWithRecip(g, lesserX1Ord, cp->lesserX1OrderRecip); }