diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-06-05 20:58:19 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-06-05 20:58:19 +0800 |
commit | 2707ef159e0d988b8e4c0d9ed644a9e47deae3f4 (patch) | |
tree | 7398b3a533cefacfc4056d2ee15309cd72a45579 | |
parent | acf1c832c65429be7f07d8bae5ce91978f78e75f (diff) | |
download | dexon-bls-2707ef159e0d988b8e4c0d9ed644a9e47deae3f4.tar.gz dexon-bls-2707ef159e0d988b8e4c0d9ed644a9e47deae3f4.tar.zst dexon-bls-2707ef159e0d988b8e4c0d9ed644a9e47deae3f4.zip |
use struts of bn.h
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | go/bls/bls.go | 20 | ||||
-rw-r--r-- | include/bls/bls.h | 10 | ||||
-rw-r--r-- | include/bls/bls.hpp | 33 | ||||
-rw-r--r-- | src/bls.cpp | 10 | ||||
-rw-r--r-- | test/bls_c384_test.cpp | 4 | ||||
-rw-r--r-- | test/bls_test.cpp | 2 |
7 files changed, 41 insertions, 44 deletions
@@ -11,11 +11,11 @@ SAMPLE_SRC=bls_smpl.cpp bls_tool.cpp CFLAGS+=-I../mcl/include UNIT?=6 ifeq ($(UNIT),4) - CFLAGS+=-DMBN_FP_UNIT_SIZE=4 + CFLAGS+=-D"MCLBN_FP_UNIT_SIZE=4" GO_TAG=bn256 endif ifeq ($(UNIT),6) - CFLAGS+=-DMBN_FP_UNIT_SIZE=6 + CFLAGS+=-D"MCLBN_FP_UNIT_SIZE=6" GO_TAG=bn384 endif @@ -72,7 +72,7 @@ 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 $(BLS384_SLIB) +test_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 . diff --git a/go/bls/bls.go b/go/bls/bls.go index 7ca3553..e2421c5 100644 --- a/go/bls/bls.go +++ b/go/bls/bls.go @@ -1,7 +1,7 @@ package bls /* -#cgo CFLAGS:-DMBN_FP_UNIT_SIZE=6 +#cgo CFLAGS:-DMCLBN_FP_UNIT_SIZE=6 #cgo LDFLAGS:-lbls384 -lmclbn384 -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto #include <bls/bls.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.blsInit(C.int(curve), C.MBN_FP_UNIT_SIZE) + err := C.blsInit(C.int(curve), C.MCLBN_FP_UNIT_SIZE) if err != 0 { return fmt.Errorf("ERR Init curve=%d", curve) } @@ -31,7 +31,7 @@ func Init(curve int) error { // GetMaxOpUnitSize -- func GetMaxOpUnitSize() int { - return int(C.MBN_FP_UNIT_SIZE) + return int(C.MCLBN_FP_UNIT_SIZE) } // GetOpUnitSize -- @@ -63,13 +63,13 @@ func GetFieldOrder() string { // ID -- type ID struct { - v [C.MBN_FP_UNIT_SIZE]C.uint64_t + v C.mclBnFr } // getPointer -- func (id *ID) getPointer() (p *C.blsId) { // #nosec - return (*C.blsId)(unsafe.Pointer(&id.v[0])) + return (*C.blsId)(unsafe.Pointer(id)) } // GetLittleEndian -- @@ -144,7 +144,7 @@ func (id *ID) IsEqual(rhs *ID) bool { // SecretKey -- type SecretKey struct { - v [C.MBN_FP_UNIT_SIZE]C.uint64_t + v C.mclBnFr } // getPointer -- @@ -280,13 +280,13 @@ func (sec *SecretKey) GetPop() (sign *Sign) { // PublicKey -- type PublicKey struct { - v [C.MBN_FP_UNIT_SIZE * 2 * 3]C.uint64_t + v C.mclBnG2 } // getPointer -- func (pub *PublicKey) getPointer() (p *C.blsPublicKey) { // #nosec - return (*C.blsPublicKey)(unsafe.Pointer(&pub.v[0])) + return (*C.blsPublicKey)(unsafe.Pointer(pub)) } // Serialize -- @@ -362,13 +362,13 @@ func (pub *PublicKey) Recover(pubVec []PublicKey, idVec []ID) error { // Sign -- type Sign struct { - v [C.MBN_FP_UNIT_SIZE * 3]C.uint64_t + v C.mclBnG1 } // getPointer -- func (sign *Sign) getPointer() (p *C.blsSignature) { // #nosec - return (*C.blsSignature)(unsafe.Pointer(&sign.v[0])) + return (*C.blsSignature)(unsafe.Pointer(sign)) } // Serialize -- diff --git a/include/bls/bls.h b/include/bls/bls.h index cb84147..47b33cf 100644 --- a/include/bls/bls.h +++ b/include/bls/bls.h @@ -14,7 +14,7 @@ #else #define BLS_DLL_API __declspec(dllimport) #ifndef BLS_NO_AUTOLINK - #if MBN_FP_UNIT_SIZE == 4 + #if MCLBN_FP_UNIT_SIZE == 4 #pragma comment(lib, "bls256.lib") #endif #endif @@ -34,19 +34,19 @@ enum { }; typedef struct { - uint64_t buf[MBN_FP_UNIT_SIZE]; + mclBnFr v; } blsId; typedef struct { - uint64_t buf[MBN_FP_UNIT_SIZE]; + mclBnFr v; } blsSecretKey; typedef struct { - uint64_t buf[MBN_FP_UNIT_SIZE * 2 * 3]; + mclBnG2 v; } blsPublicKey; typedef struct { - uint64_t buf[MBN_FP_UNIT_SIZE * 3]; + mclBnG1 v; } blsSignature; /* diff --git a/include/bls/bls.hpp b/include/bls/bls.hpp index 1ac58d9..3eda465 100644 --- a/include/bls/bls.hpp +++ b/include/bls/bls.hpp @@ -6,16 +6,13 @@ @license modified new BSD license http://opensource.org/licenses/BSD-3-Clause */ -#ifndef MBN_FP_UNIT_SIZE - #error "define MBN_FP_UNIT_SIZE 4(or 6)" -#endif +#include <mcl/bn.h> #include <vector> #include <string> #include <iosfwd> #include <stdint.h> #ifdef _MSC_VER - #pragma comment(lib, "mcl.lib") #pragma comment(lib, "bls.lib") #endif @@ -62,7 +59,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 = MBN_FP_UNIT_SIZE); +void init(int curve = CurveFp254BNb, int maxUnitSize = MCLBN_FP_UNIT_SIZE); size_t getOpUnitSize(); void getCurveOrder(std::string& str); void getFieldOrder(std::string& str); @@ -77,7 +74,7 @@ class Id; r = 0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d sizeof(uint64_t) * keySize byte */ -const size_t keySize = MBN_FP_UNIT_SIZE; +const size_t keySize = MCLBN_FP_UNIT_SIZE; typedef std::vector<SecretKey> SecretKeyVec; typedef std::vector<PublicKey> PublicKeyVec; @@ -85,12 +82,12 @@ typedef std::vector<Signature> SignatureVec; typedef std::vector<Id> IdVec; class Id { - uint64_t self_[MBN_FP_UNIT_SIZE]; + mclBnFr self_; friend class PublicKey; friend class SecretKey; template<class T, class G> friend struct WrapArray; - impl::Id& getInner() { return *reinterpret_cast<impl::Id*>(self_); } - const impl::Id& getInner() const { return *reinterpret_cast<const impl::Id*>(self_); } + impl::Id& getInner() { return *reinterpret_cast<impl::Id*>(this); } + const impl::Id& getInner() const { return *reinterpret_cast<const impl::Id*>(this); } public: Id(unsigned int id = 0); bool operator==(const Id& rhs) const; @@ -113,10 +110,10 @@ public: s ; secret key */ class SecretKey { - uint64_t self_[MBN_FP_UNIT_SIZE]; + mclBnFr self_; 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_); } + impl::SecretKey& getInner() { return *reinterpret_cast<impl::SecretKey*>(this); } + const impl::SecretKey& getInner() const { return *reinterpret_cast<const impl::SecretKey*>(this); } public: SecretKey() : self_() {} bool operator==(const SecretKey& rhs) const; @@ -178,12 +175,12 @@ public: sQ ; public key */ class PublicKey { - uint64_t self_[MBN_FP_UNIT_SIZE * 2 * 3]; + mclBnG2 self_; friend class SecretKey; friend class Signature; template<class T, class G> friend struct WrapArray; - impl::PublicKey& getInner() { return *reinterpret_cast<impl::PublicKey*>(self_); } - const impl::PublicKey& getInner() const { return *reinterpret_cast<const impl::PublicKey*>(self_); } + impl::PublicKey& getInner() { return *reinterpret_cast<impl::PublicKey*>(this); } + const impl::PublicKey& getInner() const { return *reinterpret_cast<const impl::PublicKey*>(this); } public: PublicKey() : self_() {} bool operator==(const PublicKey& rhs) const; @@ -217,11 +214,11 @@ public: s H(m) ; signature */ class Signature { - uint64_t self_[MBN_FP_UNIT_SIZE * 3]; + mclBnG1 self_; friend class SecretKey; template<class T, class G> friend struct WrapArray; - impl::Signature& getInner() { return *reinterpret_cast<impl::Signature*>(self_); } - const impl::Signature& getInner() const { return *reinterpret_cast<const impl::Signature*>(self_); } + impl::Signature& getInner() { return *reinterpret_cast<impl::Signature*>(this); } + const impl::Signature& getInner() const { return *reinterpret_cast<const impl::Signature*>(this); } public: Signature() : self_() {} bool operator==(const Signature& rhs) const; diff --git a/src/bls.cpp b/src/bls.cpp index 92dcdda..d6f5bc0 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -9,14 +9,14 @@ #include <vector> #include <string> #include <bls/bls.hpp> -#if MBN_FP_UNIT_SIZE == 4 +#if MCLBN_FP_UNIT_SIZE == 4 #include <mcl/bn256.hpp> using namespace mcl::bn256; -#elif MBN_FP_UNIT_SIZE == 6 +#elif MCLBN_FP_UNIT_SIZE == 6 #include <mcl/bn384.hpp> using namespace mcl::bn384; #else - #error "define MBN_FP_UNIT_SIZE 4(or 6)" + #error "define MCLBN_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 != MBN_FP_UNIT_SIZE) throw cybozu::Exception("bls:init:bad maxUnitSize") << maxUnitSize << MBN_FP_UNIT_SIZE; + if (maxUnitSize != MCLBN_FP_UNIT_SIZE) throw cybozu::Exception("bls:init:bad maxUnitSize") << maxUnitSize << MCLBN_FP_UNIT_SIZE; mcl::bn::CurveParam cp; switch (curve) { case bls::CurveFp254BNb: cp = mcl::bn::CurveFp254BNb; break; -#if MBN_FP_UNIT_SIZE == 6 +#if MCLBN_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 40aa3a3..8405926 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 MBN_FP_UNIT_SIZE == 6 +#if MCLBN_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], MBN_FP_UNIT_SIZE); + blsInit(tbl[i], MCLBN_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 22d6bf0..7c587d6 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 MBN_FP_UNIT_SIZE == 6 +#if MCLBN_FP_UNIT_SIZE == 6 { bls::CurveFp382_1, "Fp382_1" }, { bls::CurveFp382_2, "Fp382_2" }, #endif |