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
CFLAGS += -std=c++11
SRC_SRC=bls.cpp bls_if.cpp
TEST_SRC=bls_test.cpp bls_if_test.cpp
SRC_SRC=bls.cpp bls_c.cpp
TEST_SRC=bls_test.cpp bls_c384_test.cpp
SAMPLE_SRC=bls_smpl.cpp bls_tool.cpp
CFLAGS+=-I../mcl/include
UNIT?=6
ifeq ($(UNIT),4)
CFLAGS+=-DBLS_MAX_OP_UNIT_SIZE=4
CFLAGS+=-DBLS_FP_UNIT_SIZE=4
GO_TAG=bn256
endif
ifeq ($(UNIT),6)
CFLAGS+=-DBLS_MAX_OP_UNIT_SIZE=6
CFLAGS+=-DBLS_FP_UNIT_SIZE=6
GO_TAG=bn384
endif
@ -37,11 +37,11 @@ $(MCL_LIB):
##################################################################
BLS_IF_LIB=$(LIB_DIR)/libbls_if.a
lib: $(BLS_LIB) $(BLS_IF_LIB)
BLS384_LIB=$(LIB_DIR)/libbls384.a
lib: $(BLS_LIB) $(BLS384_LIB)
$(BLS_IF_LIB): $(LIB_OBJ) $(OBJ_DIR)/bls_if.o
$(AR) $@ $(LIB_OBJ) $(OBJ_DIR)/bls_if.o
$(BLS384_LIB): $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
$(AR) $@ $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
VPATH=test sample src
@ -50,11 +50,11 @@ VPATH=test sample src
$(OBJ_DIR)/%.o: %.cpp
$(PRE)$(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d)
$(EXE_DIR)/%.exe: $(OBJ_DIR)/%.o $(BLS_LIB) $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(BLS_LIB) -lmcl -L../mcl/lib $(LDFLAGS)
$(OBJ_DIR)/bls_c384.o: bls_c.cpp
$(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)
$(PRE)$(CXX) $< -o $@ $(BLS_LIB) $(BLS_IF_LIB) -lmcl -L../mcl/lib $(LDFLAGS)
$(EXE_DIR)/%.exe: $(OBJ_DIR)/%.o $(BLS_LIB) $(BLS384_LIB) $(MCL_LIB)
$(PRE)$(CXX) $< -o $@ $(BLS_LIB) $(BLS384_LIB) -lmcl -L../mcl/lib $(LDFLAGS)
SAMPLE_EXE=$(addprefix $(EXE_DIR)/,$(SAMPLE_SRC:.cpp=.exe))
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
@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 && go test -tags $(GO_TAG) .
# 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) $(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)
DEPEND_FILE=$(addprefix $(OBJ_DIR)/, $(ALL_SRC:.cpp=.d))

