Performance improvements in fp_mulmod, fp_submod and fp_submod to handle ALT_ECC_SIZE better. Revert fp_clear to fp_add_d, since it isn't required and slows it down.

This commit is contained in:
David Garske 2016-05-10 15:17:40 -07:00
parent 5703e5eadb
commit 7c5483ba0b
1 changed files with 12 additions and 4 deletions

View File

@ -989,9 +989,12 @@ int fp_mulmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d)
fp_init(&t); fp_init(&t);
fp_mul(a, b, &t); fp_mul(a, b, &t);
#ifdef ALT_ECC_SIZE
err = fp_mod(&t, c, &t); err = fp_mod(&t, c, &t);
fp_copy(&t, d); fp_copy(&t, d);
fp_clear(&t); #else
err = fp_mod(&t, c, d);
#endif
return err; return err;
} }
@ -1004,9 +1007,12 @@ int fp_submod(fp_int *a, fp_int *b, fp_int *c, fp_int *d)
fp_init(&t); fp_init(&t);
fp_sub(a, b, &t); fp_sub(a, b, &t);
#ifdef ALT_ECC_SIZE
err = fp_mod(&t, c, &t); err = fp_mod(&t, c, &t);
fp_copy(&t, d); fp_copy(&t, d);
fp_clear(&t); #else
err = fp_mod(&t, c, d);
#endif
return err; return err;
} }
@ -1019,9 +1025,12 @@ int fp_addmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d)
fp_init(&t); fp_init(&t);
fp_add(a, b, &t); fp_add(a, b, &t);
#ifdef ALT_ECC_SIZE
err = fp_mod(&t, c, &t); err = fp_mod(&t, c, &t);
fp_copy(&t, d); fp_copy(&t, d);
fp_clear(&t); #else
err = fp_mod(&t, c, d);
#endif
return err; return err;
} }
@ -2833,7 +2842,6 @@ void fp_add_d(fp_int *a, fp_digit b, fp_int *c)
fp_init(&tmp); fp_init(&tmp);
fp_set(&tmp, b); fp_set(&tmp, b);
fp_add(a, &tmp, c); fp_add(a, &tmp, c);
fp_clear(&tmp);
} }
/* external compatibility */ /* external compatibility */