From ce6ad745414aaef1ca03a7d118e7b9ae8434655e Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Thu, 1 Jun 2017 05:56:36 +0900 Subject: [PATCH] rename macro --- Makefile | 4 ++-- include/mcl/bn.h | 18 +++++++++--------- mklib.bat | 17 +++++++++++------ src/bn_c.cpp | 10 +++++----- test/bn_c256_test.cpp | 2 +- test/bn_c384_test.cpp | 2 +- test/bn_c_test.hpp | 10 +++++----- 7 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 6979145..dcaad9a 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) -DMCLBN_MAX_OP_UNIT_SIZE=4 + $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -DMCLBN_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) -DMCLBN_MAX_OP_UNIT_SIZE=6 + $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -DMCLBN_FP_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 09c0595..9706c71 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_MAX_OP_UNIT_SIZE - #error "define MCLBN_MAX_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,10 +19,10 @@ #else #define MCLBN_DLL_API __declspec(dllimport) #ifndef MCL_NO_AUTOLINK - #if MCLBN_MAX_OP_UNIT_SIZE == 4 - #pragma comment(lib, "bn_if256.lib") + #if MCLBN_FP_UNIT_SIZE == 4 + #pragma comment(lib, "mclbn256.lib") #else - #pragma comment(lib, "bn_if384.lib") + #pragma comment(lib, "mclbn384.lib") #endif #endif #endif @@ -37,19 +37,19 @@ extern "C" { #ifdef MCLBN_DEFINE_STRUCT typedef struct { - uint64_t d[MCLBN_MAX_OP_UNIT_SIZE]; + uint64_t d[MCLBN_FP_UNIT_SIZE]; } MCLBN_Fr; typedef struct { - uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 3]; + uint64_t d[MCLBN_FP_UNIT_SIZE * 3]; } MCLBN_G1; typedef struct { - uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 2 * 3]; + uint64_t d[MCLBN_FP_UNIT_SIZE * 2 * 3]; } MCLBN_G2; typedef struct { - uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 12]; + uint64_t d[MCLBN_FP_UNIT_SIZE * 12]; } MCLBN_GT; #else diff --git a/mklib.bat b/mklib.bat index be82d5f..4d9f886 100644 --- a/mklib.bat +++ b/mklib.bat @@ -4,11 +4,16 @@ rem nasm -f win64 -D_WIN64 src\asm\low_x86-64.asm rem lib /OUT:lib\mcl.lib /nodefaultlib fp.obj src\asm\low_x86-64.obj echo cl /c %CFLAGS% src\fp.cpp /Foobj\fp.obj -cl /c %CFLAGS% src\fp.cpp /Foobj\fp.obj + cl /c %CFLAGS% src\fp.cpp /Foobj\fp.obj echo lib /nologo /OUT:lib\mcl.lib /nodefaultlib obj\fp.obj -lib /nologo /OUT:lib\mcl.lib /nodefaultlib obj\fp.obj + lib /nologo /OUT:lib\mcl.lib /nodefaultlib obj\fp.obj -echo cl /c %CFLAGS% src\bn_if.cpp /Foobj\bn_if256.obj /DBN_MAX_FP_UNIT_SIZE=4 -cl /c %CFLAGS% src\bn_if.cpp /Foobj\bn_if256.obj /DBN_MAX_FP_UNIT_SIZE=4 -echo link /nologo /DLL /OUT:bin\bn_if256.dll obj\bn_if256.obj obj\fp.obj %LDFLAGS% /implib:lib\bn_if256.lib -link /nologo /DLL /OUT:bin\bn_if256.dll obj\bn_if256.obj obj\fp.obj %LDFLAGS% /implib:lib\bn_if256.lib +echo cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c256.obj /DMCLBN_FP_UNIT_SIZE=4 + cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c256.obj /DMCLBN_FP_UNIT_SIZE=4 +echo link /nologo /DLL /OUT:bin\mclbn256.dll obj\bn_c256.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn256.lib + link /nologo /DLL /OUT:bin\mclbn256.dll obj\bn_c256.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn256.lib + +echo cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c384.obj /DMCLBN_FP_UNIT_SIZE=6 + cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c384.obj /DMCLBN_FP_UNIT_SIZE=6 +echo link /nologo /DLL /OUT:bin\mclbn384.dll obj\bn_c384.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn384.lib + link /nologo /DLL /OUT:bin\mclbn384.dll obj\bn_c384.obj obj\fp.obj %LDFLAGS% /implib:lib\mclbn384.lib diff --git a/src/bn_c.cpp b/src/bn_c.cpp index 814f2f3..855faca 100644 --- a/src/bn_c.cpp +++ b/src/bn_c.cpp @@ -9,7 +9,7 @@ static std::random_device g_rg; static cybozu::RandomGenerator g_rg; #endif -#if MCLBN_MAX_OP_UNIT_SIZE == 4 +#if MCLBN_FP_UNIT_SIZE == 4 #include using namespace mcl::bn256; #else @@ -107,8 +107,8 @@ int MCLBN_setErrFile(const char *name) int MCLBN_initLib(int curve, int maxUnitSize) try { - 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); + if (maxUnitSize != MCLBN_FP_UNIT_SIZE) { + if (g_fp) fprintf(g_fp, "MCLBN_initLib:maxUnitSize is mismatch %d %d\n", maxUnitSize, MCLBN_FP_UNIT_SIZE); return -1; } mcl::bn::CurveParam cp; @@ -116,7 +116,7 @@ int MCLBN_initLib(int curve, int maxUnitSize) case MCLBN_curveFp254BNb: cp = mcl::bn::CurveFp254BNb; break; -#if MCLBN_MAX_OP_UNIT_SIZE == 6 +#if MCLBN_FP_UNIT_SIZE == 6 case MCLBN_curveFp382_1: cp = mcl::bn::CurveFp382_1; break; @@ -128,7 +128,7 @@ int MCLBN_initLib(int curve, int maxUnitSize) if (g_fp) fprintf(g_fp, "MCLBN_initLib:not supported curve %d\n", curve); return -1; } -#if MCLBN_MAX_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 bc24189..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_MAX_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 b7cb40e..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_MAX_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 de7aaed..a658a65 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_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); +#if MCLBN_FP_UNIT_SIZE == 4 + printf("test MCLBN_curveFp254BNb %d\n", MCLBN_FP_UNIT_SIZE); + ret = MCLBN_initLib(MCLBN_curveFp254BNb, MCLBN_FP_UNIT_SIZE); #else - printf("test MCLBN_curveFp382_1 %d\n", MCLBN_MAX_OP_UNIT_SIZE); - ret = MCLBN_initLib(MCLBN_curveFp382_1, MCLBN_MAX_OP_UNIT_SIZE); + printf("test MCLBN_curveFp382_1 %d\n", MCLBN_FP_UNIT_SIZE); + ret = MCLBN_initLib(MCLBN_curveFp382_1, MCLBN_FP_UNIT_SIZE); #endif CYBOZU_TEST_EQUAL(ret, 0); }