diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-07-07 18:32:20 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-07-07 18:32:20 +0800 |
commit | 4a401bd204da47f71094a902ee230ac0902ac726 (patch) | |
tree | 7287cf3fc2dbf018df6a21e74f7d43fc4134bb49 | |
parent | c23d3804b3e363c8b98c0ccdecffe662be0d01b2 (diff) | |
download | dexon-mcl-4a401bd204da47f71094a902ee230ac0902ac726.tar.gz dexon-mcl-4a401bd204da47f71094a902ee230ac0902ac726.tar.zst dexon-mcl-4a401bd204da47f71094a902ee230ac0902ac726.zip |
move mclBn_* to mcl
-rw-r--r-- | include/mcl/bn.h | 20 | ||||
-rw-r--r-- | src/bn_c_impl.hpp | 50 |
2 files changed, 70 insertions, 0 deletions
diff --git a/include/mcl/bn.h b/include/mcl/bn.h index 082ac55..e07c32b 100644 --- a/include/mcl/bn.h +++ b/include/mcl/bn.h @@ -273,6 +273,26 @@ MCLBN_DLL_API void mclBn_precomputeG2(uint64_t *Qbuf, const mclBnG2 *Q); MCLBN_DLL_API void mclBn_precomputedMillerLoop(mclBnGT *f, const mclBnG1 *P, const uint64_t *Qbuf); MCLBN_DLL_API void mclBn_precomputedMillerLoop2(mclBnGT *f, const mclBnG1 *P1, const uint64_t *Q1buf, const mclBnG1 *P2, const uint64_t *Q2buf); +/* + Lagrange interpolation + recover out = y(0) by { (xVec[i], yVec[i]) } + return 0 if success else -1 + @note k >= 2, xVec[i] != 0, xVec[i] != xVec[j] for i != j +*/ +MCLBN_DLL_API int mclBn_FrLagrangeInterpolation(mclBnFr *out, const mclBnFr *xVec, const mclBnFr *yVec, size_t k); +MCLBN_DLL_API int mclBn_G1LagrangeInterpolation(mclBnG1 *out, const mclBnFr *xVec, const mclBnG1 *yVec, size_t k); +MCLBN_DLL_API int mclBn_G2LagrangeInterpolation(mclBnG2 *out, const mclBnFr *xVec, const mclBnG2 *yVec, size_t k); + +/* + evaluate polynomial + out = f(x) = c[0] + c[1] * x + c[2] * x^2 + ... + c[cSize - 1] * x^(cSize - 1) + @note cSize >= 2 +*/ +MCLBN_DLL_API int mclBn_FrEvaluatePolynomial(mclBnFr *out, const mclBnFr *cVec, size_t cSize, const mclBnFr *x); +MCLBN_DLL_API int mclBn_G1EvaluatePolynomial(mclBnG1 *out, const mclBnG1 *cVec, size_t cSize, const mclBnFr *x); +MCLBN_DLL_API int mclBn_G2EvaluatePolynomial(mclBnG2 *out, const mclBnG2 *cVec, size_t cSize, const mclBnFr *x); + + #ifdef __cplusplus } #endif diff --git a/src/bn_c_impl.hpp b/src/bn_c_impl.hpp index 4a07db5..84f1900 100644 --- a/src/bn_c_impl.hpp +++ b/src/bn_c_impl.hpp @@ -15,6 +15,7 @@ using namespace mcl::bn256; #include <mcl/bn384.hpp> using namespace mcl::bn384; #endif +#include <mcl/lagrange.hpp> static FILE *g_fp = NULL; @@ -526,3 +527,52 @@ void mclBn_precomputedMillerLoop2(mclBnGT *f, const mclBnG1 *P1, const uint64_t { BN::precomputedMillerLoop2(*cast(f), *cast(P1), cast(Q1buf), *cast(P2), cast(Q2buf)); } + +int mclBn_FrLagrangeInterpolation(mclBnFr *out, const mclBnFr *xVec, const mclBnFr *yVec, size_t k) + try +{ + mcl::LagrangeInterpolation(*cast(out), cast(xVec), cast(yVec), k); + return 0; +} catch (std::exception& e) { + return -1; +} +int mclBn_G1LagrangeInterpolation(mclBnG1 *out, const mclBnFr *xVec, const mclBnG1 *yVec, size_t k) + try +{ + mcl::LagrangeInterpolation(*cast(out), cast(xVec), cast(yVec), k); + return 0; +} catch (std::exception& e) { + return -1; +} +int mclBn_G2LagrangeInterpolation(mclBnG2 *out, const mclBnFr *xVec, const mclBnG2 *yVec, size_t k) + try +{ + mcl::LagrangeInterpolation(*cast(out), cast(xVec), cast(yVec), k); + return 0; +} catch (std::exception& e) { + return -1; +} +int mclBn_FrEvaluatePolynomial(mclBnFr *out, const mclBnFr *cVec, size_t cSize, const mclBnFr *x) + try +{ + mcl::evaluatePolynomial(*cast(out), cast(cVec), cSize, *cast(x)); + return 0; +} catch (std::exception& e) { + return -1; +} +int mclBn_G1EvaluatePolynomial(mclBnG1 *out, const mclBnG1 *cVec, size_t cSize, const mclBnFr *x) + try +{ + mcl::evaluatePolynomial(*cast(out), cast(cVec), cSize, *cast(x)); + return 0; +} catch (std::exception& e) { + return -1; +} +int mclBn_G2EvaluatePolynomial(mclBnG2 *out, const mclBnG2 *cVec, size_t cSize, const mclBnFr *x) + try +{ + mcl::evaluatePolynomial(*cast(out), cast(cVec), cSize, *cast(x)); + return 0; +} catch (std::exception& e) { + return -1; +} |