aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-04-23 21:01:50 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-04-23 21:01:50 +0800
commitc7b481bb530f2632c05e58b779bf2c6ca0e4a8a2 (patch)
tree9d87317073648a9cc2c45d5bb53ea91fc863c993
parent947f42a7c84718e5a0434f69f1faff4adc01227f (diff)
downloaddexon-bls-c7b481bb530f2632c05e58b779bf2c6ca0e4a8a2.tar
dexon-bls-c7b481bb530f2632c05e58b779bf2c6ca0e4a8a2.tar.gz
dexon-bls-c7b481bb530f2632c05e58b779bf2c6ca0e4a8a2.tar.bz2
dexon-bls-c7b481bb530f2632c05e58b779bf2c6ca0e4a8a2.tar.lz
dexon-bls-c7b481bb530f2632c05e58b779bf2c6ca0e4a8a2.tar.xz
dexon-bls-c7b481bb530f2632c05e58b779bf2c6ca0e4a8a2.tar.zst
dexon-bls-c7b481bb530f2632c05e58b779bf2c6ca0e4a8a2.zip
add GetCurveOrder/GetFieldOrder to Go
-rw-r--r--Makefile3
-rw-r--r--go/bls/bls.go22
-rw-r--r--go/bls/bls_test.go27
3 files changed, 51 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 1e2e216..1dd0b76 100644
--- a/Makefile
+++ b/Makefile
@@ -66,7 +66,8 @@ 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/bls/bls.go go/bls/bls_test.go $(BLS_LIB) $(BLS_IF_LIB)
- cd go/bls && go test -tags $(GO_TAG) -v .
+ 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)
diff --git a/go/bls/bls.go b/go/bls/bls.go
index ec3fa1d..43183cb 100644
--- a/go/bls/bls.go
+++ b/go/bls/bls.go
@@ -35,6 +35,28 @@ func GetOpUnitSize() int {
return int(C.blsGetOpUnitSize())
}
+// GetCurveOrder --
+func GetCurveOrder() string {
+ buf := make([]byte, 1024)
+ // #nosec
+ n := C.blsGetCurveOrder((*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if n == 0 {
+ panic("implementation err. size of buf is small")
+ }
+ return string(buf[:n])
+}
+
+// GetCurveOrder --
+func GetFieldOrder() string {
+ buf := make([]byte, 1024)
+ // #nosec
+ n := C.blsGetFieldOrder((*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if n == 0 {
+ panic("implementation err. size of buf is small")
+ }
+ return string(buf[:n])
+}
+
// ID --
type ID struct {
v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t
diff --git a/go/bls/bls_test.go b/go/bls/bls_test.go
index 50f1b7e..4a8ccbf 100644
--- a/go/bls/bls_test.go
+++ b/go/bls/bls_test.go
@@ -228,6 +228,31 @@ func testData(t *testing.T) {
}
}
+func testOrder(t *testing.T, c int) {
+ var curve string
+ var field string
+ if c == CurveFp254BNb {
+ curve = "16798108731015832284940804142231733909759579603404752749028378864165570215949"
+ field = "16798108731015832284940804142231733909889187121439069848933715426072753864723"
+ } else if c == CurveFp382_1 {
+ curve = "5540996953667913971058039301942914304734176495422447785042938606876043190415948413757785063597439175372845535461389"
+ field = "5540996953667913971058039301942914304734176495422447785045292539108217242186829586959562222833658991069414454984723"
+ } else if c == CurveFp382_2 {
+ curve = "5541245505022739011583672869577435255026888277144126952448297309161979278754528049907713682488818304329661351460877"
+ field = "5541245505022739011583672869577435255026888277144126952450651294188487038640194767986566260919128250811286032482323"
+ } else {
+ t.Fatal("bad c", c)
+ }
+ var s string
+ s = GetCurveOrder()
+ if s != curve {
+ t.Errorf("bad curve order\n%s\n%s\n", s, curve)
+ }
+ s = GetFieldOrder()
+ if s != field {
+ t.Errorf("bad field order\n%s\n%s\n", s, field)
+ }
+}
func test(t *testing.T, c int) {
Init(c)
@@ -240,6 +265,7 @@ func test(t *testing.T, c int) {
testPop(t)
testData(t)
testStringConversion(t)
+ testOrder(t, c)
}
func TestMain(t *testing.T) {
@@ -257,6 +283,7 @@ func TestMain(t *testing.T) {
// Benchmarks
var curve = CurveFp382_1
+
//var curve = CurveFp254BNb
func BenchmarkPubkeyFromSeckey(b *testing.B) {