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

Function mont_mul

modules/crypt/arith/xsBigIntEx.c:462–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462static txBigInt *mont_mul(txMachine *the, txBigInt *r, txBigInt *a, txBigInt *b, txBigInt *m, txU4 u, pool_t *pool)
463{
464 int i, n, sz;
465 txBigInt *t1, *t2, *t3;
466
467 sz = MAX(b->size + 1, m->size + 1) + 1;
468 t1 = pool_get(the, sz, pool);
469 t2 = pool_get(the, sz, pool);
470 t3 = pool_get(the, sz + 1, pool);
471 t3->size = 1;
472 t3->data[0] = 0;
473 for (i = 0, n = m->size; i < n; i++) {
474 txU4 s = i < a->size ? a->data[i] : 0;
475 txU4 u1 = (t3->data[0] + s * b->data[0]) * u;
476 fxBigInt_umul1(the, t1, b, s);
477 fxBigInt_umul1(the, t2, m, u1);
478 fxBigInt_uadd(the, t1, t1, t2);
479 fxBigInt_uadd(the, t3, t3, t1);
480 fxBigInt_ulsr1(the, t3, t3, mxBigIntWordSize);
481 }
482 if (fxBigInt_ucomp(t3, m) >= 0)
483 fxBigInt_sub(the, t3, t3, m);
484 fxBigInt_copy(r, t3);
485 pool_put(t3, sz + 1);
486 pool_put(t2, sz);
487 pool_put(t1, sz);
488 return r;
489}
490
491static txBigInt *mont_square(txMachine *the, txBigInt *r, txBigInt *a, txBigInt *m, txU4 u, pool_t *pool)
492{

Callers 2

fxBigInt_mont_exp_LRFunction · 0.85
fxBigInt_mont_exp_SWFunction · 0.85

Calls 8

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

Tested by

no test coverage detected