aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml8
-rw-r--r--Makefile12
-rw-r--r--go/blscgo/bls.go12
-rw-r--r--include/bls.hpp19
-rw-r--r--include/bls_if.h13
-rw-r--r--readme.md3
-rw-r--r--src/bls.cpp18
-rw-r--r--src/bls_if.cpp4
-rw-r--r--test/bls_if_test.cpp4
9 files changed, 60 insertions, 33 deletions
diff --git a/.travis.yml b/.travis.yml
index a1a46c3..0569d82 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,8 +12,8 @@ script:
- git clone https://github.com/herumi/mcl.git
- git clone https://github.com/herumi/bls.git
- cd bls
- - make test DEBUG=1
+ - make UNIT=4 test
+ - make UNIT=4 run_go
- make clean
- - make
- - make run_go
-
+ - make UNIT=6 test
+ - make UNIT=6 run_go
diff --git a/Makefile b/Makefile
index 7bc3616..7cb7e7f 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,14 @@ TEST_SRC=bls_test.cpp bls_if_test.cpp
SAMPLE_SRC=bls_smpl.cpp bls_tool.cpp
CFLAGS+=-I../mcl/include
+ifeq ($(UNIT),4)
+ CFLAGS+=-DBLS_MAX_OP_UNIT_SIZE=4
+ GO_TAG=bn256
+endif
+ifeq ($(UNIT),6)
+ CFLAGS+=-DBLS_MAX_OP_UNIT_SIZE=6
+ GO_TAG=bn384
+endif
sample_test: $(EXE_DIR)/bls_smpl.exe
python bls_smpl.py
@@ -63,12 +71,10 @@ test: $(TEST_EXE)
@grep -v "ng=0, exception=0" result.txt; if [ $$? -eq 1 ]; then echo "all unit tests succeed"; else exit 1; fi
run_go: go/main.go $(BLS_LIB) $(BLS_IF_LIB)
-# cd go && env GODEBUG=cgocheck=0 go run main.go
- cd go && go run main.go
+ cd go && go run -tags $(GO_TAG) main.go
clean:
$(RM) $(BLS_LIB) $(OBJ_DIR)/* $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS_IF_LIB)
- $(MAKE) -C ../mcl clean
ALL_SRC=$(SRC_SRC) $(TEST_SRC) $(SAMPLE_SRC)
DEPEND_FILE=$(addprefix $(OBJ_DIR)/, $(ALL_SRC:.cpp=.d))
diff --git a/go/blscgo/bls.go b/go/blscgo/bls.go
index f75945b..3d78ee0 100644
--- a/go/blscgo/bls.go
+++ b/go/blscgo/bls.go
@@ -2,6 +2,8 @@ package blscgo
/*
#cgo CFLAGS:-I../../include
+#cgo bn256 CFLAGS:-DBLS_MAX_OP_UNIT_SIZE=4
+#cgo bn384 CFLAGS:-DBLS_MAX_OP_UNIT_SIZE=6
#cgo LDFLAGS:-lbls -lbls_if -lmcl -lgmp -lgmpxx -L../lib -L../../lib -L../../../mcl/lib -L../../mcl/lib -lstdc++ -lcrypto
#include "bls_if.h"
*/
@@ -15,12 +17,12 @@ const CurveFp382_2 = 2
// Init --
func Init(curve int) {
- C.blsInit(C.int(curve))
+ C.blsInit(C.int(curve), C.BLS_MAX_OP_UNIT_SIZE)
}
// ID --
type ID struct {
- v [6]C.uint64_t
+ v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t
}
// getPointer --
@@ -63,7 +65,7 @@ func (id *ID) Set(v []uint64) error {
// SecretKey --
type SecretKey struct {
- v [6]C.uint64_t
+ v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t
}
// getPointer --
@@ -153,7 +155,7 @@ func (sec *SecretKey) GetPop() (sign *Sign) {
// PublicKey --
type PublicKey struct {
- v [6 * 2 * 3]C.uint64_t
+ v [C.BLS_MAX_OP_UNIT_SIZE * 2 * 3]C.uint64_t
}
// getPointer --
@@ -201,7 +203,7 @@ func (pub *PublicKey) Recover(pubVec []PublicKey, idVec []ID) {
// Sign --
type Sign struct {
- v [6 * 3]C.uint64_t
+ v [C.BLS_MAX_OP_UNIT_SIZE * 3]C.uint64_t
}
// getPointer --
diff --git a/include/bls.hpp b/include/bls.hpp
index 194f669..f0a3650 100644
--- a/include/bls.hpp
+++ b/include/bls.hpp
@@ -6,6 +6,9 @@
@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)"
+#endif
#include <vector>
#include <string>
#include <iosfwd>
@@ -46,8 +49,10 @@ struct Id;
/*
initialize this library
call this once before using the other method
+ @param curve [in] type of curve
+ @param maxUnitSize [in] 4 or 6 (specify same value used in compiling for validation)
*/
-void init(int curve = CurveFp254BNb);
+void init(int curve = CurveFp254BNb, int maxUnitSize = BLS_MAX_OP_UNIT_SIZE);
class SecretKey;
class PublicKey;
@@ -57,9 +62,9 @@ class Id;
/*
the value of secretKey and Id must be less than
r = 0x2523648240000001ba344d8000000007ff9f800000000010a10000000000000d
- sizeof(uint64_t) * keySize = 32-byte
+ sizeof(uint64_t) * keySize byte
*/
-const size_t keySize = 4;
+const size_t keySize = BLS_MAX_OP_UNIT_SIZE;
typedef std::vector<SecretKey> SecretKeyVec;
typedef std::vector<PublicKey> PublicKeyVec;
@@ -67,7 +72,7 @@ typedef std::vector<Sign> SignVec;
typedef std::vector<Id> IdVec;
class Id {
- uint64_t self_[6]; // 384-bit
+ uint64_t self_[BLS_MAX_OP_UNIT_SIZE];
friend class PublicKey;
friend class SecretKey;
template<class T, class G> friend struct WrapArray;
@@ -92,7 +97,7 @@ public:
s ; secret key
*/
class SecretKey {
- uint64_t self_[6]; // 384-bit
+ uint64_t self_[BLS_MAX_OP_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_); }
@@ -150,7 +155,7 @@ public:
sQ ; public key
*/
class PublicKey {
- uint64_t self_[6 * 2 * 3]; // 384-bit x 2 x 3
+ uint64_t self_[BLS_MAX_OP_UNIT_SIZE * 2 * 3];
friend class SecretKey;
friend class Sign;
template<class T, class G> friend struct WrapArray;
@@ -187,7 +192,7 @@ public:
s H(m) ; sign
*/
class Sign {
- uint64_t self_[6 * 3]; // 384-bit x 3
+ uint64_t self_[BLS_MAX_OP_UNIT_SIZE * 3];
friend class SecretKey;
template<class T, class G> friend struct WrapArray;
impl::Sign& getInner() { return *reinterpret_cast<impl::Sign*>(self_); }
diff --git a/include/bls_if.h b/include/bls_if.h
index d02d325..194d14f 100644
--- a/include/bls_if.h
+++ b/include/bls_if.h
@@ -6,6 +6,9 @@
@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)"
+#endif
#include <stdint.h> // for uint64_t, uint8_t
#include <stdlib.h> // for size_t
@@ -25,22 +28,22 @@ enum {
};
typedef struct {
- uint64_t buf[6];
+ uint64_t buf[BLS_MAX_OP_UNIT_SIZE];
} blsId;
typedef struct {
- uint64_t buf[6];
+ uint64_t buf[BLS_MAX_OP_UNIT_SIZE];
} blsSecretKey;
typedef struct {
- uint64_t buf[6 * 2 * 3];
+ uint64_t buf[BLS_MAX_OP_UNIT_SIZE * 2 * 3];
} blsPublicKey;
typedef struct {
- uint64_t buf[6 * 3];
+ uint64_t buf[BLS_MAX_OP_UNIT_SIZE * 3];
} blsSign;
-void blsInit(int curve);
+void blsInit(int curve, int maxUnitSize);
blsId *blsIdCreate(void);
void blsIdDestroy(blsId *id);
diff --git a/readme.md b/readme.md
index a0d2c13..b199678 100644
--- a/readme.md
+++ b/readme.md
@@ -18,10 +18,11 @@ git clone git://github.com/herumi/cybozulib_ext ; for only Windows
```
# Build and test for Linux
+Specifiy UNIT=4 or 6 always to make.
To make lib/libbls.a and test, run
```
cd bls
-make test
+make test UNIT=4
```
To make sample programs, run
```
diff --git a/src/bls.cpp b/src/bls.cpp
index ff747bf..a159373 100644
--- a/src/bls.cpp
+++ b/src/bls.cpp
@@ -4,14 +4,21 @@
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
-#include <bls.hpp>
-#include <mcl/bn384.hpp>
#include <cybozu/crypto.hpp>
#include <cybozu/random_generator.hpp>
#include <vector>
#include <string>
-
+#include <bls.hpp>
+#if BLS_MAX_OP_UNIT_SIZE == 4
+#include <mcl/bn256.hpp>
+using namespace mcl::bn256;
+#elif BLS_MAX_OP_UNIT_SIZE == 6
+#include <mcl/bn384.hpp>
using namespace mcl::bn384;
+#else
+ #error "define BLS_MAX_OP_UNIT_SIZE 4(or 6)"
+#endif
+
typedef std::vector<Fr> FrVec;
#define PUT(x) std::cout << #x << "=" << x << std::endl;
@@ -156,19 +163,22 @@ std::ostream& writeAsHex(std::ostream& os, const T& t)
return os << str;
}
-void init(int curve)
+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;
mcl::bn::CurveParam cp;
switch (curve) {
case bls::CurveFp254BNb:
cp = mcl::bn::CurveFp254BNb;
break;
+#if BLS_MAX_OP_UNIT_SIZE == 6
case bls::CurveFp382_1:
cp = mcl::bn::CurveFp382_1;
break;
case bls::CurveFp382_2:
cp = mcl::bn::CurveFp382_2;
break;
+#endif
default:
throw cybozu::Exception("bls:init:bad curve") << curve;
}
diff --git a/src/bls_if.cpp b/src/bls_if.cpp
index 091bace..05ba0e8 100644
--- a/src/bls_if.cpp
+++ b/src/bls_if.cpp
@@ -43,9 +43,9 @@ size_t getStrT(const Outer *p, char *buf, size_t maxBufSize)
return 0;
}
-void blsInit(int curve)
+void blsInit(int curve, int maxUnitSize)
{
- bls::init(curve);
+ bls::init(curve, maxUnitSize);
}
blsId *blsIdCreate()
diff --git a/test/bls_if_test.cpp b/test/bls_if_test.cpp
index 84a2961..e93d85d 100644
--- a/test/bls_if_test.cpp
+++ b/test/bls_if_test.cpp
@@ -10,7 +10,7 @@ CYBOZU_TEST_AUTO(bls_if)
const char *msg = "this is a pen";
const size_t msgSize = strlen(msg);
- blsInit(BlsCurveFp254BNb);
+ blsInit(BlsCurveFp254BNb, BLS_MAX_OP_UNIT_SIZE);
sec = blsSecretKeyCreate();
blsSecretKeyInit(sec);
blsSecretKeyPut(sec);
@@ -38,7 +38,7 @@ CYBOZU_TEST_AUTO(bls_if_use_stack)
const char *msg = "this is a pen";
const size_t msgSize = strlen(msg);
- blsInit(BlsCurveFp254BNb);
+ blsInit(BlsCurveFp254BNb, BLS_MAX_OP_UNIT_SIZE);
blsSecretKeyInit(&sec);
blsSecretKeyPut(&sec);