MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / mont_reduction

Function mont_reduction

modules/crypt/arith/xsBigIntEx.c:412–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412txBigInt *mont_reduction(txMachine *the, txBigInt *r, txBigInt *a, txBigInt *m, txU4 u, pool_t *pool)
413{
414 txBigInt *t1, *t2;
415 txU2 t1siz, t2siz;
416 int n;
417
418 n = m->size;
419 t2siz = n + 1;
420 t1siz = MAX(t2siz, a->size) + 1;
421 t2 = pool_get(the, t2siz, pool);
422 t1 = pool_get(the, t1siz, pool);
423 fxBigInt_copy(t1, a);
424 while (--n >= 0) {
425 txU4 u1 = u * t1->data[0]; /* mod b */
426 fxBigInt_umul1(the, t2, m, u1);
427 fxBigInt_uadd(the, t1, t1, t2);
428 fxBigInt_ulsr1(the, t1, t1, mxBigIntWordSize);
429 }
430 if (fxBigInt_ucomp(t1, m) >= 0)
431 fxBigInt_sub(the, t1, t1, m);
432 fxBigInt_copy(r, t1);
433 pool_put(t1, t1siz);
434 pool_put(t2, t2siz);
435 return r;
436}
437
438txBigInt *mont_in(txMachine *the, txBigInt *r, txBigInt *a, txBigInt *m)
439{

Callers 2

mont_outFunction · 0.85
mont_squareFunction · 0.85

Calls 8

pool_getFunction · 0.85
fxBigInt_copyFunction · 0.85
fxBigInt_umul1Function · 0.85
fxBigInt_uaddFunction · 0.85
fxBigInt_ulsr1Function · 0.85
fxBigInt_ucompFunction · 0.85
fxBigInt_subFunction · 0.85
pool_putFunction · 0.85

Tested by

no test coverage detected