diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-08-25 09:18:48 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-08-25 09:18:48 +0800 |
commit | bb3acae83faaeac370d4ce4cbf8aa939b7215085 (patch) | |
tree | 9d4bcc352d85089f28df51884038c875c48e7e1a | |
parent | 4c92ce33e37287dbc338b024a32db49799a65527 (diff) | |
download | tangerine-mcl-bb3acae83faaeac370d4ce4cbf8aa939b7215085.tar.gz tangerine-mcl-bb3acae83faaeac370d4ce4cbf8aa939b7215085.tar.zst tangerine-mcl-bb3acae83faaeac370d4ce4cbf8aa939b7215085.zip |
unifty fp2Dbl_mulPre functions
-rw-r--r-- | include/mcl/fp_tower.hpp | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/include/mcl/fp_tower.hpp b/include/mcl/fp_tower.hpp index fa36a52..3cd9ba0 100644 --- a/include/mcl/fp_tower.hpp +++ b/include/mcl/fp_tower.hpp @@ -709,9 +709,9 @@ struct Fp2DblT { mulPre = (void (*)(Fp2DblT&, const Fp2&, const Fp2&))op.fp2Dbl_mulPreA_; } else { if (op.isFullBit) { - mulPre = fp2Dbl_mulPreW; + mulPre = fp2Dbl_mulPreW<true>; } else { - mulPre = fp2Dbl_mulPreNoCarryW; + mulPre = fp2Dbl_mulPreW<false>; } } } @@ -719,6 +719,7 @@ struct Fp2DblT { Fp2Dbl::mulPre by FpDblT @note mod of NIST_P192 is fast */ + template<bool isFullBit> static void fp2Dbl_mulPreW(Fp2DblT& z, const Fp2& x, const Fp2& y) { const Fp& a = x.a; @@ -729,35 +730,23 @@ struct Fp2DblT { FpDbl& d1 = z.b; FpDbl d2; Fp s, t; - Fp::add(s, a, b); - Fp::add(t, c, d); - FpDbl::mulPre(d1, s, t); // (a + b)(c + d) - FpDbl::mulPre(d0, a, c); - FpDbl::mulPre(d2, b, d); - FpDbl::sub(d1, d1, d0); // (a + b)(c + d) - ac - FpDbl::sub(d1, d1, d2); // (a + b)(c + d) - ac - bd - FpDbl::sub(d0, d0, d2); // ac - bd - } - /* - Fp2Dbl::mulPre by FpDbl with No Carry - */ - static void fp2Dbl_mulPreNoCarryW(Fp2DblT& z, const Fp2& x, const Fp2& y) - { - const Fp& a = x.a; - const Fp& b = x.b; - const Fp& c = y.a; - const Fp& d = y.b; - FpDbl& d0 = z.a; - FpDbl& d1 = z.b; - FpDbl d2; - Fp s, t; - Fp::addPre(s, a, b); - Fp::addPre(t, c, d); + if (isFullBit) { + Fp::add(s, a, b); + Fp::add(t, c, d); + } else { + Fp::addPre(s, a, b); + Fp::addPre(t, c, d); + } FpDbl::mulPre(d1, s, t); // (a + b)(c + d) FpDbl::mulPre(d0, a, c); FpDbl::mulPre(d2, b, d); - FpDbl::subPre(d1, d1, d0); // (a + b)(c + d) - ac - FpDbl::subPre(d1, d1, d2); // (a + b)(c + d) - ac - bd + if (isFullBit) { + FpDbl::sub(d1, d1, d0); // (a + b)(c + d) - ac + FpDbl::sub(d1, d1, d2); // (a + b)(c + d) - ac - bd + } else { + FpDbl::subPre(d1, d1, d0); + FpDbl::subPre(d1, d1, d2); + } FpDbl::sub(d0, d0, d2); // ac - bd } }; |