rename bls_if.h to bls.h

dev
MITSUNARI Shigeo 8 years ago
parent 1682083203
commit 5a38c2e8c9
  1. 28
      Makefile
  2. 20
      go/bls/bls.go
  3. 16
      include/bls/bls.h
  4. 16
      include/bls/bls.hpp
  5. 10
      src/bls.cpp
  6. 2
      src/bls_c.cpp
  7. 18
      test/bls_c384_test.cpp
  8. 2
      test/bls_test.cpp

@ -4,18 +4,18 @@ OBJ_DIR=obj
EXE_DIR=bin EXE_DIR=bin
CFLAGS += -std=c++11 CFLAGS += -std=c++11
SRC_SRC=bls.cpp bls_if.cpp SRC_SRC=bls.cpp bls_c.cpp
TEST_SRC=bls_test.cpp bls_if_test.cpp TEST_SRC=bls_test.cpp bls_c384_test.cpp
SAMPLE_SRC=bls_smpl.cpp bls_tool.cpp SAMPLE_SRC=bls_smpl.cpp bls_tool.cpp
CFLAGS+=-I../mcl/include CFLAGS+=-I../mcl/include
UNIT?=6 UNIT?=6
ifeq ($(UNIT),4) ifeq ($(UNIT),4)
CFLAGS+=-DBLS_MAX_OP_UNIT_SIZE=4 CFLAGS+=-DBLS_FP_UNIT_SIZE=4
GO_TAG=bn256 GO_TAG=bn256
endif endif
ifeq ($(UNIT),6) ifeq ($(UNIT),6)
CFLAGS+=-DBLS_MAX_OP_UNIT_SIZE=6 CFLAGS+=-DBLS_FP_UNIT_SIZE=6
GO_TAG=bn384 GO_TAG=bn384
endif endif
@ -37,11 +37,11 @@ $(MCL_LIB):
################################################################## ##################################################################
BLS_IF_LIB=$(LIB_DIR)/libbls_if.a BLS384_LIB=$(LIB_DIR)/libbls384.a
lib: $(BLS_LIB) $(BLS_IF_LIB) lib: $(BLS_LIB) $(BLS384_LIB)
$(BLS_IF_LIB): $(LIB_OBJ) $(OBJ_DIR)/bls_if.o $(BLS384_LIB): $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
$(AR) $@ $(LIB_OBJ) $(OBJ_DIR)/bls_if.o $(AR) $@ $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
VPATH=test sample src VPATH=test sample src
@ -50,11 +50,11 @@ VPATH=test sample src
$(OBJ_DIR)/%.o: %.cpp $(OBJ_DIR)/%.o: %.cpp
$(PRE)$(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d) $(PRE)$(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d)
$(EXE_DIR)/%.exe: $(OBJ_DIR)/%.o $(BLS_LIB) $(MCL_LIB) $(OBJ_DIR)/bls_c384.o: bls_c.cpp
$(PRE)$(CXX) $< -o $@ $(BLS_LIB) -lmcl -L../mcl/lib $(LDFLAGS) $(PRE)$(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d) -DBLS_FP_UNIT_SIZE=6
$(EXE_DIR)/bls_if_test.exe: $(OBJ_DIR)/bls_if_test.o $(BLS_LIB) $(MCL_LIB) $(BLS_IF_LIB) $(EXE_DIR)/%.exe: $(OBJ_DIR)/%.o $(BLS_LIB) $(BLS384_LIB) $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(BLS_LIB) $(BLS_IF_LIB) -lmcl -L../mcl/lib $(LDFLAGS) $(PRE)$(CXX) $< -o $@ $(BLS_LIB) $(BLS384_LIB) -lmcl -L../mcl/lib $(LDFLAGS)
SAMPLE_EXE=$(addprefix $(EXE_DIR)/,$(SAMPLE_SRC:.cpp=.exe)) SAMPLE_EXE=$(addprefix $(EXE_DIR)/,$(SAMPLE_SRC:.cpp=.exe))
sample: $(SAMPLE_EXE) $(BLS_LIB) sample: $(SAMPLE_EXE) $(BLS_LIB)
@ -65,13 +65,13 @@ test: $(TEST_EXE)
@sh -ec 'for i in $(TEST_EXE); do $$i|grep "ctest:name"; done' > result.txt @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 @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) $(BLS_IF_LIB) 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 && env PKG_CONFIG_PATH=./ go test -tags $(GO_TAG) .
cd go/bls && go test -tags $(GO_TAG) . cd go/bls && go test -tags $(GO_TAG) .
# cd go/bls && go test -tags $(GO_TAG) -v . # cd go/bls && go test -tags $(GO_TAG) -v .
clean: clean:
$(RM) $(BLS_LIB) $(OBJ_DIR)/*.d $(OBJ_DIR)/*.o $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS_IF_LIB) $(RM) $(BLS_LIB) $(OBJ_DIR)/*.d $(OBJ_DIR)/*.o $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS384_LIB)
ALL_SRC=$(SRC_SRC) $(TEST_SRC) $(SAMPLE_SRC) ALL_SRC=$(SRC_SRC) $(TEST_SRC) $(SAMPLE_SRC)
DEPEND_FILE=$(addprefix $(OBJ_DIR)/, $(ALL_SRC:.cpp=.d)) DEPEND_FILE=$(addprefix $(OBJ_DIR)/, $(ALL_SRC:.cpp=.d))

@ -2,10 +2,10 @@ package bls
/* /*
#cgo CFLAGS:-I../../include #cgo CFLAGS:-I../../include
#cgo LDFLAGS:-lbls_if -lbls -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto -L../../lib -L../../../mcl/lib #cgo LDFLAGS:-lbls384 -lmcl -lgmpxx -lstdc++ -lgmp -lcrypto -L../../lib -L../../../mcl/lib
#cgo bn256 CFLAGS:-UBLS_MAX_OP_UNIT_SIZE -DBLS_MAX_OP_UNIT_SIZE=4 #cgo bn256 CFLAGS:-UBLS_FP_UNIT_SIZE -DBLS_FP_UNIT_SIZE=4
#cgo bn384 CFLAGS:-UBLS_MAX_OP_UNIT_SIZE -DBLS_MAX_OP_UNIT_SIZE=6 #cgo bn384 CFLAGS:-UBLS_FP_UNIT_SIZE -DBLS_FP_UNIT_SIZE=6
#include <bls/bls_if.h> #include <bls/bls.h>
*/ */
import "C" import "C"
import "fmt" import "fmt"
@ -24,7 +24,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.blsInit(C.int(curve), C.BLS_MAX_OP_UNIT_SIZE) err := C.blsInit(C.int(curve), C.BLS_FP_UNIT_SIZE)
if err != 0 { if err != 0 {
return fmt.Errorf("ERR Init curve=%d", curve) return fmt.Errorf("ERR Init curve=%d", curve)
} }
@ -33,7 +33,7 @@ func Init(curve int) error {
// GetMaxOpUnitSize -- // GetMaxOpUnitSize --
func GetMaxOpUnitSize() int { func GetMaxOpUnitSize() int {
return int(C.BLS_MAX_OP_UNIT_SIZE) return int(C.BLS_FP_UNIT_SIZE)
} }
// GetOpUnitSize -- // GetOpUnitSize --
@ -65,7 +65,7 @@ func GetFieldOrder() string {
// ID -- // ID --
type ID struct { type ID struct {
v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t v [C.BLS_FP_UNIT_SIZE]C.uint64_t
} }
// getPointer -- // getPointer --
@ -146,7 +146,7 @@ func (id *ID) IsEqual(rhs *ID) bool {
// SecretKey -- // SecretKey --
type SecretKey struct { type SecretKey struct {
v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t v [C.BLS_FP_UNIT_SIZE]C.uint64_t
} }
// getPointer -- // getPointer --
@ -282,7 +282,7 @@ func (sec *SecretKey) GetPop() (sign *Sign) {
// PublicKey -- // PublicKey --
type PublicKey struct { type PublicKey struct {
v [C.BLS_MAX_OP_UNIT_SIZE * 2 * 3]C.uint64_t v [C.BLS_FP_UNIT_SIZE * 2 * 3]C.uint64_t
} }
// getPointer -- // getPointer --
@ -364,7 +364,7 @@ func (pub *PublicKey) Recover(pubVec []PublicKey, idVec []ID) error {
// Sign -- // Sign --
type Sign struct { type Sign struct {
v [C.BLS_MAX_OP_UNIT_SIZE * 3]C.uint64_t v [C.BLS_FP_UNIT_SIZE * 3]C.uint64_t
} }
// 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 BLS_MAX_OP_UNIT_SIZE #ifndef BLS_FP_UNIT_SIZE
#error "define BLS_MAX_OP_UNIT_SIZE 4(or 6)" #error "define BLS_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,8 +19,8 @@
#else #else
#define BLS_DLL_API __declspec(dllimport) #define BLS_DLL_API __declspec(dllimport)
#ifndef BLS_NO_AUTOLINK #ifndef BLS_NO_AUTOLINK
#if BLS_MAX_OP_UNIT_SIZE == 4 #if BLS_FP_UNIT_SIZE == 4
#pragma comment(lib, "bls_if256.lib") #pragma comment(lib, "bls256.lib")
#endif #endif
#endif #endif
#endif #endif
@ -39,19 +39,19 @@ enum {
}; };
typedef struct { typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE]; uint64_t buf[BLS_FP_UNIT_SIZE];
} blsId; } blsId;
typedef struct { typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE]; uint64_t buf[BLS_FP_UNIT_SIZE];
} blsSecretKey; } blsSecretKey;
typedef struct { typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE * 2 * 3]; uint64_t buf[BLS_FP_UNIT_SIZE * 2 * 3];
} blsPublicKey; } blsPublicKey;
typedef struct { typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE * 3]; uint64_t buf[BLS_FP_UNIT_SIZE * 3];
} blsSignature; } blsSignature;
/* /*

@ -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 BLS_MAX_OP_UNIT_SIZE #ifndef BLS_FP_UNIT_SIZE
#error "define BLS_MAX_OP_UNIT_SIZE 4(or 6)" #error "define BLS_FP_UNIT_SIZE 4(or 6)"
#endif #endif
#include <vector> #include <vector>
#include <string> #include <string>
@ -62,7 +62,7 @@ struct Id;
@param maxUnitSize [in] 4 or 6 (specify same value used in compiling for validation) @param maxUnitSize [in] 4 or 6 (specify same value used in compiling for validation)
@note init() is not thread safe @note init() is not thread safe
*/ */
void init(int curve = CurveFp254BNb, int maxUnitSize = BLS_MAX_OP_UNIT_SIZE); void init(int curve = CurveFp254BNb, int maxUnitSize = BLS_FP_UNIT_SIZE);
size_t getOpUnitSize(); size_t getOpUnitSize();
void getCurveOrder(std::string& str); void getCurveOrder(std::string& str);
void getFieldOrder(std::string& str); void getFieldOrder(std::string& str);
@ -77,7 +77,7 @@ class Id;
r = 0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d r = 0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d
sizeof(uint64_t) * keySize byte sizeof(uint64_t) * keySize byte
*/ */
const size_t keySize = BLS_MAX_OP_UNIT_SIZE; const size_t keySize = BLS_FP_UNIT_SIZE;
typedef std::vector<SecretKey> SecretKeyVec; typedef std::vector<SecretKey> SecretKeyVec;
typedef std::vector<PublicKey> PublicKeyVec; typedef std::vector<PublicKey> PublicKeyVec;
@ -85,7 +85,7 @@ typedef std::vector<Signature> SignatureVec;
typedef std::vector<Id> IdVec; typedef std::vector<Id> IdVec;
class Id { class Id {
uint64_t self_[BLS_MAX_OP_UNIT_SIZE]; uint64_t self_[BLS_FP_UNIT_SIZE];
friend class PublicKey; friend class PublicKey;
friend class SecretKey; friend class SecretKey;
template<class T, class G> friend struct WrapArray; template<class T, class G> friend struct WrapArray;
@ -113,7 +113,7 @@ public:
s ; secret key s ; secret key
*/ */
class SecretKey { class SecretKey {
uint64_t self_[BLS_MAX_OP_UNIT_SIZE]; uint64_t self_[BLS_FP_UNIT_SIZE];
template<class T, class G> friend struct WrapArray; template<class T, class G> friend struct WrapArray;
impl::SecretKey& getInner() { return *reinterpret_cast<impl::SecretKey*>(self_); } impl::SecretKey& getInner() { return *reinterpret_cast<impl::SecretKey*>(self_); }
const impl::SecretKey& getInner() const { return *reinterpret_cast<const impl::SecretKey*>(self_); } const impl::SecretKey& getInner() const { return *reinterpret_cast<const impl::SecretKey*>(self_); }
@ -178,7 +178,7 @@ public:
sQ ; public key sQ ; public key
*/ */
class PublicKey { class PublicKey {
uint64_t self_[BLS_MAX_OP_UNIT_SIZE * 2 * 3]; uint64_t self_[BLS_FP_UNIT_SIZE * 2 * 3];
friend class SecretKey; friend class SecretKey;
friend class Signature; friend class Signature;
template<class T, class G> friend struct WrapArray; template<class T, class G> friend struct WrapArray;
@ -217,7 +217,7 @@ public:
s H(m) ; signature s H(m) ; signature
*/ */
class Signature { class Signature {
uint64_t self_[BLS_MAX_OP_UNIT_SIZE * 3]; uint64_t self_[BLS_FP_UNIT_SIZE * 3];
friend class SecretKey; friend class SecretKey;
template<class T, class G> friend struct WrapArray; template<class T, class G> friend struct WrapArray;
impl::Signature& getInner() { return *reinterpret_cast<impl::Signature*>(self_); } impl::Signature& getInner() { return *reinterpret_cast<impl::Signature*>(self_); }

@ -9,14 +9,14 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <bls/bls.hpp> #include <bls/bls.hpp>
#if BLS_MAX_OP_UNIT_SIZE == 4 #if BLS_FP_UNIT_SIZE == 4
#include <mcl/bn256.hpp> #include <mcl/bn256.hpp>
using namespace mcl::bn256; using namespace mcl::bn256;
#elif BLS_MAX_OP_UNIT_SIZE == 6 #elif BLS_FP_UNIT_SIZE == 6
#include <mcl/bn384.hpp> #include <mcl/bn384.hpp>
using namespace mcl::bn384; using namespace mcl::bn384;
#else #else
#error "define BLS_MAX_OP_UNIT_SIZE 4(or 6)" #error "define BLS_FP_UNIT_SIZE 4(or 6)"
#endif #endif
typedef std::vector<Fr> FrVec; typedef std::vector<Fr> FrVec;
@ -165,13 +165,13 @@ std::ostream& writeAsHex(std::ostream& os, const T& t)
void init(int curve, int maxUnitSize) void init(int curve, int maxUnitSize)
{ {
if (maxUnitSize != BLS_MAX_OP_UNIT_SIZE) throw cybozu::Exception("bls:init:bad maxUnitSize") << maxUnitSize << BLS_MAX_OP_UNIT_SIZE; if (maxUnitSize != BLS_FP_UNIT_SIZE) throw cybozu::Exception("bls:init:bad maxUnitSize") << maxUnitSize << BLS_FP_UNIT_SIZE;
mcl::bn::CurveParam cp; mcl::bn::CurveParam cp;
switch (curve) { switch (curve) {
case bls::CurveFp254BNb: case bls::CurveFp254BNb:
cp = mcl::bn::CurveFp254BNb; cp = mcl::bn::CurveFp254BNb;
break; break;
#if BLS_MAX_OP_UNIT_SIZE == 6 #if BLS_FP_UNIT_SIZE == 6
case bls::CurveFp382_1: case bls::CurveFp382_1:
cp = mcl::bn::CurveFp382_1; cp = mcl::bn::CurveFp382_1;
break; break;

@ -1,6 +1,6 @@
#include "bls/bls.hpp" #include "bls/bls.hpp"
#define BLS_DLL_EXPORT #define BLS_DLL_EXPORT
#include "bls/bls_if.h" #include "bls/bls.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <memory.h> #include <memory.h>

@ -1,8 +1,8 @@
#include <cybozu/test.hpp> #include <cybozu/test.hpp>
#include <bls/bls_if.h> #include <bls/bls.h>
#include <string.h> #include <string.h>
void bls_if_use_stackTest() void bls_use_stackTest()
{ {
blsSecretKey sec; blsSecretKey sec;
blsPublicKey pub; blsPublicKey pub;
@ -19,7 +19,7 @@ void bls_if_use_stackTest()
CYBOZU_TEST_ASSERT(blsVerify(&sig, &pub, msg, msgSize)); CYBOZU_TEST_ASSERT(blsVerify(&sig, &pub, msg, msgSize));
} }
void bls_ifDataTest() void blsDataTest()
{ {
const char *msg = "test test"; const char *msg = "test test";
const size_t msgSize = strlen(msg); const size_t msgSize = strlen(msg);
@ -50,7 +50,7 @@ void bls_ifDataTest()
CYBOZU_TEST_ASSERT(blsSignatureIsEqual(&sig1, &sig2)); CYBOZU_TEST_ASSERT(blsSignatureIsEqual(&sig1, &sig2));
} }
void bls_ifOrderTest(const char *curveOrder, const char *fieldOrder) void blsOrderTest(const char *curveOrder, const char *fieldOrder)
{ {
char buf[1024]; char buf[1024];
size_t len; size_t len;
@ -66,7 +66,7 @@ CYBOZU_TEST_AUTO(all)
{ {
const int tbl[] = { const int tbl[] = {
blsCurveFp254BNb, blsCurveFp254BNb,
#if BLS_MAX_OP_UNIT_SIZE == 6 #if BLS_FP_UNIT_SIZE == 6
blsCurveFp382_1, blsCurveFp382_1,
blsCurveFp382_2 blsCurveFp382_2
#endif #endif
@ -83,9 +83,9 @@ CYBOZU_TEST_AUTO(all)
}; };
for (size_t i = 0; i < sizeof(tbl) / sizeof(tbl[0]); i++) { for (size_t i = 0; i < sizeof(tbl) / sizeof(tbl[0]); i++) {
printf("i=%d\n", (int)i); printf("i=%d\n", (int)i);
blsInit(tbl[i], BLS_MAX_OP_UNIT_SIZE); blsInit(tbl[i], BLS_FP_UNIT_SIZE);
bls_if_use_stackTest(); bls_use_stackTest();
bls_ifDataTest(); blsDataTest();
bls_ifOrderTest(curveOrderTbl[i], fieldOrderTbl[i]); blsOrderTest(curveOrderTbl[i], fieldOrderTbl[i]);
} }
} }

@ -403,7 +403,7 @@ CYBOZU_TEST_AUTO(all)
const char *name; const char *name;
} tbl[] = { } tbl[] = {
{ bls::CurveFp254BNb, "Fp254" }, { bls::CurveFp254BNb, "Fp254" },
#if BLS_MAX_OP_UNIT_SIZE == 6 #if BLS_FP_UNIT_SIZE == 6
{ bls::CurveFp382_1, "Fp382_1" }, { bls::CurveFp382_1, "Fp382_1" },
{ bls::CurveFp382_2, "Fp382_2" }, { bls::CurveFp382_2, "Fp382_2" },
#endif #endif

Loading…
Cancel
Save