rename macro

dev
MITSUNARI Shigeo 8 years ago
parent 0de2e4c1a1
commit ce6ad74541
  1. 4
      Makefile
  2. 18
      include/mcl/bn.h
  3. 17
      mklib.bat
  4. 10
      src/bn_c.cpp
  5. 2
      test/bn_c256_test.cpp
  6. 2
      test/bn_c384_test.cpp
  7. 10
      test/bn_c_test.hpp

@ -97,7 +97,7 @@ $(BN256_SLIB): $(LIB_OBJ) $(BN256_OBJ)
$(PRE)$(CXX) -o $@ $(LIB_OBJ) $(BN256_OBJ) -shared $(PRE)$(CXX) -o $@ $(LIB_OBJ) $(BN256_OBJ) -shared
$(BN256_OBJ): src/bn_c.cpp $(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) $(BN384_LIB): $(LIB_OBJ) $(BN384_OBJ)
$(AR) $@ $(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 $(PRE)$(CXX) -o $@ $(LIB_OBJ) $(BN384_OBJ) -shared
$(BN384_OBJ): src/bn_c.cpp $(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) $(ASM_OBJ): $(ASM_SRC)
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) $(PRE)$(CXX) -c $< -o $@ $(CFLAGS)

@ -6,8 +6,8 @@
@license modified new BSD license @license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause http://opensource.org/licenses/BSD-3-Clause
*/ */
#ifndef MCLBN_MAX_OP_UNIT_SIZE #ifndef MCLBN_FP_UNIT_SIZE
#error "define MCLBN_MAX_OP_UNIT_SIZE 4(or 6)" #error "define MCLBN_FP_UNIT_SIZE 4(or 6)"
#endif #endif
#include <stdint.h> // for uint64_t, uint8_t #include <stdint.h> // for uint64_t, uint8_t
@ -19,10 +19,10 @@
#else #else
#define MCLBN_DLL_API __declspec(dllimport) #define MCLBN_DLL_API __declspec(dllimport)
#ifndef MCL_NO_AUTOLINK #ifndef MCL_NO_AUTOLINK
#if MCLBN_MAX_OP_UNIT_SIZE == 4 #if MCLBN_FP_UNIT_SIZE == 4
#pragma comment(lib, "bn_if256.lib") #pragma comment(lib, "mclbn256.lib")
#else #else
#pragma comment(lib, "bn_if384.lib") #pragma comment(lib, "mclbn384.lib")
#endif #endif
#endif #endif
#endif #endif
@ -37,19 +37,19 @@ extern "C" {
#ifdef MCLBN_DEFINE_STRUCT #ifdef MCLBN_DEFINE_STRUCT
typedef struct { typedef struct {
uint64_t d[MCLBN_MAX_OP_UNIT_SIZE]; uint64_t d[MCLBN_FP_UNIT_SIZE];
} MCLBN_Fr; } MCLBN_Fr;
typedef struct { typedef struct {
uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 3]; uint64_t d[MCLBN_FP_UNIT_SIZE * 3];
} MCLBN_G1; } MCLBN_G1;
typedef struct { typedef struct {
uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 2 * 3]; uint64_t d[MCLBN_FP_UNIT_SIZE * 2 * 3];
} MCLBN_G2; } MCLBN_G2;
typedef struct { typedef struct {
uint64_t d[MCLBN_MAX_OP_UNIT_SIZE * 12]; uint64_t d[MCLBN_FP_UNIT_SIZE * 12];
} MCLBN_GT; } MCLBN_GT;
#else #else

@ -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 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 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 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 echo cl /c %CFLAGS% src\bn_c.cpp /Foobj\bn_c256.obj /DMCLBN_FP_UNIT_SIZE=4
cl /c %CFLAGS% src\bn_if.cpp /Foobj\bn_if256.obj /DBN_MAX_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\bn_if256.dll obj\bn_if256.obj obj\fp.obj %LDFLAGS% /implib:lib\bn_if256.lib 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\bn_if256.dll obj\bn_if256.obj obj\fp.obj %LDFLAGS% /implib:lib\bn_if256.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

