rename MCLBN_OP_UNIT_SIZE to MCLBN_FP_UNIT_SIZE

dev
MITSUNARI Shigeo 8 years ago
parent 15e511bbb3
commit 4876e522f7
  1. 4
      Makefile
  2. 12
      ffi/go/mcl/mcl.go
  3. 30
      include/mcl/bn.h
  4. 11
      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) -D"MCLBN_OP_UNIT_SIZE=4" $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_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) -D"MCLBN_OP_UNIT_SIZE=6" $(PRE)$(CXX) -c $< -o $@ $(CFLAGS) -D"MCLBN_FP_UNIT_SIZE=6"
$(ASM_OBJ): $(ASM_SRC) $(ASM_OBJ): $(ASM_SRC)
$(PRE)$(CXX) -c $< -o $@ $(CFLAGS) $(PRE)$(CXX) -c $< -o $@ $(CFLAGS)

@ -1,7 +1,7 @@
package mcl 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 #cgo LDFLAGS:-lmclbn384_dy -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto
#include <mcl/bn.h> #include <mcl/bn.h>
*/ */
@ -22,7 +22,7 @@ const CurveFp382_2 = 2
// call this function before calling all the other operations // call this function before calling all the other operations
// this function is not thread safe // this function is not thread safe
func Init(curve int) error { 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 { if err != 0 {
return fmt.Errorf("ERR mclBn_init curve=%d", curve) return fmt.Errorf("ERR mclBn_init curve=%d", curve)
} }
@ -32,7 +32,7 @@ func Init(curve int) error {
//////////////////////////////////////////////// ////////////////////////////////////////////////
// Fr -- // Fr --
type Fr struct { type Fr struct {
v [C.MCLBN_OP_UNIT_SIZE]C.uint64_t v C.mclBnFr
} }
// getPointer -- // getPointer --
@ -168,7 +168,7 @@ func FrDiv(out *Fr, x *Fr, y *Fr) {
//////////////////////////////////////////// ////////////////////////////////////////////
// G1 -- // G1 --
type G1 struct { type G1 struct {
v [C.MCLBN_OP_UNIT_SIZE * 3]C.uint64_t v C.mclBnG1
} }
// getPointer -- // getPointer --
@ -274,7 +274,7 @@ func G1Mul(out *G1, x *G1, y *Fr) {
//////////////////////////////////////////// ////////////////////////////////////////////
// G2 -- // G2 --
type G2 struct { type G2 struct {
v [C.MCLBN_OP_UNIT_SIZE * 2 * 3]C.uint64_t v C.mclBnG1
} }
// getPointer -- // getPointer --
@ -380,7 +380,7 @@ func G2Mul(out *G2, x *G2, y *Fr) {
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// GT -- // GT --
type GT struct { type GT struct {
v [C.MCLBN_OP_UNIT_SIZE * 12]C.uint64_t v C.mclBnGT
} }
// getPointer -- // getPointer --

@ -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_OP_UNIT_SIZE #ifndef MCLBN_FP_UNIT_SIZE
#error "define MCLBN_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,7 +19,7 @@
#else #else
#define MCLBN_DLL_API __declspec(dllimport) #define MCLBN_DLL_API __declspec(dllimport)
#ifndef MCL_NO_AUTOLINK #ifndef MCL_NO_AUTOLINK
#if MCLBN_OP_UNIT_SIZE == 4 #if MCLBN_FP_UNIT_SIZE == 4
#pragma comment(lib, "mclbn256.lib") #pragma comment(lib, "mclbn256.lib")
#else #else
#pragma comment(lib, "mclbn384.lib") #pragma comment(lib, "mclbn384.lib")
@ -34,31 +34,31 @@
extern "C" { extern "C" {
#endif #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 { typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE]; uint64_t d[MCLBN_FP_UNIT_SIZE];
} mclBnFr; } mclBnFr;
typedef struct { typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE * 3]; uint64_t d[MCLBN_FP_UNIT_SIZE * 3];
} mclBnG1; } mclBnG1;
typedef struct { typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE * 2 * 3]; uint64_t d[MCLBN_FP_UNIT_SIZE * 2 * 3];
} mclBnG2; } mclBnG2;
typedef struct { typedef struct {
uint64_t d[MCLBN_OP_UNIT_SIZE * 12]; uint64_t d[MCLBN_FP_UNIT_SIZE * 12];
} mclBnGT; } mclBnGT;
#else
typedef struct mclBnFr mclBnFr;
typedef struct mclBnG1 mclBnG1;
typedef struct mclBnG2 mclBnG2;
typedef struct mclBnGT mclBnGT;
#endif #endif
/* /*

@ -1,5 +1,4 @@
#define MCLBN_DLL_EXPORT #define MCLBN_DLL_EXPORT
#define MCLBN_DEFINE_STRUCT
#include <mcl/bn.h> #include <mcl/bn.h>
#if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 #if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11
#include <random> #include <random>
@ -9,7 +8,7 @@ static std::random_device g_rg;
static cybozu::RandomGenerator g_rg; static cybozu::RandomGenerator g_rg;
#endif #endif
#if MCLBN_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 +106,8 @@ int mclBn_setErrFile(const char *name)
int mclBn_init(int curve, int maxUnitSize) int mclBn_init(int curve, int maxUnitSize)
try try
{ {
if (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_OP_UNIT_SIZE); if (g_fp) fprintf(g_fp, "mclBn_init: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 +115,7 @@ int mclBn_init(int curve, int maxUnitSize)
case mclBn_curveFp254BNb: case mclBn_curveFp254BNb:
cp = mcl::bn::CurveFp254BNb; cp = mcl::bn::CurveFp254BNb;
break; break;
#if MCLBN_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 +127,7 @@ int mclBn_init(int curve, int maxUnitSize)
if (g_fp) fprintf(g_fp, "MCLBN_init:not supported curve %d\n", curve); if (g_fp) fprintf(g_fp, "MCLBN_init:not supported curve %d\n", curve);
return -1; return -1;
} }
#if MCLBN_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_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_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_OP_UNIT_SIZE == 4 #if MCLBN_FP_UNIT_SIZE == 4
printf("test MCLBN_curveFp254BNb %d\n", MCLBN_OP_UNIT_SIZE); printf("test MCLBN_curveFp254BNb %d\n", MCLBN_FP_UNIT_SIZE);
ret = mclBn_init(mclBn_curveFp254BNb, MCLBN_OP_UNIT_SIZE); ret = mclBn_init(mclBn_curveFp254BNb, MCLBN_FP_UNIT_SIZE);
#else #else
printf("test MCLBN_curveFp382_1 %d\n", MCLBN_OP_UNIT_SIZE); printf("test MCLBN_curveFp382_1 %d\n", MCLBN_FP_UNIT_SIZE);
ret = mclBn_init(mclBn_curveFp382_1, MCLBN_OP_UNIT_SIZE); ret = mclBn_init(mclBn_curveFp382_1, MCLBN_FP_UNIT_SIZE);
#endif #endif
CYBOZU_TEST_EQUAL(ret, 0); CYBOZU_TEST_EQUAL(ret, 0);
} }

Loading…
Cancel
Save