#include "os.h"#include <mp.h> /* operands need to have m->top+1 digits of space and satisfy 0 ≤ a ≤ m-1 */static mpint*modarg(mpint *a, mpint *m){ if(a->size <= m->top || a->sign < 0 || mpmagcmp(a, m) >= 0){ a = mpcopy(a); mpmod(a, m, a); mpbits(a, Dbits*(m->top+1)); a->top = m->top; } else if(a->top < m->top){ memset(&a->p[a->top], 0, (m->top - a->top)*Dbytes); } return a;} voidmpmodmul(mpint *b1, mpint *b2, mpint *m, mpint *prod){ mpint *a, *b; a = modarg(b1, m); b = modarg(b2, m); mpmul(a, b, prod); mpmod(prod, m, prod); if(a != b1) mpfree(a); if(b != b2) mpfree(b);}
#include "os.h"
#include <mp.h>
/* operands need to have m->top+1 digits of space and satisfy 0 ≤ a ≤ m-1 */
static mpint*
modarg(mpint *a, mpint *m)
{
if(a->size <= m->top || a->sign < 0 || mpmagcmp(a, m) >= 0){
a = mpcopy(a);
mpmod(a, m, a);
mpbits(a, Dbits*(m->top+1));
a->top = m->top;
} else if(a->top < m->top){
memset(&a->p[a->top], 0, (m->top - a->top)*Dbytes);
}
return a;
}
void
mpmodmul(mpint *b1, mpint *b2, mpint *m, mpint *prod)
{
mpint *a, *b;
a = modarg(b1, m);
b = modarg(b2, m);
mpmul(a, b, prod);
mpmod(prod, m, prod);
if(a != b1)
mpfree(a);
if(b != b2)
mpfree(b);
}