@ -9,7 +9,7 @@ static std::random_device g_rg;
static cybozu::RandomGenerator g_rg; static cybozu::RandomGenerator g_rg;
#endif #endif
#if MCLBN_MAX_OP_UNIT_SIZE == 4 #if MCLBN_FP_UNIT_SIZE == 4
#include <mcl/bn256.hpp> #include <mcl/bn256.hpp>
using namespace mcl::bn256; using namespace mcl::bn256;
#else #else
@ -107,8 +107,8 @@ int MCLBN_setErrFile(const char *name)
int MCLBN_initLib(int curve, int maxUnitSize) int MCLBN_initLib(int curve, int maxUnitSize)
try try
{ {
if (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_MAX_OP_UNIT_SIZE); if (g_fp) fprintf(g_fp, "MCLBN_initLib:maxUnitSize is mismatch %d %d\n", maxUnitSize, MCLBN_FP_UNIT_SIZE);
return -1; return -1;
} }
mcl::bn::CurveParam cp; mcl::bn::CurveParam cp;
@ -116,7 +116,7 @@ int MCLBN_initLib(int curve, int maxUnitSize)
case MCLBN_curveFp254BNb: case MCLBN_curveFp254BNb:
cp = mcl::bn::CurveFp254BNb; cp = mcl::bn::CurveFp254BNb;
break; break;
#if MCLBN_MAX_OP_UNIT_SIZE == 6 #if MCLBN_FP_UNIT_SIZE == 6
case MCLBN_curveFp382_1: case MCLBN_curveFp382_1:
cp = mcl::bn::CurveFp382_1; cp = mcl::bn::CurveFp382_1;
break; 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); if (g_fp) fprintf(g_fp, "MCLBN_initLib:not supported curve %d\n", curve);
return -1; return -1;
} }
#if MCLBN_MAX_OP_UNIT_SIZE == 4 #if MCLBN_FP_UNIT_SIZE == 4
bn256init(cp); bn256init(cp);
#else #else
bn384init(cp); bn384init(cp);

@ -1,6 +1,6 @@
#include <mcl/bn256.hpp> #include <mcl/bn256.hpp>
using namespace mcl::bn256; using namespace mcl::bn256;
#define MCLBN_DEFINE_STRUCT #define MCLBN_DEFINE_STRUCT
#define MCLBN_MAX_OP_UNIT_SIZE 4 #define MCLBN_FP_UNIT_SIZE 4
#include "bn_c_test.hpp" #include "bn_c_test.hpp"

@ -1,6 +1,6 @@
#include <mcl/bn384.hpp> #include <mcl/bn384.hpp>
using namespace mcl::bn384; using namespace mcl::bn384;
#define MCLBN_DEFINE_STRUCT #define MCLBN_DEFINE_STRUCT
#define MCLBN_MAX_OP_UNIT_SIZE 6 #define MCLBN_FP_UNIT_SIZE 6
#include "bn_c_test.hpp" #include "bn_c_test.hpp"

@ -27,12 +27,12 @@ CYBOZU_TEST_AUTO(init)
ret = MCLBN_setErrFile("stderr"); ret = MCLBN_setErrFile("stderr");
CYBOZU_TEST_EQUAL(ret, 0); CYBOZU_TEST_EQUAL(ret, 0);
#if MCLBN_MAX_OP_UNIT_SIZE == 4 #if MCLBN_FP_UNIT_SIZE == 4
printf("test MCLBN_curveFp254BNb %d\n", MCLBN_MAX_OP_UNIT_SIZE); printf("test MCLBN_curveFp254BNb %d\n", MCLBN_FP_UNIT_SIZE);
ret = MCLBN_initLib(MCLBN_curveFp254BNb, MCLBN_MAX_OP_UNIT_SIZE); ret = MCLBN_initLib(MCLBN_curveFp254BNb, MCLBN_FP_UNIT_SIZE);
#else #else
printf("test MCLBN_curveFp382_1 %d\n", MCLBN_MAX_OP_UNIT_SIZE); printf("test MCLBN_curveFp382_1 %d\n", MCLBN_FP_UNIT_SIZE);
ret = MCLBN_initLib(MCLBN_curveFp382_1, MCLBN_MAX_OP_UNIT_SIZE); ret = MCLBN_initLib(MCLBN_curveFp382_1, MCLBN_FP_UNIT_SIZE);
#endif #endif
CYBOZU_TEST_EQUAL(ret, 0); CYBOZU_TEST_EQUAL(ret, 0);
} }

Loading…
Cancel
Save