From 0de2e4c1a1fa6fa93253b06378f48a6f9922ad49 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Thu, 1 Jun 2017 05:45:06 +0900 Subject: rename BN_ to MCLBN_ --- Makefile | 4 +- include/mcl/bn.h | 202 ++++++++++++++-------------- sample/pairing_c.c | 2 +- src/bn_c.cpp | 230 ++++++++++++++++---------------- test/bn_c256_test.cpp | 4 +- test/bn_c384_test.cpp | 4 +- test/bn_c_test.hpp | 354 +++++++++++++++++++++++++------------------------- 7 files changed, 400 insertions(+), 400 deletions(-) diff --git a/Makefile b/Makefile index 87d5645..6979145 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ $(BN256_SLIB): $(LIB_OBJ) $(BN256_OBJ) $(PRE)$(CXX) -o $@ $(LIB_OBJ) $(BN256_OBJ) -shared $(BN256_OBJ): src/bn_c.cpp - $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -DBN_MAX_OP_UNIT_SIZE=4 + $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -DMCLBN_MAX_OP_UNIT_SIZE=4 $(BN384_LIB): $(LIB_OBJ) $(BN384_OBJ) $(AR) $@ $(LIB_OBJ) $(BN384_OBJ) @@ -106,7 +106,7 @@ $(BN384_SLIB): $(LIB_OBJ) $(BN384_OBJ) $(PRE)$(CXX) -o $@ $(LIB_OBJ) $(BN384_OBJ) -shared $(BN384_OBJ): src/bn_c.cpp - $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -DBN_MAX_OP_UNIT_SIZE=6 + $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -DMCLBN_MAX_OP_UNIT_SIZE=6 $(ASM_OBJ): $(ASM_SRC) $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) diff --git a/include/mcl/bn.h b/include/mcl/bn.h index b03e5f7..09c0595 100644 --- a/include/mcl/bn.h +++ b/include/mcl/bn.h @@ -6,20 +6,20 @@ @license modified new BSD license http://opensource.org/licenses/BSD-3-Clause */ -#ifndef BN_MAX_OP_UNIT_SIZE - #error "define BN_MAX_OP_UNIT_SIZE 4(or 6)" +#ifndef MCLBN_MAX_OP_UNIT_SIZE + #error "define MCLBN_MAX_OP_UNIT_SIZE 4(or 6)" #endif #include // for uint64_t, uint8_t #include // for size_t #ifdef _MSC_VER -#ifdef BN_DLL_EXPORT -#define BN_DLL_API __declspec(dllexport) +#ifdef MCLBN_DLL_EXPORT +#define MCLBN_DLL_API __declspec(dllexport) #else -#define BN_DLL_API __declspec(dllimport) +#define MCLBN_DLL_API __declspec(dllimport) #ifndef MCL_NO_AUTOLINK - #if BN_MAX_OP_UNIT_SIZE == 4 + #if MCLBN_MAX_OP_UNIT_SIZE == 4 #pragma comment(lib, "bn_if256.lib") #else #pragma comment(lib, "bn_if384.lib") @@ -27,37 +27,37 @@ #endif #endif #else -#define BN_DLL_API +#define MCLBN_DLL_API #endif #ifdef __cplusplus extern "C" { #endif -#ifdef BN_DEFINE_STRUCT +#ifdef MCLBN_DEFINE_STRUCT typedef struct { - uint64_t d[BN_MAX_OP_UNIT_SIZE]; -} BN_Fr; + uint64_t d[MCLBN_MAX_OP_UNIT_SIZE]; +} MCLBN_Fr; typedef struct { - uint64_t d[BN_MAX_OP_UNIT_SIZE * 3]; -} BN_G1; + uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 3]; +} MCLBN_G1; typedef struct { - uint64_t d[BN_MAX_OP_UNIT_SIZE * 2 * 3]; -} BN_G2; + uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 2 * 3]; +} MCLBN_G2; typedef struct { - uint64_t d[BN_MAX_OP_UNIT_SIZE * 12]; -} BN_GT; + uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 12]; +} MCLBN_GT; #else -typedef struct BN_Fr BN_Fr; -typedef struct BN_G1 BN_G1; -typedef struct BN_G2 BN_G2; -typedef struct BN_GT BN_GT; +typedef struct MCLBN_Fr MCLBN_Fr; +typedef struct MCLBN_G1 MCLBN_G1; +typedef struct MCLBN_G2 MCLBN_G2; +typedef struct MCLBN_GT MCLBN_GT; #endif @@ -68,155 +68,155 @@ typedef struct BN_GT BN_GT; return 0 if success @note not threadsafe */ -BN_DLL_API int BN_setErrFile(const char *name); +MCLBN_DLL_API int MCLBN_setErrFile(const char *name); enum { - BN_curveFp254BNb = 0, - BN_curveFp382_1 = 1, - BN_curveFp382_2 = 2 + MCLBN_curveFp254BNb = 0, + MCLBN_curveFp382_1 = 1, + MCLBN_curveFp382_2 = 2 }; /* init library @param curve [in] type of bn curve @param maxUnitSize [in] 4 or 6 - curve = BN_CurveFp254BNb is allowed if maxUnitSize = 4 - curve = BN_CurveFp254BNb/BN_CurveFp382_1/BN_CurveFp382_2 are allowed if maxUnitSize = 6 + curve = MCLBN_CurveFp254BNb is allowed if maxUnitSize = 4 + curve = MCLBN_CurveFp254BNb/MCLBN_CurveFp382_1/MCLBN_CurveFp382_2 are allowed if maxUnitSize = 6 @note not threadsafe - @note BN_init is used in libeay32 + @note MCLBN_init is used in libeay32 */ -BN_DLL_API int BN_initLib(int curve, int maxUnitSize); +MCLBN_DLL_API int MCLBN_initLib(int curve, int maxUnitSize); //////////////////////////////////////////////// // set zero -BN_DLL_API void BN_Fr_clear(BN_Fr *x); +MCLBN_DLL_API void MCLBN_Fr_clear(MCLBN_Fr *x); // set x to y -BN_DLL_API void BN_Fr_setInt(BN_Fr *y, int x); +MCLBN_DLL_API void MCLBN_Fr_setInt(MCLBN_Fr *y, int x); // return 0 if success -BN_DLL_API int BN_Fr_setDecStr(BN_Fr *x, const char *buf, size_t bufSize); -BN_DLL_API int BN_Fr_setHexStr(BN_Fr *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_Fr_setDecStr(MCLBN_Fr *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_Fr_setHexStr(MCLBN_Fr *x, const char *buf, size_t bufSize); // mask buf with (1 << (bitLen(r) - 1)) - 1 if buf >= r -BN_DLL_API int BN_Fr_setLittleEndian(BN_Fr *x, const void *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_Fr_setLittleEndian(MCLBN_Fr *x, const void *buf, size_t bufSize); // return 1 if true and 0 otherwise -BN_DLL_API int BN_Fr_isValid(const BN_Fr *x); -BN_DLL_API int BN_Fr_isEqual(const BN_Fr *x, const BN_Fr *y); -BN_DLL_API int BN_Fr_isZero(const BN_Fr *x); -BN_DLL_API int BN_Fr_isOne(const BN_Fr *x); +MCLBN_DLL_API int MCLBN_Fr_isValid(const MCLBN_Fr *x); +MCLBN_DLL_API int MCLBN_Fr_isEqual(const MCLBN_Fr *x, const MCLBN_Fr *y); +MCLBN_DLL_API int MCLBN_Fr_isZero(const MCLBN_Fr *x); +MCLBN_DLL_API int MCLBN_Fr_isOne(const MCLBN_Fr *x); -BN_DLL_API void BN_Fr_setByCSPRNG(BN_Fr *x); +MCLBN_DLL_API void MCLBN_Fr_setByCSPRNG(MCLBN_Fr *x); // hash(s) and set x -BN_DLL_API void BN_hashToFr(BN_Fr *x, const void *buf, size_t bufSize); +MCLBN_DLL_API void MCLBN_hashToFr(MCLBN_Fr *x, const void *buf, size_t bufSize); // return strlen(buf) if sucess else 0 -BN_DLL_API size_t BN_Fr_getDecStr(char *buf, size_t maxBufSize, const BN_Fr *x); -BN_DLL_API size_t BN_Fr_getHexStr(char *buf, size_t maxBufSize, const BN_Fr *x); +MCLBN_DLL_API size_t MCLBN_Fr_getDecStr(char *buf, size_t maxBufSize, const MCLBN_Fr *x); +MCLBN_DLL_API size_t MCLBN_Fr_getHexStr(char *buf, size_t maxBufSize, const MCLBN_Fr *x); // return written byte if sucess else 0 -BN_DLL_API size_t BN_Fr_getLittleEndian(void *buf, size_t bufSize, const BN_Fr *x); +MCLBN_DLL_API size_t MCLBN_Fr_getLittleEndian(void *buf, size_t bufSize, const MCLBN_Fr *x); -BN_DLL_API void BN_Fr_neg(BN_Fr *y, const BN_Fr *x); -BN_DLL_API void BN_Fr_inv(BN_Fr *y, const BN_Fr *x); -BN_DLL_API void BN_Fr_add(BN_Fr *z, const BN_Fr *x, const BN_Fr *y); -BN_DLL_API void BN_Fr_sub(BN_Fr *z, const BN_Fr *x, const BN_Fr *y); -BN_DLL_API void BN_Fr_mul(BN_Fr *z, const BN_Fr *x, const BN_Fr *y); -BN_DLL_API void BN_Fr_div(BN_Fr *z, const BN_Fr *x, const BN_Fr *y); +MCLBN_DLL_API void MCLBN_Fr_neg(MCLBN_Fr *y, const MCLBN_Fr *x); +MCLBN_DLL_API void MCLBN_Fr_inv(MCLBN_Fr *y, const MCLBN_Fr *x); +MCLBN_DLL_API void MCLBN_Fr_add(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y); +MCLBN_DLL_API void MCLBN_Fr_sub(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y); +MCLBN_DLL_API void MCLBN_Fr_mul(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y); +MCLBN_DLL_API void MCLBN_Fr_div(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y); //////////////////////////////////////////////// // set zero -BN_DLL_API void BN_G1_clear(BN_G1 *x); +MCLBN_DLL_API void MCLBN_G1_clear(MCLBN_G1 *x); // return 0 if success -BN_DLL_API int BN_G1_setHexStr(BN_G1 *x, const char *buf, size_t bufSize); -BN_DLL_API int BN_G1_deserialize(BN_G1 *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_G1_setHexStr(MCLBN_G1 *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_G1_deserialize(MCLBN_G1 *x, const char *buf, size_t bufSize); // return 1 if true and 0 otherwise -BN_DLL_API int BN_G1_isValid(const BN_G1 *x); -BN_DLL_API int BN_G1_isEqual(const BN_G1 *x, const BN_G1 *y); -BN_DLL_API int BN_G1_isZero(const BN_G1 *x); +MCLBN_DLL_API int MCLBN_G1_isValid(const MCLBN_G1 *x); +MCLBN_DLL_API int MCLBN_G1_isEqual(const MCLBN_G1 *x, const MCLBN_G1 *y); +MCLBN_DLL_API int MCLBN_G1_isZero(const MCLBN_G1 *x); -BN_DLL_API int BN_hashAndMapToG1(BN_G1 *x, const void *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_hashAndMapToG1(MCLBN_G1 *x, const void *buf, size_t bufSize); // return 0 if success -BN_DLL_API size_t BN_G1_getHexStr(char *buf, size_t maxBufSize, const BN_G1 *x); +MCLBN_DLL_API size_t MCLBN_G1_getHexStr(char *buf, size_t maxBufSize, const MCLBN_G1 *x); // return written size if sucess else 0 -BN_DLL_API size_t BN_G1_serialize(void *buf, size_t maxBufSize, const BN_G1 *x); +MCLBN_DLL_API size_t MCLBN_G1_serialize(void *buf, size_t maxBufSize, const MCLBN_G1 *x); -BN_DLL_API void BN_G1_neg(BN_G1 *y, const BN_G1 *x); -BN_DLL_API void BN_G1_dbl(BN_G1 *y, const BN_G1 *x); -BN_DLL_API void BN_G1_add(BN_G1 *z, const BN_G1 *x, const BN_G1 *y); -BN_DLL_API void BN_G1_sub(BN_G1 *z, const BN_G1 *x, const BN_G1 *y); -BN_DLL_API void BN_G1_mul(BN_G1 *z, const BN_G1 *x, const BN_Fr *y); +MCLBN_DLL_API void MCLBN_G1_neg(MCLBN_G1 *y, const MCLBN_G1 *x); +MCLBN_DLL_API void MCLBN_G1_dbl(MCLBN_G1 *y, const MCLBN_G1 *x); +MCLBN_DLL_API void MCLBN_G1_add(MCLBN_G1 *z, const MCLBN_G1 *x, const MCLBN_G1 *y); +MCLBN_DLL_API void MCLBN_G1_sub(MCLBN_G1 *z, const MCLBN_G1 *x, const MCLBN_G1 *y); +MCLBN_DLL_API void MCLBN_G1_mul(MCLBN_G1 *z, const MCLBN_G1 *x, const MCLBN_Fr *y); //////////////////////////////////////////////// // set zero -BN_DLL_API void BN_G2_clear(BN_G2 *x); +MCLBN_DLL_API void MCLBN_G2_clear(MCLBN_G2 *x); // return 0 if success -BN_DLL_API int BN_G2_setHexStr(BN_G2 *x, const char *buf, size_t bufSize); -BN_DLL_API int BN_G2_deserialize(BN_G2 *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_G2_setHexStr(MCLBN_G2 *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_G2_deserialize(MCLBN_G2 *x, const char *buf, size_t bufSize); // return 1 if true and 0 otherwise -BN_DLL_API int BN_G2_isValid(const BN_G2 *x); -BN_DLL_API int BN_G2_isEqual(const BN_G2 *x, const BN_G2 *y); -BN_DLL_API int BN_G2_isZero(const BN_G2 *x); +MCLBN_DLL_API int MCLBN_G2_isValid(const MCLBN_G2 *x); +MCLBN_DLL_API int MCLBN_G2_isEqual(const MCLBN_G2 *x, const MCLBN_G2 *y); +MCLBN_DLL_API int MCLBN_G2_isZero(const MCLBN_G2 *x); -BN_DLL_API int BN_hashAndMapToG2(BN_G2 *x, const void *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_hashAndMapToG2(MCLBN_G2 *x, const void *buf, size_t bufSize); // return 0 if success -BN_DLL_API size_t BN_G2_getHexStr(char *buf, size_t maxBufSize, const BN_G2 *x); +MCLBN_DLL_API size_t MCLBN_G2_getHexStr(char *buf, size_t maxBufSize, const MCLBN_G2 *x); // return written size if sucess else 0 -BN_DLL_API size_t BN_G2_serialize(void *buf, size_t maxBufSize, const BN_G2 *x); +MCLBN_DLL_API size_t MCLBN_G2_serialize(void *buf, size_t maxBufSize, const MCLBN_G2 *x); -BN_DLL_API void BN_G2_neg(BN_G2 *y, const BN_G2 *x); -BN_DLL_API void BN_G2_dbl(BN_G2 *y, const BN_G2 *x); -BN_DLL_API void BN_G2_add(BN_G2 *z, const BN_G2 *x, const BN_G2 *y); -BN_DLL_API void BN_G2_sub(BN_G2 *z, const BN_G2 *x, const BN_G2 *y); -BN_DLL_API void BN_G2_mul(BN_G2 *z, const BN_G2 *x, const BN_Fr *y); +MCLBN_DLL_API void MCLBN_G2_neg(MCLBN_G2 *y, const MCLBN_G2 *x); +MCLBN_DLL_API void MCLBN_G2_dbl(MCLBN_G2 *y, const MCLBN_G2 *x); +MCLBN_DLL_API void MCLBN_G2_add(MCLBN_G2 *z, const MCLBN_G2 *x, const MCLBN_G2 *y); +MCLBN_DLL_API void MCLBN_G2_sub(MCLBN_G2 *z, const MCLBN_G2 *x, const MCLBN_G2 *y); +MCLBN_DLL_API void MCLBN_G2_mul(MCLBN_G2 *z, const MCLBN_G2 *x, const MCLBN_Fr *y); //////////////////////////////////////////////// // set zero -BN_DLL_API void BN_GT_clear(BN_GT *x); +MCLBN_DLL_API void MCLBN_GT_clear(MCLBN_GT *x); // return 0 if success -BN_DLL_API int BN_GT_setDecStr(BN_GT *x, const char *buf, size_t bufSize); -BN_DLL_API int BN_GT_setHexStr(BN_GT *x, const char *buf, size_t bufSize); -BN_DLL_API int BN_GT_deserialize(BN_GT *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_GT_setDecStr(MCLBN_GT *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_GT_setHexStr(MCLBN_GT *x, const char *buf, size_t bufSize); +MCLBN_DLL_API int MCLBN_GT_deserialize(MCLBN_GT *x, const char *buf, size_t bufSize); // return 1 if true and 0 otherwise -BN_DLL_API int BN_GT_isEqual(const BN_GT *x, const BN_GT *y); -BN_DLL_API int BN_GT_isZero(const BN_GT *x); -BN_DLL_API int BN_GT_isOne(const BN_GT *x); +MCLBN_DLL_API int MCLBN_GT_isEqual(const MCLBN_GT *x, const MCLBN_GT *y); +MCLBN_DLL_API int MCLBN_GT_isZero(const MCLBN_GT *x); +MCLBN_DLL_API int MCLBN_GT_isOne(const MCLBN_GT *x); // return 0 if success -BN_DLL_API size_t BN_GT_getDecStr(char *buf, size_t maxBufSize, const BN_GT *x); -BN_DLL_API size_t BN_GT_getHexStr(char *buf, size_t maxBufSize, const BN_GT *x); +MCLBN_DLL_API size_t MCLBN_GT_getDecStr(char *buf, size_t maxBufSize, const MCLBN_GT *x); +MCLBN_DLL_API size_t MCLBN_GT_getHexStr(char *buf, size_t maxBufSize, const MCLBN_GT *x); // return written size if sucess else 0 -BN_DLL_API size_t BN_GT_serialize(void *buf, size_t maxBufSize, const BN_GT *x); +MCLBN_DLL_API size_t MCLBN_GT_serialize(void *buf, size_t maxBufSize, const MCLBN_GT *x); -BN_DLL_API void BN_GT_neg(BN_GT *y, const BN_GT *x); -BN_DLL_API void BN_GT_inv(BN_GT *y, const BN_GT *x); -BN_DLL_API void BN_GT_add(BN_GT *z, const BN_GT *x, const BN_GT *y); -BN_DLL_API void BN_GT_sub(BN_GT *z, const BN_GT *x, const BN_GT *y); -BN_DLL_API void BN_GT_mul(BN_GT *z, const BN_GT *x, const BN_GT *y); -BN_DLL_API void BN_GT_div(BN_GT *z, const BN_GT *x, const BN_GT *y); +MCLBN_DLL_API void MCLBN_GT_neg(MCLBN_GT *y, const MCLBN_GT *x); +MCLBN_DLL_API void MCLBN_GT_inv(MCLBN_GT *y, const MCLBN_GT *x); +MCLBN_DLL_API void MCLBN_GT_add(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y); +MCLBN_DLL_API void MCLBN_GT_sub(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y); +MCLBN_DLL_API void MCLBN_GT_mul(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y); +MCLBN_DLL_API void MCLBN_GT_div(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y); -BN_DLL_API void BN_GT_pow(BN_GT *z, const BN_GT *x, const BN_Fr *y); +MCLBN_DLL_API void MCLBN_GT_pow(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_Fr *y); -BN_DLL_API void BN_pairing(BN_GT *z, const BN_G1 *x, const BN_G2 *y); -BN_DLL_API void BN_finalExp(BN_GT *y, const BN_GT *x); -BN_DLL_API void BN_millerLoop(BN_GT *z, const BN_G1 *x, const BN_G2 *y); +MCLBN_DLL_API void MCLBN_pairing(MCLBN_GT *z, const MCLBN_G1 *x, const MCLBN_G2 *y); +MCLBN_DLL_API void MCLBN_finalExp(MCLBN_GT *y, const MCLBN_GT *x); +MCLBN_DLL_API void MCLBN_millerLoop(MCLBN_GT *z, const MCLBN_G1 *x, const MCLBN_G2 *y); // return precomputedQcoeffSize * sizeof(Fp6) / sizeof(uint64_t) -BN_DLL_API int BN_getUint64NumToPrecompute(void); +MCLBN_DLL_API int MCLBN_getUint64NumToPrecompute(void); -// allocate Qbuf[BN_getUint64NumToPrecompute()] before calling this -BN_DLL_API void BN_precomputeG2(uint64_t *Qbuf, const BN_G2 *Q); +// allocate Qbuf[MCLBN_getUint64NumToPrecompute()] before calling this +MCLBN_DLL_API void MCLBN_precomputeG2(uint64_t *Qbuf, const MCLBN_G2 *Q); -BN_DLL_API void BN_precomputedMillerLoop(BN_GT *f, const BN_G1 *P, const uint64_t *Qbuf); -BN_DLL_API void BN_precomputedMillerLoop2(BN_GT *f, const BN_G1 *P1, const uint64_t *Q1buf, const BN_G1 *P2, const uint64_t *Q2buf); +MCLBN_DLL_API void MCLBN_precomputedMillerLoop(MCLBN_GT *f, const MCLBN_G1 *P, const uint64_t *Qbuf); +MCLBN_DLL_API void MCLBN_precomputedMillerLoop2(MCLBN_GT *f, const MCLBN_G1 *P1, const uint64_t *Q1buf, const MCLBN_G1 *P2, const uint64_t *Q2buf); #ifdef __cplusplus } diff --git a/sample/pairing_c.c b/sample/pairing_c.c index 863b756..e37baf1 100644 --- a/sample/pairing_c.c +++ b/sample/pairing_c.c @@ -1,6 +1,6 @@ #define BN256_DEFINE_STRUCT #define BN_MAX_FP_UNIT_SIZE 4 -#include +#include #include int g_err = 0; diff --git a/src/bn_c.cpp b/src/bn_c.cpp index 92d510c..814f2f3 100644 --- a/src/bn_c.cpp +++ b/src/bn_c.cpp @@ -1,5 +1,5 @@ -#define BN_DLL_EXPORT -#define BN_DEFINE_STRUCT +#define MCLBN_DLL_EXPORT +#define MCLBN_DEFINE_STRUCT #include #if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 #include @@ -9,7 +9,7 @@ static std::random_device g_rg; static cybozu::RandomGenerator g_rg; #endif -#if BN_MAX_OP_UNIT_SIZE == 4 +#if MCLBN_MAX_OP_UNIT_SIZE == 4 #include using namespace mcl::bn256; #else @@ -19,17 +19,17 @@ using namespace mcl::bn384; static FILE *g_fp = NULL; -static Fr *cast(BN_Fr *p) { return reinterpret_cast(p); } -static const Fr *cast(const BN_Fr *p) { return reinterpret_cast(p); } +static Fr *cast(MCLBN_Fr *p) { return reinterpret_cast(p); } +static const Fr *cast(const MCLBN_Fr *p) { return reinterpret_cast(p); } -static G1 *cast(BN_G1 *p) { return reinterpret_cast(p); } -static const G1 *cast(const BN_G1 *p) { return reinterpret_cast(p); } +static G1 *cast(MCLBN_G1 *p) { return reinterpret_cast(p); } +static const G1 *cast(const MCLBN_G1 *p) { return reinterpret_cast(p); } -static G2 *cast(BN_G2 *p) { return reinterpret_cast(p); } -static const G2 *cast(const BN_G2 *p) { return reinterpret_cast(p); } +static G2 *cast(MCLBN_G2 *p) { return reinterpret_cast(p); } +static const G2 *cast(const MCLBN_G2 *p) { return reinterpret_cast(p); } -static Fp12 *cast(BN_GT *p) { return reinterpret_cast(p); } -static const Fp12 *cast(const BN_GT *p) { return reinterpret_cast(p); } +static Fp12 *cast(MCLBN_GT *p) { return reinterpret_cast(p); } +static const Fp12 *cast(const MCLBN_GT *p) { return reinterpret_cast(p); } static Fp6 *cast(uint64_t *p) { return reinterpret_cast(p); } static const Fp6 *cast(const uint64_t *p) { return reinterpret_cast(p); } @@ -85,7 +85,7 @@ int deserialize(T *x, const void *buf, size_t bufSize, int ioMode, const char *m return -1; } -int BN_setErrFile(const char *name) +int MCLBN_setErrFile(const char *name) { int ret = closeErrFile(); if (name == NULL || *name == '\0') { @@ -104,31 +104,31 @@ int BN_setErrFile(const char *name) #endif } -int BN_initLib(int curve, int maxUnitSize) +int MCLBN_initLib(int curve, int maxUnitSize) try { - if (maxUnitSize != BN_MAX_OP_UNIT_SIZE) { - if (g_fp) fprintf(g_fp, "BN_initLib:maxUnitSize is mismatch %d %d\n", maxUnitSize, BN_MAX_OP_UNIT_SIZE); + if (maxUnitSize != MCLBN_MAX_OP_UNIT_SIZE) { + if (g_fp) fprintf(g_fp, "MCLBN_initLib:maxUnitSize is mismatch %d %d\n", maxUnitSize, MCLBN_MAX_OP_UNIT_SIZE); return -1; } mcl::bn::CurveParam cp; switch (curve) { - case BN_curveFp254BNb: + case MCLBN_curveFp254BNb: cp = mcl::bn::CurveFp254BNb; break; -#if BN_MAX_OP_UNIT_SIZE == 6 - case BN_curveFp382_1: +#if MCLBN_MAX_OP_UNIT_SIZE == 6 + case MCLBN_curveFp382_1: cp = mcl::bn::CurveFp382_1; break; - case BN_curveFp382_2: + case MCLBN_curveFp382_2: cp = mcl::bn::CurveFp382_2; break; #endif default: - if (g_fp) fprintf(g_fp, "BN_initLib:not supported curve %d\n", curve); + if (g_fp) fprintf(g_fp, "MCLBN_initLib:not supported curve %d\n", curve); return -1; } -#if BN_MAX_OP_UNIT_SIZE == 4 +#if MCLBN_MAX_OP_UNIT_SIZE == 4 bn256init(cp); #else bn384init(cp); @@ -141,132 +141,132 @@ int BN_initLib(int curve, int maxUnitSize) //////////////////////////////////////////////// // set zero -void BN_Fr_clear(BN_Fr *x) +void MCLBN_Fr_clear(MCLBN_Fr *x) { cast(x)->clear(); } // set x to y -void BN_Fr_setInt(BN_Fr *y, int x) +void MCLBN_Fr_setInt(MCLBN_Fr *y, int x) { *cast(y) = x; } -int BN_Fr_setDecStr(BN_Fr *x, const char *buf, size_t bufSize) +int MCLBN_Fr_setDecStr(MCLBN_Fr *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, 10, "BN_Fr_setDecStr", false); + return deserialize(x, buf, bufSize, 10, "MCLBN_Fr_setDecStr", false); } -int BN_Fr_setHexStr(BN_Fr *x, const char *buf, size_t bufSize) +int MCLBN_Fr_setHexStr(MCLBN_Fr *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, 16, "BN_Fr_setHexStr", false); + return deserialize(x, buf, bufSize, 16, "MCLBN_Fr_setHexStr", false); } -int BN_Fr_setLittleEndian(BN_Fr *x, const void *buf, size_t bufSize) +int MCLBN_Fr_setLittleEndian(MCLBN_Fr *x, const void *buf, size_t bufSize) { const size_t byteSize = cast(x)->getByteSize(); if (bufSize > byteSize) bufSize = byteSize; std::string s((const char *)buf, bufSize); s.resize(byteSize); - return deserialize(x, s.c_str(), s.size(), mcl::IoFixedSizeByteSeq, "BN_Fr_setLittleEndian", false); + return deserialize(x, s.c_str(), s.size(), mcl::IoFixedSizeByteSeq, "MCLBN_Fr_setLittleEndian", false); } // return 1 if true -int BN_Fr_isValid(const BN_Fr *x) +int MCLBN_Fr_isValid(const MCLBN_Fr *x) { return cast(x)->isValid(); } -int BN_Fr_isEqual(const BN_Fr *x, const BN_Fr *y) +int MCLBN_Fr_isEqual(const MCLBN_Fr *x, const MCLBN_Fr *y) { return *cast(x) == *cast(y); } -int BN_Fr_isZero(const BN_Fr *x) +int MCLBN_Fr_isZero(const MCLBN_Fr *x) { return cast(x)->isZero(); } -int BN_Fr_isOne(const BN_Fr *x) +int MCLBN_Fr_isOne(const MCLBN_Fr *x) { return cast(x)->isOne(); } -void BN_Fr_setByCSPRNG(BN_Fr *x) +void MCLBN_Fr_setByCSPRNG(MCLBN_Fr *x) { cast(x)->setRand(g_rg); } // hash(buf) and set x -void BN_hashToFr(BN_Fr *x, const void *buf, size_t bufSize) +void MCLBN_hashToFr(MCLBN_Fr *x, const void *buf, size_t bufSize) { cast(x)->setHashOf(buf, bufSize); } -size_t BN_Fr_getDecStr(char *buf, size_t maxBufSize, const BN_Fr *x) +size_t MCLBN_Fr_getDecStr(char *buf, size_t maxBufSize, const MCLBN_Fr *x) { - return serialize(buf, maxBufSize, x, 10, "BN_Fr_getDecStr", false); + return serialize(buf, maxBufSize, x, 10, "MCLBN_Fr_getDecStr", false); } -size_t BN_Fr_getHexStr(char *buf, size_t maxBufSize, const BN_Fr *x) +size_t MCLBN_Fr_getHexStr(char *buf, size_t maxBufSize, const MCLBN_Fr *x) { - return serialize(buf, maxBufSize, x, 16, "BN_Fr_getHexStr", false); + return serialize(buf, maxBufSize, x, 16, "MCLBN_Fr_getHexStr", false); } -size_t BN_Fr_getLittleEndian(void *buf, size_t maxBufSize, const BN_Fr *x) +size_t MCLBN_Fr_getLittleEndian(void *buf, size_t maxBufSize, const MCLBN_Fr *x) { - return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "BN_Fr_getLittleEndian", false); + return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "MCLBN_Fr_getLittleEndian", false); } -void BN_Fr_neg(BN_Fr *y, const BN_Fr *x) +void MCLBN_Fr_neg(MCLBN_Fr *y, const MCLBN_Fr *x) { Fr::neg(*cast(y), *cast(x)); } -void BN_Fr_inv(BN_Fr *y, const BN_Fr *x) +void MCLBN_Fr_inv(MCLBN_Fr *y, const MCLBN_Fr *x) { Fr::inv(*cast(y), *cast(x)); } -void BN_Fr_add(BN_Fr *z, const BN_Fr *x, const BN_Fr *y) +void MCLBN_Fr_add(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y) { Fr::add(*cast(z),*cast(x), *cast(y)); } -void BN_Fr_sub(BN_Fr *z, const BN_Fr *x, const BN_Fr *y) +void MCLBN_Fr_sub(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y) { Fr::sub(*cast(z),*cast(x), *cast(y)); } -void BN_Fr_mul(BN_Fr *z, const BN_Fr *x, const BN_Fr *y) +void MCLBN_Fr_mul(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y) { Fr::mul(*cast(z),*cast(x), *cast(y)); } -void BN_Fr_div(BN_Fr *z, const BN_Fr *x, const BN_Fr *y) +void MCLBN_Fr_div(MCLBN_Fr *z, const MCLBN_Fr *x, const MCLBN_Fr *y) { Fr::div(*cast(z),*cast(x), *cast(y)); } //////////////////////////////////////////////// // set zero -void BN_G1_clear(BN_G1 *x) +void MCLBN_G1_clear(MCLBN_G1 *x) { cast(x)->clear(); } -int BN_G1_setHexStr(BN_G1 *x, const char *buf, size_t bufSize) +int MCLBN_G1_setHexStr(MCLBN_G1 *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "BN_G1_setHexStr", true); + return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "MCLBN_G1_setHexStr", true); } -int BN_G1_deserialize(BN_G1 *x, const char *buf, size_t bufSize) +int MCLBN_G1_deserialize(MCLBN_G1 *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "BN_G1_setHexStr", false); + return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "MCLBN_G1_setHexStr", false); } // return 1 if true -int BN_G1_isValid(const BN_G1 *x) +int MCLBN_G1_isValid(const MCLBN_G1 *x) { return cast(x)->isValid(); } -int BN_G1_isEqual(const BN_G1 *x, const BN_G1 *y) +int MCLBN_G1_isEqual(const MCLBN_G1 *x, const MCLBN_G1 *y) { return *cast(x) == *cast(y); } -int BN_G1_isZero(const BN_G1 *x) +int MCLBN_G1_isZero(const MCLBN_G1 *x) { return cast(x)->isZero(); } -int BN_hashAndMapToG1(BN_G1 *x, const void *buf, size_t bufSize) +int MCLBN_hashAndMapToG1(MCLBN_G1 *x, const void *buf, size_t bufSize) try { Fp y; @@ -274,72 +274,72 @@ int BN_hashAndMapToG1(BN_G1 *x, const void *buf, size_t bufSize) BN::mapToG1(*cast(x), y); return 0; } catch (std::exception& e) { - if (g_fp) fprintf(g_fp, "BN_hashAndMapToG1 %s\n", e.what()); + if (g_fp) fprintf(g_fp, "MCLBN_hashAndMapToG1 %s\n", e.what()); return 1; } -size_t BN_G1_getHexStr(char *buf, size_t maxBufSize, const BN_G1 *x) +size_t MCLBN_G1_getHexStr(char *buf, size_t maxBufSize, const MCLBN_G1 *x) { - return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "BN_G1_getHexStr", true); + return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "MCLBN_G1_getHexStr", true); } -size_t BN_G1_serialize(void *buf, size_t maxBufSize, const BN_G1 *x) +size_t MCLBN_G1_serialize(void *buf, size_t maxBufSize, const MCLBN_G1 *x) { - return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "BN_G1_serialize", false); + return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "MCLBN_G1_serialize", false); } -void BN_G1_neg(BN_G1 *y, const BN_G1 *x) +void MCLBN_G1_neg(MCLBN_G1 *y, const MCLBN_G1 *x) { G1::neg(*cast(y), *cast(x)); } -void BN_G1_dbl(BN_G1 *y, const BN_G1 *x) +void MCLBN_G1_dbl(MCLBN_G1 *y, const MCLBN_G1 *x) { G1::dbl(*cast(y), *cast(x)); } -void BN_G1_add(BN_G1 *z, const BN_G1 *x, const BN_G1 *y) +void MCLBN_G1_add(MCLBN_G1 *z, const MCLBN_G1 *x, const MCLBN_G1 *y) { G1::add(*cast(z),*cast(x), *cast(y)); } -void BN_G1_sub(BN_G1 *z, const BN_G1 *x, const BN_G1 *y) +void MCLBN_G1_sub(MCLBN_G1 *z, const MCLBN_G1 *x, const MCLBN_G1 *y) { G1::sub(*cast(z),*cast(x), *cast(y)); } -void BN_G1_mul(BN_G1 *z, const BN_G1 *x, const BN_Fr *y) +void MCLBN_G1_mul(MCLBN_G1 *z, const MCLBN_G1 *x, const MCLBN_Fr *y) { G1::mul(*cast(z),*cast(x), *cast(y)); } //////////////////////////////////////////////// // set zero -void BN_G2_clear(BN_G2 *x) +void MCLBN_G2_clear(MCLBN_G2 *x) { cast(x)->clear(); } -int BN_G2_setHexStr(BN_G2 *x, const char *buf, size_t bufSize) +int MCLBN_G2_setHexStr(MCLBN_G2 *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "BN_G2_setHexStr", true); + return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "MCLBN_G2_setHexStr", true); } -int BN_G2_deserialize(BN_G2 *x, const char *buf, size_t bufSize) +int MCLBN_G2_deserialize(MCLBN_G2 *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "BN_G2_setHexStr", false); + return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "MCLBN_G2_setHexStr", false); } // return 1 if true -int BN_G2_isValid(const BN_G2 *x) +int MCLBN_G2_isValid(const MCLBN_G2 *x) { return cast(x)->isValid(); } -int BN_G2_isEqual(const BN_G2 *x, const BN_G2 *y) +int MCLBN_G2_isEqual(const MCLBN_G2 *x, const MCLBN_G2 *y) { return *cast(x) == *cast(y); } -int BN_G2_isZero(const BN_G2 *x) +int MCLBN_G2_isZero(const MCLBN_G2 *x) { return cast(x)->isZero(); } -int BN_hashAndMapToG2(BN_G2 *x, const void *buf, size_t bufSize) +int MCLBN_hashAndMapToG2(MCLBN_G2 *x, const void *buf, size_t bufSize) try { Fp y; @@ -347,148 +347,148 @@ int BN_hashAndMapToG2(BN_G2 *x, const void *buf, size_t bufSize) BN::mapToG2(*cast(x), Fp2(y, 0)); return 0; } catch (std::exception& e) { - if (g_fp) fprintf(g_fp, "BN_hashAndMapToG2 %s\n", e.what()); + if (g_fp) fprintf(g_fp, "MCLBN_hashAndMapToG2 %s\n", e.what()); return 1; } -size_t BN_G2_getHexStr(char *buf, size_t maxBufSize, const BN_G2 *x) +size_t MCLBN_G2_getHexStr(char *buf, size_t maxBufSize, const MCLBN_G2 *x) { - return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "BN_G2_getHexStr", true); + return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "MCLBN_G2_getHexStr", true); } -size_t BN_G2_serialize(void *buf, size_t maxBufSize, const BN_G2 *x) +size_t MCLBN_G2_serialize(void *buf, size_t maxBufSize, const MCLBN_G2 *x) { - return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "BN_G2_serialize", false); + return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "MCLBN_G2_serialize", false); } -void BN_G2_neg(BN_G2 *y, const BN_G2 *x) +void MCLBN_G2_neg(MCLBN_G2 *y, const MCLBN_G2 *x) { G2::neg(*cast(y), *cast(x)); } -void BN_G2_dbl(BN_G2 *y, const BN_G2 *x) +void MCLBN_G2_dbl(MCLBN_G2 *y, const MCLBN_G2 *x) { G2::dbl(*cast(y), *cast(x)); } -void BN_G2_add(BN_G2 *z, const BN_G2 *x, const BN_G2 *y) +void MCLBN_G2_add(MCLBN_G2 *z, const MCLBN_G2 *x, const MCLBN_G2 *y) { G2::add(*cast(z),*cast(x), *cast(y)); } -void BN_G2_sub(BN_G2 *z, const BN_G2 *x, const BN_G2 *y) +void MCLBN_G2_sub(MCLBN_G2 *z, const MCLBN_G2 *x, const MCLBN_G2 *y) { G2::sub(*cast(z),*cast(x), *cast(y)); } -void BN_G2_mul(BN_G2 *z, const BN_G2 *x, const BN_Fr *y) +void MCLBN_G2_mul(MCLBN_G2 *z, const MCLBN_G2 *x, const MCLBN_Fr *y) { G2::mul(*cast(z),*cast(x), *cast(y)); } //////////////////////////////////////////////// // set zero -void BN_GT_clear(BN_GT *x) +void MCLBN_GT_clear(MCLBN_GT *x) { cast(x)->clear(); } -int BN_GT_setDecStr(BN_GT *x, const char *buf, size_t bufSize) +int MCLBN_GT_setDecStr(MCLBN_GT *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, 10, "BN_GT_setDecStr", false); + return deserialize(x, buf, bufSize, 10, "MCLBN_GT_setDecStr", false); } -int BN_GT_setHexStr(BN_GT *x, const char *buf, size_t bufSize) +int MCLBN_GT_setHexStr(MCLBN_GT *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, 16, "BN_GT_setHexStr", false); + return deserialize(x, buf, bufSize, 16, "MCLBN_GT_setHexStr", false); } -int BN_GT_deserialize(BN_GT *x, const char *buf, size_t bufSize) +int MCLBN_GT_deserialize(MCLBN_GT *x, const char *buf, size_t bufSize) { - return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "BN_GT_setHexStr", false); + return deserialize(x, buf, bufSize, mcl::IoFixedSizeByteSeq, "MCLBN_GT_setHexStr", false); } // return 1 if true -int BN_GT_isEqual(const BN_GT *x, const BN_GT *y) +int MCLBN_GT_isEqual(const MCLBN_GT *x, const MCLBN_GT *y) { return *cast(x) == *cast(y); } -int BN_GT_isZero(const BN_GT *x) +int MCLBN_GT_isZero(const MCLBN_GT *x) { return cast(x)->isZero(); } -int BN_GT_isOne(const BN_GT *x) +int MCLBN_GT_isOne(const MCLBN_GT *x) { return cast(x)->isOne(); } -size_t BN_GT_getDecStr(char *buf, size_t maxBufSize, const BN_GT *x) +size_t MCLBN_GT_getDecStr(char *buf, size_t maxBufSize, const MCLBN_GT *x) { - return serialize(buf, maxBufSize, x, 10, "BN_GT_getDecStr", false); + return serialize(buf, maxBufSize, x, 10, "MCLBN_GT_getDecStr", false); } -size_t BN_GT_getHexStr(char *buf, size_t maxBufSize, const BN_GT *x) +size_t MCLBN_GT_getHexStr(char *buf, size_t maxBufSize, const MCLBN_GT *x) { - return serialize(buf, maxBufSize, x, 16, "BN_GT_getHexStr", false); + return serialize(buf, maxBufSize, x, 16, "MCLBN_GT_getHexStr", false); } -size_t BN_GT_serialize(void *buf, size_t maxBufSize, const BN_GT *x) +size_t MCLBN_GT_serialize(void *buf, size_t maxBufSize, const MCLBN_GT *x) { - return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "BN_GT_serialize", false); + return serialize(buf, maxBufSize, x, mcl::IoFixedSizeByteSeq, "MCLBN_GT_serialize", false); } -void BN_GT_neg(BN_GT *y, const BN_GT *x) +void MCLBN_GT_neg(MCLBN_GT *y, const MCLBN_GT *x) { Fp12::neg(*cast(y), *cast(x)); } -void BN_GT_inv(BN_GT *y, const BN_GT *x) +void MCLBN_GT_inv(MCLBN_GT *y, const MCLBN_GT *x) { Fp12::inv(*cast(y), *cast(x)); } -void BN_GT_add(BN_GT *z, const BN_GT *x, const BN_GT *y) +void MCLBN_GT_add(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y) { Fp12::add(*cast(z),*cast(x), *cast(y)); } -void BN_GT_sub(BN_GT *z, const BN_GT *x, const BN_GT *y) +void MCLBN_GT_sub(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y) { Fp12::sub(*cast(z),*cast(x), *cast(y)); } -void BN_GT_mul(BN_GT *z, const BN_GT *x, const BN_GT *y) +void MCLBN_GT_mul(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y) { Fp12::mul(*cast(z),*cast(x), *cast(y)); } -void BN_GT_div(BN_GT *z, const BN_GT *x, const BN_GT *y) +void MCLBN_GT_div(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_GT *y) { Fp12::div(*cast(z),*cast(x), *cast(y)); } -void BN_GT_pow(BN_GT *z, const BN_GT *x, const BN_Fr *y) +void MCLBN_GT_pow(MCLBN_GT *z, const MCLBN_GT *x, const MCLBN_Fr *y) { Fp12::pow(*cast(z), *cast(x), *cast(y)); } -void BN_pairing(BN_GT *z, const BN_G1 *x, const BN_G2 *y) +void MCLBN_pairing(MCLBN_GT *z, const MCLBN_G1 *x, const MCLBN_G2 *y) { BN::pairing(*cast(z), *cast(x), *cast(y)); } -void BN_finalExp(BN_GT *y, const BN_GT *x) +void MCLBN_finalExp(MCLBN_GT *y, const MCLBN_GT *x) { BN::finalExp(*cast(y), *cast(x)); } -void BN_millerLoop(BN_GT *z, const BN_G1 *x, const BN_G2 *y) +void MCLBN_millerLoop(MCLBN_GT *z, const MCLBN_G1 *x, const MCLBN_G2 *y) { BN::millerLoop(*cast(z), *cast(x), *cast(y)); } -int BN_getUint64NumToPrecompute(void) +int MCLBN_getUint64NumToPrecompute(void) { return int(BN::param.precomputedQcoeffSize * sizeof(Fp6) / sizeof(uint64_t)); } -void BN_precomputeG2(uint64_t *Qbuf, const BN_G2 *Q) +void MCLBN_precomputeG2(uint64_t *Qbuf, const MCLBN_G2 *Q) { BN::precomputeG2(cast(Qbuf), *cast(Q)); } -void BN_precomputedMillerLoop(BN_GT *f, const BN_G1 *P, const uint64_t *Qbuf) +void MCLBN_precomputedMillerLoop(MCLBN_GT *f, const MCLBN_G1 *P, const uint64_t *Qbuf) { BN::precomputedMillerLoop(*cast(f), *cast(P), cast(Qbuf)); } -void BN_precomputedMillerLoop2(BN_GT *f, const BN_G1 *P1, const uint64_t *Q1buf, const BN_G1 *P2, const uint64_t *Q2buf) +void MCLBN_precomputedMillerLoop2(MCLBN_GT *f, const MCLBN_G1 *P1, const uint64_t *Q1buf, const MCLBN_G1 *P2, const uint64_t *Q2buf) { BN::precomputedMillerLoop2(*cast(f), *cast(P1), cast(Q1buf), *cast(P2), cast(Q2buf)); } diff --git a/test/bn_c256_test.cpp b/test/bn_c256_test.cpp index 2991d95..bc24189 100644 --- a/test/bn_c256_test.cpp +++ b/test/bn_c256_test.cpp @@ -1,6 +1,6 @@ #include using namespace mcl::bn256; -#define BN_DEFINE_STRUCT -#define BN_MAX_OP_UNIT_SIZE 4 +#define MCLBN_DEFINE_STRUCT +#define MCLBN_MAX_OP_UNIT_SIZE 4 #include "bn_c_test.hpp" diff --git a/test/bn_c384_test.cpp b/test/bn_c384_test.cpp index c9b6376..b7cb40e 100644 --- a/test/bn_c384_test.cpp +++ b/test/bn_c384_test.cpp @@ -1,6 +1,6 @@ #include using namespace mcl::bn384; -#define BN_DEFINE_STRUCT -#define BN_MAX_OP_UNIT_SIZE 6 +#define MCLBN_DEFINE_STRUCT +#define MCLBN_MAX_OP_UNIT_SIZE 6 #include "bn_c_test.hpp" diff --git a/test/bn_c_test.hpp b/test/bn_c_test.hpp index 686ee4a..de7aaed 100644 --- a/test/bn_c_test.hpp +++ b/test/bn_c_test.hpp @@ -19,296 +19,296 @@ std::ostream dump(std::ostream& os, const uint64_t (&x)[N]) CYBOZU_TEST_AUTO(init) { int ret; - CYBOZU_TEST_EQUAL(sizeof(BN_Fr), sizeof(Fr)); - CYBOZU_TEST_EQUAL(sizeof(BN_G1), sizeof(G1)); - CYBOZU_TEST_EQUAL(sizeof(BN_G2), sizeof(G2)); - CYBOZU_TEST_EQUAL(sizeof(BN_GT), sizeof(Fp12)); + CYBOZU_TEST_EQUAL(sizeof(MCLBN_Fr), sizeof(Fr)); + CYBOZU_TEST_EQUAL(sizeof(MCLBN_G1), sizeof(G1)); + CYBOZU_TEST_EQUAL(sizeof(MCLBN_G2), sizeof(G2)); + CYBOZU_TEST_EQUAL(sizeof(MCLBN_GT), sizeof(Fp12)); - ret = BN_setErrFile("stderr"); + ret = MCLBN_setErrFile("stderr"); CYBOZU_TEST_EQUAL(ret, 0); -#if BN_MAX_OP_UNIT_SIZE == 4 - printf("test BN_curveFp254BNb %d\n", BN_MAX_OP_UNIT_SIZE); - ret = BN_initLib(BN_curveFp254BNb, BN_MAX_OP_UNIT_SIZE); +#if MCLBN_MAX_OP_UNIT_SIZE == 4 + printf("test MCLBN_curveFp254BNb %d\n", MCLBN_MAX_OP_UNIT_SIZE); + ret = MCLBN_initLib(MCLBN_curveFp254BNb, MCLBN_MAX_OP_UNIT_SIZE); #else - printf("test BN_curveFp382_1 %d\n", BN_MAX_OP_UNIT_SIZE); - ret = BN_initLib(BN_curveFp382_1, BN_MAX_OP_UNIT_SIZE); + printf("test MCLBN_curveFp382_1 %d\n", MCLBN_MAX_OP_UNIT_SIZE); + ret = MCLBN_initLib(MCLBN_curveFp382_1, MCLBN_MAX_OP_UNIT_SIZE); #endif CYBOZU_TEST_EQUAL(ret, 0); } CYBOZU_TEST_AUTO(Fr) { - BN_Fr x, y; + MCLBN_Fr x, y; memset(&x, 0xff, sizeof(x)); - CYBOZU_TEST_ASSERT(!BN_Fr_isValid(&x)); + CYBOZU_TEST_ASSERT(!MCLBN_Fr_isValid(&x)); memset(&x, 1, sizeof(x)); - CYBOZU_TEST_ASSERT(BN_Fr_isValid(&x)); - CYBOZU_TEST_ASSERT(!BN_Fr_isZero(&x)); + CYBOZU_TEST_ASSERT(MCLBN_Fr_isValid(&x)); + CYBOZU_TEST_ASSERT(!MCLBN_Fr_isZero(&x)); - BN_Fr_clear(&x); - CYBOZU_TEST_ASSERT(BN_Fr_isZero(&x)); + MCLBN_Fr_clear(&x); + CYBOZU_TEST_ASSERT(MCLBN_Fr_isZero(&x)); - BN_Fr_setInt(&x, 1); - CYBOZU_TEST_ASSERT(BN_Fr_isOne(&x)); + MCLBN_Fr_setInt(&x, 1); + CYBOZU_TEST_ASSERT(MCLBN_Fr_isOne(&x)); - BN_Fr_setInt(&y, -1); - CYBOZU_TEST_ASSERT(!BN_Fr_isEqual(&x, &y)); + MCLBN_Fr_setInt(&y, -1); + CYBOZU_TEST_ASSERT(!MCLBN_Fr_isEqual(&x, &y)); y = x; - CYBOZU_TEST_ASSERT(BN_Fr_isEqual(&x, &y)); + CYBOZU_TEST_ASSERT(MCLBN_Fr_isEqual(&x, &y)); - BN_hashToFr(&x, "", 0); - BN_hashToFr(&y, "abc", 3); - CYBOZU_TEST_ASSERT(!BN_Fr_isEqual(&x, &y)); - BN_hashToFr(&x, "abc", 3); - CYBOZU_TEST_ASSERT(BN_Fr_isEqual(&x, &y)); + MCLBN_hashToFr(&x, "", 0); + MCLBN_hashToFr(&y, "abc", 3); + CYBOZU_TEST_ASSERT(!MCLBN_Fr_isEqual(&x, &y)); + MCLBN_hashToFr(&x, "abc", 3); + CYBOZU_TEST_ASSERT(MCLBN_Fr_isEqual(&x, &y)); char buf[1024]; - BN_Fr_setInt(&x, 12345678); + MCLBN_Fr_setInt(&x, 12345678); size_t size; - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_EQUAL(size, 8); CYBOZU_TEST_EQUAL(buf, "12345678"); - BN_Fr_setInt(&x, -7654321); - BN_Fr_neg(&x, &x); - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + MCLBN_Fr_setInt(&x, -7654321); + MCLBN_Fr_neg(&x, &x); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_EQUAL(size, 7); CYBOZU_TEST_EQUAL(buf, "7654321"); - BN_Fr_setInt(&y, 123 - 7654321); - BN_Fr_add(&x, &x, &y); - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + MCLBN_Fr_setInt(&y, 123 - 7654321); + MCLBN_Fr_add(&x, &x, &y); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_EQUAL(size, 3); CYBOZU_TEST_EQUAL(buf, "123"); - BN_Fr_setInt(&y, 100); - BN_Fr_sub(&x, &x, &y); - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + MCLBN_Fr_setInt(&y, 100); + MCLBN_Fr_sub(&x, &x, &y); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_EQUAL(size, 2); CYBOZU_TEST_EQUAL(buf, "23"); - BN_Fr_mul(&x, &x, &y); - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + MCLBN_Fr_mul(&x, &x, &y); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_EQUAL(size, 4); CYBOZU_TEST_EQUAL(buf, "2300"); - BN_Fr_div(&x, &x, &y); - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + MCLBN_Fr_div(&x, &x, &y); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_EQUAL(size, 2); CYBOZU_TEST_EQUAL(buf, "23"); - CYBOZU_TEST_ASSERT(!BN_Fr_setDecStr(&x, "12345678901234567", 17)); - CYBOZU_TEST_ASSERT(!BN_Fr_setDecStr(&y, "20000000000000000", 17)); - BN_Fr_add(&x, &x, &y); - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + CYBOZU_TEST_ASSERT(!MCLBN_Fr_setDecStr(&x, "12345678901234567", 17)); + CYBOZU_TEST_ASSERT(!MCLBN_Fr_setDecStr(&y, "20000000000000000", 17)); + MCLBN_Fr_add(&x, &x, &y); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_EQUAL(size, 17); CYBOZU_TEST_EQUAL(buf, "32345678901234567"); - BN_Fr_setInt(&x, 1); - BN_Fr_neg(&x, &x); - size = BN_Fr_getDecStr(buf, sizeof(buf), &x); + MCLBN_Fr_setInt(&x, 1); + MCLBN_Fr_neg(&x, &x); + size = MCLBN_Fr_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_ASSERT(size > 0); CYBOZU_TEST_EQUAL(size, strlen(buf)); - CYBOZU_TEST_ASSERT(!BN_Fr_setDecStr(&y, buf, size)); - CYBOZU_TEST_ASSERT(BN_Fr_isEqual(&x, &y)); + CYBOZU_TEST_ASSERT(!MCLBN_Fr_setDecStr(&y, buf, size)); + CYBOZU_TEST_ASSERT(MCLBN_Fr_isEqual(&x, &y)); } CYBOZU_TEST_AUTO(G1) { - BN_G1 x, y, z; + MCLBN_G1 x, y, z; memset(&x, 0xff, sizeof(x)); - CYBOZU_TEST_ASSERT(!BN_G1_isValid(&x)); - BN_G1_clear(&x); - CYBOZU_TEST_ASSERT(BN_G1_isValid(&x)); - CYBOZU_TEST_ASSERT(BN_G1_isZero(&x)); + CYBOZU_TEST_ASSERT(!MCLBN_G1_isValid(&x)); + MCLBN_G1_clear(&x); + CYBOZU_TEST_ASSERT(MCLBN_G1_isValid(&x)); + CYBOZU_TEST_ASSERT(MCLBN_G1_isZero(&x)); - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG1(&y, "abc", 3)); + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG1(&y, "abc", 3)); char buf[1024]; size_t size; - size = BN_G1_getHexStr(buf, sizeof(buf), &x); + size = MCLBN_G1_getHexStr(buf, sizeof(buf), &x); CYBOZU_TEST_ASSERT(size > 0); CYBOZU_TEST_EQUAL(size, strlen(buf)); - CYBOZU_TEST_ASSERT(!BN_G1_setHexStr(&y, buf, strlen(buf))); - CYBOZU_TEST_ASSERT(BN_G1_isEqual(&x, &y)); - - BN_G1_neg(&x, &x); - BN_G1_add(&x, &x, &y); - CYBOZU_TEST_ASSERT(BN_G1_isZero(&x)); - - BN_G1_dbl(&x, &y); // x = 2y - BN_G1_add(&z, &y, &y); - CYBOZU_TEST_ASSERT(BN_G1_isEqual(&x, &z)); - BN_G1_add(&z, &z, &y); // z = 3y - BN_Fr n; - BN_Fr_setInt(&n, 3); - BN_G1_mul(&x, &y, &n); // x = 3y - CYBOZU_TEST_ASSERT(BN_G1_isEqual(&x, &z)); - BN_G1_sub(&x, &x, &y); // x = 2y - - BN_Fr_setInt(&n, 2); - BN_G1_mul(&z, &y, &n); // z = 2y - CYBOZU_TEST_ASSERT(BN_G1_isEqual(&x, &z)); + CYBOZU_TEST_ASSERT(!MCLBN_G1_setHexStr(&y, buf, strlen(buf))); + CYBOZU_TEST_ASSERT(MCLBN_G1_isEqual(&x, &y)); + + MCLBN_G1_neg(&x, &x); + MCLBN_G1_add(&x, &x, &y); + CYBOZU_TEST_ASSERT(MCLBN_G1_isZero(&x)); + + MCLBN_G1_dbl(&x, &y); // x = 2y + MCLBN_G1_add(&z, &y, &y); + CYBOZU_TEST_ASSERT(MCLBN_G1_isEqual(&x, &z)); + MCLBN_G1_add(&z, &z, &y); // z = 3y + MCLBN_Fr n; + MCLBN_Fr_setInt(&n, 3); + MCLBN_G1_mul(&x, &y, &n); // x = 3y + CYBOZU_TEST_ASSERT(MCLBN_G1_isEqual(&x, &z)); + MCLBN_G1_sub(&x, &x, &y); // x = 2y + + MCLBN_Fr_setInt(&n, 2); + MCLBN_G1_mul(&z, &y, &n); // z = 2y + CYBOZU_TEST_ASSERT(MCLBN_G1_isEqual(&x, &z)); } CYBOZU_TEST_AUTO(G2) { - BN_G2 x, y, z; + MCLBN_G2 x, y, z; memset(&x, 0xff, sizeof(x)); - CYBOZU_TEST_ASSERT(!BN_G2_isValid(&x)); - BN_G2_clear(&x); - CYBOZU_TEST_ASSERT(BN_G2_isValid(&x)); - CYBOZU_TEST_ASSERT(BN_G2_isZero(&x)); + CYBOZU_TEST_ASSERT(!MCLBN_G2_isValid(&x)); + MCLBN_G2_clear(&x); + CYBOZU_TEST_ASSERT(MCLBN_G2_isValid(&x)); + CYBOZU_TEST_ASSERT(MCLBN_G2_isZero(&x)); - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG2(&x, "abc", 3)); + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG2(&x, "abc", 3)); char buf[1024]; size_t size; - size = BN_G2_getHexStr(buf, sizeof(buf), &x); + size = MCLBN_G2_getHexStr(buf, sizeof(buf), &x); CYBOZU_TEST_ASSERT(size > 0); CYBOZU_TEST_EQUAL(size, strlen(buf)); - CYBOZU_TEST_ASSERT(!BN_G2_setHexStr(&y, buf, strlen(buf))); - CYBOZU_TEST_ASSERT(BN_G2_isEqual(&x, &y)); - - BN_G2_neg(&x, &x); - BN_G2_add(&x, &x, &y); - CYBOZU_TEST_ASSERT(BN_G2_isZero(&x)); - - BN_G2_dbl(&x, &y); // x = 2y - BN_G2_add(&z, &y, &y); - CYBOZU_TEST_ASSERT(BN_G2_isEqual(&x, &z)); - BN_G2_add(&z, &z, &y); // z = 3y - BN_Fr n; - BN_Fr_setInt(&n, 3); - BN_G2_mul(&x, &y, &n); // x = 3y - CYBOZU_TEST_ASSERT(BN_G2_isEqual(&x, &z)); - BN_G2_sub(&x, &x, &y); // x = 2y - - BN_Fr_setInt(&n, 2); - BN_G2_mul(&z, &y, &n); // z = 2y - CYBOZU_TEST_ASSERT(BN_G2_isEqual(&x, &z)); + CYBOZU_TEST_ASSERT(!MCLBN_G2_setHexStr(&y, buf, strlen(buf))); + CYBOZU_TEST_ASSERT(MCLBN_G2_isEqual(&x, &y)); + + MCLBN_G2_neg(&x, &x); + MCLBN_G2_add(&x, &x, &y); + CYBOZU_TEST_ASSERT(MCLBN_G2_isZero(&x)); + + MCLBN_G2_dbl(&x, &y); // x = 2y + MCLBN_G2_add(&z, &y, &y); + CYBOZU_TEST_ASSERT(MCLBN_G2_isEqual(&x, &z)); + MCLBN_G2_add(&z, &z, &y); // z = 3y + MCLBN_Fr n; + MCLBN_Fr_setInt(&n, 3); + MCLBN_G2_mul(&x, &y, &n); // x = 3y + CYBOZU_TEST_ASSERT(MCLBN_G2_isEqual(&x, &z)); + MCLBN_G2_sub(&x, &x, &y); // x = 2y + + MCLBN_Fr_setInt(&n, 2); + MCLBN_G2_mul(&z, &y, &n); // z = 2y + CYBOZU_TEST_ASSERT(MCLBN_G2_isEqual(&x, &z)); } CYBOZU_TEST_AUTO(GT) { - BN_GT x, y, z; + MCLBN_GT x, y, z; memset(&x, 1, sizeof(x)); - CYBOZU_TEST_ASSERT(!BN_GT_isZero(&x)); + CYBOZU_TEST_ASSERT(!MCLBN_GT_isZero(&x)); - BN_GT_clear(&x); - CYBOZU_TEST_ASSERT(BN_GT_isZero(&x)); + MCLBN_GT_clear(&x); + CYBOZU_TEST_ASSERT(MCLBN_GT_isZero(&x)); char buf[2048]; const char *s = "1 2 3 4 5 6 7 8 9 10 11 12"; size_t size; - CYBOZU_TEST_ASSERT(!BN_GT_setDecStr(&x,s , strlen(s))); - size = BN_GT_getDecStr(buf, sizeof(buf), &x); + CYBOZU_TEST_ASSERT(!MCLBN_GT_setDecStr(&x,s , strlen(s))); + size = MCLBN_GT_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_ASSERT(size > 0); CYBOZU_TEST_EQUAL(size, strlen(buf)); CYBOZU_TEST_EQUAL(buf, s); y = x; - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&x, &y)); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&x, &y)); s = "-1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12"; - CYBOZU_TEST_ASSERT(!BN_GT_setDecStr(&z, s, strlen(s))); - size = BN_GT_getDecStr(buf, sizeof(buf), &z); + CYBOZU_TEST_ASSERT(!MCLBN_GT_setDecStr(&z, s, strlen(s))); + size = MCLBN_GT_getDecStr(buf, sizeof(buf), &z); CYBOZU_TEST_ASSERT(size > 0); CYBOZU_TEST_EQUAL(size, strlen(buf)); - CYBOZU_TEST_ASSERT(!BN_GT_setDecStr(&y, buf, size)); + CYBOZU_TEST_ASSERT(!MCLBN_GT_setDecStr(&y, buf, size)); - BN_GT_neg(&z, &y); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&x, &z)); + MCLBN_GT_neg(&z, &y); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&x, &z)); - BN_GT_add(&y, &x, &y); - CYBOZU_TEST_ASSERT(BN_GT_isZero(&y)); + MCLBN_GT_add(&y, &x, &y); + CYBOZU_TEST_ASSERT(MCLBN_GT_isZero(&y)); s = "2 0 0 0 0 0 0 0 0 0 0 0"; - CYBOZU_TEST_ASSERT(!BN_GT_setDecStr(&y, s, strlen(s))); - BN_GT_mul(&z, &x, &y); - size = BN_GT_getDecStr(buf, sizeof(buf), &z); + CYBOZU_TEST_ASSERT(!MCLBN_GT_setDecStr(&y, s, strlen(s))); + MCLBN_GT_mul(&z, &x, &y); + size = MCLBN_GT_getDecStr(buf, sizeof(buf), &z); CYBOZU_TEST_ASSERT(size > 0); CYBOZU_TEST_EQUAL(size, strlen(buf)); CYBOZU_TEST_EQUAL(buf, "2 4 6 8 10 12 14 16 18 20 22 24"); - BN_GT_div(&z, &z, &y); - size = BN_GT_getDecStr(buf, sizeof(buf), &x); + MCLBN_GT_div(&z, &z, &y); + size = MCLBN_GT_getDecStr(buf, sizeof(buf), &x); CYBOZU_TEST_ASSERT(size > 0); CYBOZU_TEST_EQUAL(size, strlen(buf)); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&x, &z)); - - BN_Fr n; - BN_Fr_setInt(&n, 3); - BN_GT_pow(&z, &x, &n); - BN_GT_mul(&y, &x, &x); - BN_GT_mul(&y, &y, &x); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&y, &z)); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&x, &z)); + + MCLBN_Fr n; + MCLBN_Fr_setInt(&n, 3); + MCLBN_GT_pow(&z, &x, &n); + MCLBN_GT_mul(&y, &x, &x); + MCLBN_GT_mul(&y, &y, &x); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&y, &z)); } CYBOZU_TEST_AUTO(pairing) { - BN_Fr a, b, ab; - BN_Fr_setInt(&a, 123); - BN_Fr_setInt(&b, 456); - BN_Fr_mul(&ab, &a, &b); - BN_G1 P, aP; - BN_G2 Q, bQ; - BN_GT e, e1, e2; - - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG1(&P, "1", 1)); - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG2(&Q, "1", 1)); - - BN_G1_mul(&aP, &P, &a); - BN_G2_mul(&bQ, &Q, &b); - - BN_pairing(&e, &P, &Q); - BN_GT_pow(&e1, &e, &a); - BN_pairing(&e2, &aP, &Q); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&e1, &e2)); - - BN_GT_pow(&e1, &e, &b); - BN_pairing(&e2, &P, &bQ); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&e1, &e2)); + MCLBN_Fr a, b, ab; + MCLBN_Fr_setInt(&a, 123); + MCLBN_Fr_setInt(&b, 456); + MCLBN_Fr_mul(&ab, &a, &b); + MCLBN_G1 P, aP; + MCLBN_G2 Q, bQ; + MCLBN_GT e, e1, e2; + + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG1(&P, "1", 1)); + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG2(&Q, "1", 1)); + + MCLBN_G1_mul(&aP, &P, &a); + MCLBN_G2_mul(&bQ, &Q, &b); + + MCLBN_pairing(&e, &P, &Q); + MCLBN_GT_pow(&e1, &e, &a); + MCLBN_pairing(&e2, &aP, &Q); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&e1, &e2)); + + MCLBN_GT_pow(&e1, &e, &b); + MCLBN_pairing(&e2, &P, &bQ); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&e1, &e2)); } CYBOZU_TEST_AUTO(precomputed) { - BN_G1 P1, P2; - BN_G2 Q1, Q2; - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG1(&P1, "1", 1)); - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG1(&P2, "123", 3)); - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG2(&Q1, "1", 1)); - CYBOZU_TEST_ASSERT(!BN_hashAndMapToG2(&Q2, "2", 1)); - - const int size = BN_getUint64NumToPrecompute(); + MCLBN_G1 P1, P2; + MCLBN_G2 Q1, Q2; + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG1(&P1, "1", 1)); + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG1(&P2, "123", 3)); + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG2(&Q1, "1", 1)); + CYBOZU_TEST_ASSERT(!MCLBN_hashAndMapToG2(&Q2, "2", 1)); + + const int size = MCLBN_getUint64NumToPrecompute(); std::vector Q1buf, Q2buf; Q1buf.resize(size); Q2buf.resize(size); - BN_precomputeG2(Q1buf.data(), &Q1); - BN_precomputeG2(Q2buf.data(), &Q2); + MCLBN_precomputeG2(Q1buf.data(), &Q1); + MCLBN_precomputeG2(Q2buf.data(), &Q2); - BN_GT e1, e2, f1, f2, f3; - BN_pairing(&e1, &P1, &Q1); - BN_precomputedMillerLoop(&f1, &P1, Q1buf.data()); - BN_finalExp(&f1, &f1); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&e1, &f1)); + MCLBN_GT e1, e2, f1, f2, f3; + MCLBN_pairing(&e1, &P1, &Q1); + MCLBN_precomputedMillerLoop(&f1, &P1, Q1buf.data()); + MCLBN_finalExp(&f1, &f1); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&e1, &f1)); - BN_pairing(&e2, &P2, &Q2); - BN_precomputedMillerLoop(&f2, &P2, Q2buf.data()); - BN_finalExp(&f2, &f2); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&e2, &f2)); + MCLBN_pairing(&e2, &P2, &Q2); + MCLBN_precomputedMillerLoop(&f2, &P2, Q2buf.data()); + MCLBN_finalExp(&f2, &f2); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&e2, &f2)); - BN_precomputedMillerLoop2(&f3, &P1, Q1buf.data(), &P2, Q2buf.data()); - BN_finalExp(&f3, &f3); + MCLBN_precomputedMillerLoop2(&f3, &P1, Q1buf.data(), &P2, Q2buf.data()); + MCLBN_finalExp(&f3, &f3); - BN_GT_mul(&e1, &e1, &e2); - CYBOZU_TEST_ASSERT(BN_GT_isEqual(&e1, &f3)); + MCLBN_GT_mul(&e1, &e1, &e2); + CYBOZU_TEST_ASSERT(MCLBN_GT_isEqual(&e1, &f3)); } CYBOZU_TEST_AUTO(end) { - int ret = BN_setErrFile("bn_if.log"); + int ret = MCLBN_setErrFile("bn_if.log"); CYBOZU_TEST_EQUAL(ret, 0); } -- cgit