@ -2,10 +2,10 @@ package bls
/*
#cgo CFLAGS:-I../../include
#cgo LDFLAGS:-lbls_if -lbls -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 bn384 CFLAGS:-UBLS_MAX_OP_UNIT_SIZE -DBLS_MAX_OP_UNIT_SIZE=6
#include <bls/bls_if.h>
#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
#include <bls/bls.h>
*/
import "C"
import "fmt"
@ -24,7 +24,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_MAX_OP_UNIT_SIZE)
err := C.blsInit(C.int(curve), C.BLS_FP_UNIT_SIZE)
if err != 0 {
return fmt.Errorf("ERR Init curve=%d", curve)
}
@ -33,7 +33,7 @@ func Init(curve int) error {
// GetMaxOpUnitSize --
func GetMaxOpUnitSize() int {
return int(C.BLS_MAX_OP_UNIT_SIZE)
return int(C.BLS_FP_UNIT_SIZE)
}
// GetOpUnitSize --
@ -65,7 +65,7 @@ func GetFieldOrder() string {
// ID --
type ID struct {
v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t
v [C.BLS_FP_UNIT_SIZE]C.uint64_t
}
// getPointer --
@ -146,7 +146,7 @@ func (id *ID) IsEqual(rhs *ID) bool {
// SecretKey --
type SecretKey struct {
v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t
v [C.BLS_FP_UNIT_SIZE]C.uint64_t
}
// getPointer --
@ -282,7 +282,7 @@ func (sec *SecretKey) GetPop() (sign *Sign) {
// PublicKey --
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 --
@ -364,7 +364,7 @@ func (pub *PublicKey) Recover(pubVec []PublicKey, idVec []ID) error {
// Sign --
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 --

@ -6,8 +6,8 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#ifndef BLS_MAX_OP_UNIT_SIZE
#error "define BLS_MAX_OP_UNIT_SIZE 4(or 6)"
#ifndef BLS_FP_UNIT_SIZE
#error "define BLS_FP_UNIT_SIZE 4(or 6)"
#endif
#include <stdint.h> // for uint64_t, uint8_t
@ -19,8 +19,8 @@
#else
#define BLS_DLL_API __declspec(dllimport)
#ifndef BLS_NO_AUTOLINK
#if BLS_MAX_OP_UNIT_SIZE == 4
#pragma comment(lib, "bls_if256.lib")
#if BLS_FP_UNIT_SIZE == 4
#pragma comment(lib, "bls256.lib")
#endif
#endif
#endif
@ -39,19 +39,19 @@ enum {
};
typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE];
uint64_t buf[BLS_FP_UNIT_SIZE];
} blsId;
typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE];
uint64_t buf[BLS_FP_UNIT_SIZE];
} blsSecretKey;
typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE * 2 * 3];
uint64_t buf[BLS_FP_UNIT_SIZE * 2 * 3];
} blsPublicKey;
typedef struct {
uint64_t buf[BLS_MAX_OP_UNIT_SIZE * 3];
uint64_t buf[BLS_FP_UNIT_SIZE * 3];
} blsSignature;
/*

@ -6,8 +6,8 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#ifndef BLS_MAX_OP_UNIT_SIZE
#error "define BLS_MAX_OP_UNIT_SIZE 4(or 6)"
#ifndef BLS_FP_UNIT_SIZE
#error "define BLS_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_MAX_OP_UNIT_SIZE);
void init(int curve = CurveFp254BNb, int maxUnitSize = BLS_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_MAX_OP_UNIT_SIZE;
const size_t keySize = BLS_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_MAX_OP_UNIT_SIZE];
uint64_t self_[BLS_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_MAX_OP_UNIT_SIZE];
uint64_t self_[BLS_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_MAX_OP_UNIT_SIZE * 2 * 3];
uint64_t self_[BLS_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_MAX_OP_UNIT_SIZE * 3];
uint64_t self_[BLS_FP_UNIT_SIZE * 3];
friend class SecretKey;
template<class T, class G> friend struct WrapArray;
impl::Signature& getInner() { return *reinterpret_cast<impl::Signature*>(self_); }

@ -9,14 +9,14 @@
#include <vector>
#include <string>
#include <bls/bls.hpp>
#if BLS_MAX_OP_UNIT_SIZE == 4
#if BLS_FP_UNIT_SIZE == 4
#include <mcl/bn256.hpp>
using namespace mcl::bn256;
#elif BLS_MAX_OP_UNIT_SIZE == 6
#elif BLS_FP_UNIT_SIZE == 6
#include <mcl/bn384.hpp>
using namespace mcl::bn384;
#else
#error "define BLS_MAX_OP_UNIT_SIZE 4(or 6)"
#error "define BLS_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_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;
switch (curve) {
case bls::CurveFp254BNb:
cp = mcl::bn::CurveFp254BNb;
break;
#if BLS_MAX_OP_UNIT_SIZE == 6
#if BLS_FP_UNIT_SIZE == 6
case bls::CurveFp382_1:
cp = mcl::bn::CurveFp382_1;
break;

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

@ -1,8 +1,8 @@
#include <cybozu/test.hpp>
#include <bls/bls_if.h>
#include <bls/bls.h>
#include <string.h>
void bls_if_use_stackTest()
void bls_use_stackTest()
{
blsSecretKey sec;
blsPublicKey pub;
@ -19,7 +19,7 @@ void bls_if_use_stackTest()
CYBOZU_TEST_ASSERT(blsVerify(&sig, &pub, msg, msgSize));
}
void bls_ifDataTest()
void blsDataTest()
{
const char *msg = "test test";
const size_t msgSize = strlen(msg);
@ -50,7 +50,7 @@ void bls_ifDataTest()
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];
size_t len;
@ -66,7 +66,7 @@ CYBOZU_TEST_AUTO(all)
{
const int tbl[] = {
blsCurveFp254BNb,
#if BLS_MAX_OP_UNIT_SIZE == 6
#if BLS_FP_UNIT_SIZE == 6
blsCurveFp382_1,
blsCurveFp382_2
#endif
@ -83,9 +83,9 @@ 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_MAX_OP_UNIT_SIZE);
bls_if_use_stackTest();
bls_ifDataTest();
bls_ifOrderTest(curveOrderTbl[i], fieldOrderTbl[i]);
blsInit(tbl[i], BLS_FP_UNIT_SIZE);
bls_use_stackTest();
blsDataTest();
blsOrderTest(curveOrderTbl[i], fieldOrderTbl[i]);
}
}

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

Loading…
Cancel
Save