From 4876e522f7d516ba7aec38a4dab032d21251ca87 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 5 Jun 2017 21:36:46 +0900 Subject: [PATCH] rename MCLBN_OP_UNIT_SIZE to MCLBN_FP_UNIT_SIZE --- Makefile | 4 ++-- ffi/go/mcl/mcl.go | 12 ++++++------ include/mcl/bn.h | 30 +++++++++++++++--------------- src/bn_c.cpp | 11 +++++------ test/bn_c256_test.cpp | 2 +- test/bn_c384_test.cpp | 2 +- test/bn_c_test.hpp | 10 +++++----- 7 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index f8ce751..b4a7d4b 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) -D"MCLBN_OP_UNIT_SIZE=4" + $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_FP_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) -D"MCLBN_OP_UNIT_SIZE=6" + $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_FP_UNIT_SIZE=6" $(ASM_OBJ): $(ASM_SRC) $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) diff --git a/ffi/go/mcl/mcl.go b/ffi/go/mcl/mcl.go index b2a0ead..96a2df6 100644 --- a/ffi/go/mcl/mcl.go +++ b/ffi/go/mcl/mcl.go @@ -1,7 +1,7 @@ package mcl /* -#cgo CFLAGS:-D"MCLBN_OP_UNIT_SIZE=6" +#cgo CFLAGS:-D"MCLBN_FP_UNIT_SIZE=6" #cgo LDFLAGS:-lmclbn384_dy -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto #include */ @@ -22,7 +22,7 @@ const CurveFp382_2 = 2 // call this function before calling all the other operations // this function is not thread safe func Init(curve int) error { - err := C.mclBn_init(C.int(curve), C.MCLBN_OP_UNIT_SIZE) + err := C.mclBn_init(C.int(curve), C.MCLBN_FP_UNIT_SIZE) if err != 0 { return fmt.Errorf("ERR mclBn_init curve=%d", curve) } @@ -32,7 +32,7 @@ func Init(curve int) error { //////////////////////////////////////////////// // Fr -- type Fr struct { - v [C.MCLBN_OP_UNIT_SIZE]C.uint64_t + v C.mclBnFr } // getPointer -- @@ -168,7 +168,7 @@ func FrDiv(out *Fr, x *Fr, y *Fr) { //////////////////////////////////////////// // G1 -- type G1 struct { - v [C.MCLBN_OP_UNIT_SIZE * 3]C.uint64_t + v C.mclBnG1 } // getPointer -- @@ -274,7 +274,7 @@ func G1Mul(out *G1, x *G1, y *Fr) { //////////////////////////////////////////// // G2 -- type G2 struct { - v [C.MCLBN_OP_UNIT_SIZE * 2 * 3]C.uint64_t + v C.mclBnG1 } // getPointer -- @@ -380,7 +380,7 @@ func G2Mul(out *G2, x *G2, y *Fr) { /////////////////////////////////////////////////////// // GT -- type GT struct { - v [C.MCLBN_OP_UNIT_SIZE * 12]C.uint64_t + v C.mclBnGT } // getPointer -- diff --git a/include/mcl/bn.h b/include/mcl/bn.h index 97c5727..f8fdf88 100644 --- a/include/mcl/bn.h +++ b/include/mcl/bn.h @@ -6,8 +6,8 @@ @license modified new BSD license http://opensource.org/licenses/BSD-3-Clause */ -#ifndef MCLBN_OP_UNIT_SIZE - #error "define MCLBN_OP_UNIT_SIZE 4(or 6)" +#ifndef MCLBN_FP_UNIT_SIZE + #error "define MCLBN_FP_UNIT_SIZE 4(or 6)" #endif #include // for uint64_t, uint8_t @@ -19,7 +19,7 @@ #else #define MCLBN_DLL_API __declspec(dllimport) #ifndef MCL_NO_AUTOLINK - #if MCLBN_OP_UNIT_SIZE == 4 + #if MCLBN_FP_UNIT_SIZE == 4 #pragma comment(lib, "mclbn256.lib") #else #pragma comment(lib, "mclbn384.lib") @@ -34,31 +34,31 @@ extern "C" { #endif -#ifdef MCLBN_DEFINE_STRUCT +#ifdef MCLBN_NOT_DEFINE_STRUCT + +typedef struct mclBnFr mclBnFr; +typedef struct mclBnG1 mclBnG1; +typedef struct mclBnG2 mclBnG2; +typedef struct mclBnGT mclBnGT; + +#else typedef struct { - uint64_t d[MCLBN_OP_UNIT_SIZE]; + uint64_t d[MCLBN_FP_UNIT_SIZE]; } mclBnFr; typedef struct { - uint64_t d[MCLBN_OP_UNIT_SIZE * 3]; + uint64_t d[MCLBN_FP_UNIT_SIZE * 3]; } mclBnG1; typedef struct { - uint64_t d[MCLBN_OP_UNIT_SIZE * 2 * 3]; + uint64_t d[MCLBN_FP_UNIT_SIZE * 2 * 3]; } mclBnG2; typedef struct { - uint64_t d[MCLBN_OP_UNIT_SIZE * 12]; + uint64_t d[MCLBN_FP_UNIT_SIZE * 12]; } mclBnGT; -#else - -typedef struct mclBnFr mclBnFr; -typedef struct mclBnG1 mclBnG1; -typedef struct mclBnG2 mclBnG2; -typedef struct mclBnGT mclBnGT; - #endif /* diff --git a/src/bn_c.cpp b/src/bn_c.cpp index b86f972..549c84c 100644 --- a/src/bn_c.cpp +++ b/src/bn_c.cpp @@ -1,5 +1,4 @@ #define MCLBN_DLL_EXPORT -#define MCLBN_DEFINE_STRUCT #include #if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 #include @@ -9,7 +8,7 @@ static std::random_device g_rg; static cybozu::RandomGenerator g_rg; #endif -#if MCLBN_OP_UNIT_SIZE == 4 +#if MCLBN_FP_UNIT_SIZE == 4 #include using namespace mcl::bn256; #else @@ -107,8 +106,8 @@ int mclBn_setErrFile(const char *name) int mclBn_init(int curve, int maxUnitSize) try { - if (maxUnitSize != MCLBN_OP_UNIT_SIZE) { - if (g_fp) fprintf(g_fp, "mclBn_init:maxUnitSize is mismatch %d %d\n", maxUnitSize, MCLBN_OP_UNIT_SIZE); + if (maxUnitSize != MCLBN_FP_UNIT_SIZE) { + if (g_fp) fprintf(g_fp, "mclBn_init:maxUnitSize is mismatch %d %d\n", maxUnitSize, MCLBN_FP_UNIT_SIZE); return -1; } mcl::bn::CurveParam cp; @@ -116,7 +115,7 @@ int mclBn_init(int curve, int maxUnitSize) case mclBn_curveFp254BNb: cp = mcl::bn::CurveFp254BNb; break; -#if MCLBN_OP_UNIT_SIZE == 6 +#if MCLBN_FP_UNIT_SIZE == 6 case mclBn_curveFp382_1: cp = mcl::bn::CurveFp382_1; break; @@ -128,7 +127,7 @@ int mclBn_init(int curve, int maxUnitSize) if (g_fp) fprintf(g_fp, "MCLBN_init:not supported curve %d\n", curve); return -1; } -#if MCLBN_OP_UNIT_SIZE == 4 +#if MCLBN_FP_UNIT_SIZE == 4 bn256init(cp); #else bn384init(cp); diff --git a/test/bn_c256_test.cpp b/test/bn_c256_test.cpp index 90f1b35..2ce8516 100644 --- a/test/bn_c256_test.cpp +++ b/test/bn_c256_test.cpp @@ -1,6 +1,6 @@ #include using namespace mcl::bn256; #define MCLBN_DEFINE_STRUCT -#define MCLBN_OP_UNIT_SIZE 4 +#define MCLBN_FP_UNIT_SIZE 4 #include "bn_c_test.hpp" diff --git a/test/bn_c384_test.cpp b/test/bn_c384_test.cpp index 011cced..a9f2024 100644 --- a/test/bn_c384_test.cpp +++ b/test/bn_c384_test.cpp @@ -1,6 +1,6 @@ #include using namespace mcl::bn384; #define MCLBN_DEFINE_STRUCT -#define MCLBN_OP_UNIT_SIZE 6 +#define MCLBN_FP_UNIT_SIZE 6 #include "bn_c_test.hpp" diff --git a/test/bn_c_test.hpp b/test/bn_c_test.hpp index ebbaff9..9f016f0 100644 --- a/test/bn_c_test.hpp +++ b/test/bn_c_test.hpp @@ -27,12 +27,12 @@ CYBOZU_TEST_AUTO(init) ret = mclBn_setErrFile("stderr"); CYBOZU_TEST_EQUAL(ret, 0); -#if MCLBN_OP_UNIT_SIZE == 4 - printf("test MCLBN_curveFp254BNb %d\n", MCLBN_OP_UNIT_SIZE); - ret = mclBn_init(mclBn_curveFp254BNb, MCLBN_OP_UNIT_SIZE); +#if MCLBN_FP_UNIT_SIZE == 4 + printf("test MCLBN_curveFp254BNb %d\n", MCLBN_FP_UNIT_SIZE); + ret = mclBn_init(mclBn_curveFp254BNb, MCLBN_FP_UNIT_SIZE); #else - printf("test MCLBN_curveFp382_1 %d\n", MCLBN_OP_UNIT_SIZE); - ret = mclBn_init(mclBn_curveFp382_1, MCLBN_OP_UNIT_SIZE); + printf("test MCLBN_curveFp382_1 %d\n", MCLBN_FP_UNIT_SIZE); + ret = mclBn_init(mclBn_curveFp382_1, MCLBN_FP_UNIT_SIZE); #endif CYBOZU_TEST_EQUAL(ret, 0); }