aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-06-04 08:34:43 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-06-04 08:34:43 +0800
commitacf1c832c65429be7f07d8bae5ce91978f78e75f (patch)
treebf47fed054a78659281a88fd603c9810550ae1a0
parent5a38c2e8c9a27555229e9cd61455caf1aa3d8907 (diff)
downloaddexon-bls-acf1c832c65429be7f07d8bae5ce91978f78e75f.tar
dexon-bls-acf1c832c65429be7f07d8bae5ce91978f78e75f.tar.gz
dexon-bls-acf1c832c65429be7f07d8bae5ce91978f78e75f.tar.bz2
dexon-bls-acf1c832c65429be7f07d8bae5ce91978f78e75f.tar.lz
dexon-bls-acf1c832c65429be7f07d8bae5ce91978f78e75f.tar.xz
dexon-bls-acf1c832c65429be7f07d8bae5ce91978f78e75f.tar.zst
dexon-bls-acf1c832c65429be7f07d8bae5ce91978f78e75f.zip
use MBN_.. instead of BLS_
-rw-r--r--Makefile22
-rw-r--r--go/bls/bls.go18
-rw-r--r--include/bls/bls.h17
-rw-r--r--include/bls/bls.hpp16
-rw-r--r--src/bls.cpp10
-rw-r--r--test/bls_c384_test.cpp4
-rw-r--r--test/bls_test.cpp2
7 files changed, 44 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index 6aa5927..837c335 100644
--- a/Makefile
+++ b/Makefile
@@ -11,17 +11,18 @@ SAMPLE_SRC=bls_smpl.cpp bls_tool.cpp
CFLAGS+=-I../mcl/include
UNIT?=6
ifeq ($(UNIT),4)
- CFLAGS+=-DBLS_FP_UNIT_SIZE=4
+ CFLAGS+=-DMBN_FP_UNIT_SIZE=4
GO_TAG=bn256
endif
ifeq ($(UNIT),6)
- CFLAGS+=-DBLS_FP_UNIT_SIZE=6
+ CFLAGS+=-DMBN_FP_UNIT_SIZE=6
GO_TAG=bn384
endif
sample_test: $(EXE_DIR)/bls_smpl.exe
python bls_smpl.py
+SHARE_BASENAME_SUF?=_dy
##################################################################
BLS_LIB=$(LIB_DIR)/libbls.a
@@ -31,6 +32,7 @@ $(BLS_LIB): $(LIB_OBJ)
$(AR) $@ $(LIB_OBJ)
MCL_LIB=../mcl/lib/libmcl.a
+BN384_LIB=../mcl/lib/libmclbn384.a
$(MCL_LIB):
$(MAKE) -C ../mcl
@@ -38,11 +40,16 @@ $(MCL_LIB):
##################################################################
BLS384_LIB=$(LIB_DIR)/libbls384.a
-lib: $(BLS_LIB) $(BLS384_LIB)
+BLS384_SLIB=$(LIB_DIR)/libbls384$(SHARE_BASENAME_SUF).$(LIB_SUF)
+lib: $(BLS_LIB) $(BLS384_SLIB)
$(BLS384_LIB): $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
$(AR) $@ $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
+$(BLS384_SLIB): $(BLS384_LIB) $(BN384_LIB)
+# $(PRE)$(CXX) -shared -o $@ -Wl,--whole-archive $(BLS384_LIB) $(BN384_LIB) $(MCL_LIB) -Wl,--no-whole-archive
+ $(PRE)$(CXX) -shared -o $@ -Wl,--whole-archive $(BLS384_LIB) $(BN384_LIB) -Wl,--no-whole-archive
+
VPATH=test sample src
.SUFFIXES: .cpp .d .exe
@@ -51,7 +58,7 @@ $(OBJ_DIR)/%.o: %.cpp
$(PRE)$(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d)
$(OBJ_DIR)/bls_c384.o: bls_c.cpp
- $(PRE)$(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d) -DBLS_FP_UNIT_SIZE=6
+ $(PRE)$(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d) -DMBN_FP_UNIT_SIZE=6
$(EXE_DIR)/%.exe: $(OBJ_DIR)/%.o $(BLS_LIB) $(BLS384_LIB) $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(BLS_LIB) $(BLS384_LIB) -lmcl -L../mcl/lib $(LDFLAGS)
@@ -65,13 +72,12 @@ test: $(TEST_EXE)
@sh -ec 'for i in $(TEST_EXE); do $$i|grep "ctest:name"; done' > result.txt
@grep -v "ng=0, exception=0" result.txt; if [ $$? -eq 1 ]; then echo "all unit tests succeed"; else exit 1; fi
-run_go: go/bls/bls.go go/bls/bls_test.go $(BLS_LIB) $(BLS384_LIB)
-# cd go/bls && env PKG_CONFIG_PATH=./ go test -tags $(GO_TAG) .
- cd go/bls && go test -tags $(GO_TAG) .
+run_go: go/bls/bls.go go/bls/bls_test.go $(BLS384_SLIB)
+ cd go/bls && env CGO_CFLAGS="-I../../include -I../../../mcl/include" CGO_LDFLAGS="-L../../lib -L../../../mcl/lib" LD_LIBRARY_PAHT=../../lib go test .
# cd go/bls && go test -tags $(GO_TAG) -v .
clean:
- $(RM) $(BLS_LIB) $(OBJ_DIR)/*.d $(OBJ_DIR)/*.o $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS384_LIB)
+ $(RM) $(BLS_LIB) $(OBJ_DIR)/*.d $(OBJ_DIR)/*.o $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS384_SLIB)
ALL_SRC=$(SRC_SRC) $(TEST_SRC) $(SAMPLE_SRC)
DEPEND_FILE=$(addprefix $(OBJ_DIR)/, $(ALL_SRC:.cpp=.d))
diff --git a/go/bls/bls.go b/go/bls/bls.go
index bbf765d..7ca3553 100644
--- a/go/bls/bls.go
+++ b/go/bls/bls.go
@@ -1,10 +1,8 @@
package bls
/*
-#cgo CFLAGS:-I../../include
-#cgo LDFLAGS:-lbls384 -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto -L../../lib -L../../../mcl/lib
-#cgo bn256 CFLAGS:-UBLS_FP_UNIT_SIZE -DBLS_FP_UNIT_SIZE=4
-#cgo bn384 CFLAGS:-UBLS_FP_UNIT_SIZE -DBLS_FP_UNIT_SIZE=6
+#cgo CFLAGS:-DMBN_FP_UNIT_SIZE=6
+#cgo LDFLAGS:-lbls384 -lmclbn384 -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto
#include <bls/bls.h>
*/
import "C"
@@ -24,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.blsInit(C.int(curve), C.BLS_FP_UNIT_SIZE)
+ err := C.blsInit(C.int(curve), C.MBN_FP_UNIT_SIZE)
if err != 0 {
return fmt.Errorf("ERR Init curve=%d", curve)
}
@@ -33,7 +31,7 @@ func Init(curve int) error {
// GetMaxOpUnitSize --
func GetMaxOpUnitSize() int {
- return int(C.BLS_FP_UNIT_SIZE)
+ return int(C.MBN_FP_UNIT_SIZE)
}
// GetOpUnitSize --
@@ -65,7 +63,7 @@ func GetFieldOrder() string {
// ID --
type ID struct {
- v [C.BLS_FP_UNIT_SIZE]C.uint64_t
+ v [C.MBN_FP_UNIT_SIZE]C.uint64_t
}
// getPointer --
@@ -146,7 +144,7 @@ func (id *ID) IsEqual(rhs *ID) bool {
// SecretKey --
type SecretKey struct {
- v [C.BLS_FP_UNIT_SIZE]C.uint64_t
+ v [C.MBN_FP_UNIT_SIZE]C.uint64_t
}
// getPointer --
@@ -282,7 +280,7 @@ func (sec *SecretKey) GetPop() (sign *Sign) {
// PublicKey --
type PublicKey struct {
- v [C.BLS_FP_UNIT_SIZE * 2 * 3]C.uint64_t
+ v [C.MBN_FP_UNIT_SIZE * 2 * 3]C.uint64_t
}
// getPointer --
@@ -364,7 +362,7 @@ func (pub *PublicKey) Recover(pubVec []PublicKey, idVec []ID) error {
// Sign --
type Sign struct {
- v [C.BLS_FP_UNIT_SIZE * 3]C.uint64_t
+ v [C.MBN_FP_UNIT_SIZE * 3]C.uint64_t
}
// getPointer --
diff --git a/include/bls/bls.h b/include/bls/bls.h
index e762f2e..cb84147 100644
--- a/include/bls/bls.h
+++ b/include/bls/bls.h
@@ -6,12 +6,7 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
-#ifndef BLS_FP_UNIT_SIZE
- #error "define BLS_FP_UNIT_SIZE 4(or 6)"
-#endif
-
-#include <stdint.h> // for uint64_t, uint8_t
-#include <stdlib.h> // for size_t
+#include <mcl/bn.h>
#ifdef _MSC_VER
#ifdef BLS_DLL_EXPORT
@@ -19,7 +14,7 @@
#else
#define BLS_DLL_API __declspec(dllimport)
#ifndef BLS_NO_AUTOLINK
- #if BLS_FP_UNIT_SIZE == 4
+ #if MBN_FP_UNIT_SIZE == 4
#pragma comment(lib, "bls256.lib")
#endif
#endif
@@ -39,19 +34,19 @@ enum {
};
typedef struct {
- uint64_t buf[BLS_FP_UNIT_SIZE];
+ uint64_t buf[MBN_FP_UNIT_SIZE];
} blsId;
typedef struct {
- uint64_t buf[BLS_FP_UNIT_SIZE];
+ uint64_t buf[MBN_FP_UNIT_SIZE];
} blsSecretKey;
typedef struct {
- uint64_t buf[BLS_FP_UNIT_SIZE * 2 * 3];
+ uint64_t buf[MBN_FP_UNIT_SIZE * 2 * 3];
} blsPublicKey;
typedef struct {
- uint64_t buf[BLS_FP_UNIT_SIZE * 3];
+ uint64_t buf[MBN_FP_UNIT_SIZE * 3];
} blsSignature;
/*
diff --git a/include/bls/bls.hpp b/include/bls/bls.hpp
index 382eba7..1ac58d9 100644
--- a/include/bls/bls.hpp
+++ b/include/bls/bls.hpp
@@ -6,8 +6,8 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
-#ifndef BLS_FP_UNIT_SIZE
- #error "define BLS_FP_UNIT_SIZE 4(or 6)"
+#ifndef MBN_FP_UNIT_SIZE
+ #error "define MBN_FP_UNIT_SIZE 4(or 6)"
#endif
#include <vector>
#include <string>
@@ -62,7 +62,7 @@ struct Id;
@param maxUnitSize [in] 4 or 6 (specify same value used in compiling for validation)
@note init() is not thread safe
*/
-void init(int curve = CurveFp254BNb, int maxUnitSize = BLS_FP_UNIT_SIZE);
+void init(int curve = CurveFp254BNb, int maxUnitSize = MBN_FP_UNIT_SIZE);
size_t getOpUnitSize();
void getCurveOrder(std::string& str);
void getFieldOrder(std::string& str);
@@ -77,7 +77,7 @@ class Id;
r = 0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d
sizeof(uint64_t) * keySize byte
*/
-const size_t keySize = BLS_FP_UNIT_SIZE;
+const size_t keySize = MBN_FP_UNIT_SIZE;
typedef std::vector<SecretKey> SecretKeyVec;
typedef std::vector<PublicKey> PublicKeyVec;
@@ -85,7 +85,7 @@ typedef std::vector<Signature> SignatureVec;
typedef std::vector<Id> IdVec;
class Id {
- uint64_t self_[BLS_FP_UNIT_SIZE];
+ uint64_t self_[MBN_FP_UNIT_SIZE];
friend class PublicKey;
friend class SecretKey;
template<class T, class G> friend struct WrapArray;
@@ -113,7 +113,7 @@ public:
s ; secret key
*/
class SecretKey {
- uint64_t self_[BLS_FP_UNIT_SIZE];
+ uint64_t self_[MBN_FP_UNIT_SIZE];
template<class T, class G> friend struct WrapArray;
impl::SecretKey& getInner() { return *reinterpret_cast<impl::SecretKey*>(self_); }
const impl::SecretKey& getInner() const { return *reinterpret_cast<const impl::SecretKey*>(self_); }
@@ -178,7 +178,7 @@ public:
sQ ; public key
*/
class PublicKey {
- uint64_t self_[BLS_FP_UNIT_SIZE * 2 * 3];
+ uint64_t self_[MBN_FP_UNIT_SIZE * 2 * 3];
friend class SecretKey;
friend class Signature;
template<class T, class G> friend struct WrapArray;
@@ -217,7 +217,7 @@ public:
s H(m) ; signature
*/
class Signature {
- uint64_t self_[BLS_FP_UNIT_SIZE * 3];
+ uint64_t self_[MBN_FP_UNIT_SIZE * 3];
friend class SecretKey;
template<class T, class G> friend struct WrapArray;
impl::Signature& getInner() { return *reinterpret_cast<impl::Signature*>(self_); }
diff --git a/src/bls.cpp b/src/bls.cpp
index fb3e404..92dcdda 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -9,14 +9,14 @@
#include <vector>
#include <string>
#include <bls/bls.hpp>
-#if BLS_FP_UNIT_SIZE == 4
+#if MBN_FP_UNIT_SIZE == 4
#include <mcl/bn256.hpp>
using namespace mcl::bn256;
-#elif BLS_FP_UNIT_SIZE == 6
+#elif MBN_FP_UNIT_SIZE == 6
#include <mcl/bn384.hpp>
using namespace mcl::bn384;
#else
- #error "define BLS_FP_UNIT_SIZE 4(or 6)"
+ #error "define MBN_FP_UNIT_SIZE 4(or 6)"
#endif
typedef std::vector<Fr> FrVec;
@@ -165,13 +165,13 @@ std::ostream& writeAsHex(std::ostream& os, const T& t)
void init(int curve, int maxUnitSize)
{
- if (maxUnitSize != BLS_FP_UNIT_SIZE) throw cybozu::Exception("bls:init:bad maxUnitSize") << maxUnitSize << BLS_FP_UNIT_SIZE;
+ if (maxUnitSize != MBN_FP_UNIT_SIZE) throw cybozu::Exception("bls:init:bad maxUnitSize") << maxUnitSize << MBN_FP_UNIT_SIZE;
mcl::bn::CurveParam cp;
switch (curve) {
case bls::CurveFp254BNb:
cp = mcl::bn::CurveFp254BNb;
break;
-#if BLS_FP_UNIT_SIZE == 6
+#if MBN_FP_UNIT_SIZE == 6
case bls::CurveFp382_1:
cp = mcl::bn::CurveFp382_1;
break;
diff --git a/test/bls_c384_test.cpp b/test/bls_c384_test.cpp
index 0b30e69..40aa3a3 100644
--- a/test/bls_c384_test.cpp
+++ b/test/bls_c384_test.cpp
@@ -66,7 +66,7 @@ CYBOZU_TEST_AUTO(all)
{
const int tbl[] = {
blsCurveFp254BNb,
-#if BLS_FP_UNIT_SIZE == 6
+#if MBN_FP_UNIT_SIZE == 6
blsCurveFp382_1,
blsCurveFp382_2
#endif
@@ -83,7 +83,7 @@ CYBOZU_TEST_AUTO(all)
};
for (size_t i = 0; i < sizeof(tbl) / sizeof(tbl[0]); i++) {
printf("i=%d\n", (int)i);
- blsInit(tbl[i], BLS_FP_UNIT_SIZE);
+ blsInit(tbl[i], MBN_FP_UNIT_SIZE);
bls_use_stackTest();
blsDataTest();
blsOrderTest(curveOrderTbl[i], fieldOrderTbl[i]);
diff --git a/test/bls_test.cpp b/test/bls_test.cpp
index 2eedd3d..22d6bf0 100644
--- a/test/bls_test.cpp
+++ b/test/bls_test.cpp
@@ -403,7 +403,7 @@ CYBOZU_TEST_AUTO(all)
const char *name;
} tbl[] = {
{ bls::CurveFp254BNb, "Fp254" },
-#if BLS_FP_UNIT_SIZE == 6
+#if MBN_FP_UNIT_SIZE == 6
{ bls::CurveFp382_1, "Fp382_1" },
{ bls::CurveFp382_2, "Fp382_2" },
#endif