aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-06-05 20:36:46 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-06-05 20:36:46 +0800
commit4876e522f7d516ba7aec38a4dab032d21251ca87 (patch)
treeb2d65b942464a7ba80d2b5009697b58f92f56593
parent15e511bbb349748acdcc2499604140976a1ec665 (diff)
downloadtangerine-mcl-4876e522f7d516ba7aec38a4dab032d21251ca87.tar.gz
tangerine-mcl-4876e522f7d516ba7aec38a4dab032d21251ca87.tar.zst
tangerine-mcl-4876e522f7d516ba7aec38a4dab032d21251ca87.zip
rename MCLBN_OP_UNIT_SIZE to MCLBN_FP_UNIT_SIZE
-rw-r--r--Makefile4
-rw-r--r--ffi/go/mcl/mcl.go12
-rw-r--r--include/mcl/bn.h30
-rw-r--r--src/bn_c.cpp11
-rw-r--r--test/bn_c256_test.cpp2
-rw-r--r--test/bn_c384_test.cpp2
-rw-r--r--test/bn_c_test.hpp10
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 <mcl/bn.h>
*/
@@ -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 <stdint.h> // 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 <mcl/bn.h>
#if 0 // #if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11
#include <random>
@@ -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 <mcl/bn256.hpp>
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 <mcl/bn256.hpp>
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 <mcl/bn384.hpp>
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);
}