| 410 | } |
| 411 | |
| 412 | txBigInt *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 | |
| 438 | txBigInt *mont_in(txMachine *the, txBigInt *r, txBigInt *a, txBigInt *m) |
| 439 | { |
no test coverage detected