| 723 | */ |
| 724 | |
| 725 | static void ec_add(txMachine *the, txECPoint *r, txECPoint *a, txECPoint *b, txECParam *ec, pool_t *pool) |
| 726 | { |
| 727 | txBigInt *Z1Z1, *Z2Z2, *U1, *U2, *S1, *S2, *H, *I, *J, *R, *V, *X3, *Y3, *Z3; |
| 728 | txBigInt *t1, *t2; |
| 729 | txBigInt *m = ec->m; |
| 730 | |
| 731 | if (fxBigInt_iszero(a->z)) { |
| 732 | fxBigInt_copy(r->x, b->x); |
| 733 | fxBigInt_copy(r->y, b->y); |
| 734 | fxBigInt_copy(r->z, b->z); |
| 735 | return; |
| 736 | } |
| 737 | else if (fxBigInt_iszero(b->z)) { |
| 738 | fxBigInt_copy(r->x, a->x); |
| 739 | fxBigInt_copy(r->y, a->y); |
| 740 | fxBigInt_copy(r->z, a->z); |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | t1 = pool_get(the, m->size, pool); |
| 745 | t2 = pool_get(the, m->size, pool); |
| 746 | Z1Z1 = pool_get(the, m->size, pool); |
| 747 | Z2Z2 = pool_get(the, m->size, pool); |
| 748 | U1 = pool_get(the, m->size, pool); |
| 749 | U2 = pool_get(the, m->size, pool); |
| 750 | S1 = pool_get(the, m->size, pool); |
| 751 | S2 = pool_get(the, m->size, pool); |
| 752 | |
| 753 | Z1Z1 = fxBigInt_mont_square(the, Z1Z1, a->z, m, ec->u, pool); |
| 754 | Z2Z2 = fxBigInt_mont_square(the, Z2Z2, b->z, m, ec->u, pool); |
| 755 | U1 = fxBigInt_mont_mul(the, U1, a->x, Z2Z2, m, ec->u, pool); |
| 756 | U2 = fxBigInt_mont_mul(the, U2, b->x, Z1Z1, m, ec->u, pool); |
| 757 | t1 = fxBigInt_mont_mul(the, t1, a->y, b->z, m, ec->u, pool); |
| 758 | S1 = fxBigInt_mont_mul(the, S1, t1, Z2Z2, m, ec->u, pool); |
| 759 | t1 = fxBigInt_mont_mul(the, t1, b->y, a->z, m, ec->u, pool); |
| 760 | S2 = fxBigInt_mont_mul(the, S2, t1, Z1Z1, m, ec->u, pool); |
| 761 | |
| 762 | if (fxBigInt_ucomp(U1, U2) == 0) { |
| 763 | int eq = fxBigInt_ucomp(S1, S2) == 0; |
| 764 | pool_put(S2, m->size); |
| 765 | pool_put(S1, m->size); |
| 766 | pool_put(U2, m->size); |
| 767 | pool_put(U1, m->size); |
| 768 | pool_put(Z2Z2, m->size); |
| 769 | pool_put(Z1Z1, m->size); |
| 770 | pool_put(t2, m->size); |
| 771 | pool_put(t1, m->size); |
| 772 | if (eq) |
| 773 | ec_double(the, r, a, ec, pool); |
| 774 | else { |
| 775 | // zero? |
| 776 | fxBigInt_copy(r->z, &gxBigIntZero); |
| 777 | } |
| 778 | return; |
| 779 | } |
| 780 | |
| 781 | H = pool_get(the, m->size, pool); |
| 782 | I = pool_get(the, m->size, pool); |
no test coverage detected