| 367 | } |
| 368 | |
| 369 | txBigInt *fxBigInt_mod_exp_LR(txMachine *the, txBigInt *r, txBigInt *b, txBigInt *e, txBigInt *m) |
| 370 | { |
| 371 | int i; |
| 372 | txBigInt *t, *t2 = NULL; |
| 373 | pool_t pool; |
| 374 | |
| 375 | pool_init(&pool); |
| 376 | if (r == NULL) |
| 377 | r = fxBigInt_alloc(the, m->size); |
| 378 | t = pool_get(the, m->size, &pool); |
| 379 | t = mod_exp_init(the, t, m); |
| 380 | if (fxBigInt_ucomp(b, m) > 0) { |
| 381 | t2 = pool_get(the, m->size, &pool); |
| 382 | b = fxBigInt_mod(the, t2, b, m); |
| 383 | } |
| 384 | for (i = fxBigInt_bitsize(e); --i >= 0;) { |
| 385 | fxBigInt_mod_square(the, t, t, m, &pool); |
| 386 | if (fxBigInt_isset(e, i)) |
| 387 | fxBigInt_mod_mul(the, t, t, b, m,&pool); |
| 388 | } |
| 389 | fxBigInt_copy(r, t); |
| 390 | pool_dispose(the, &pool); |
| 391 | return r; |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * Montgomery method |
no test coverage detected