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
$(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)

@ -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 <stdint.h> // 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

@ -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

@ -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 <mcl/bn256.hpp>
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);

@ -1,6 +1,6 @@
#include <mcl/bn256.hpp>
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"

@ -1,6 +1,6 @@
#include <mcl/bn384.hpp>
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"

@ -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);
}

Loading…
Cancel
Save