aboutsummaryrefslogtreecommitdiffstats
path: root/go/blscgo
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-04-14 08:54:12 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-04-14 08:54:12 +0800
commit737475faeaca06f65f1a95db810ba2aa6f83e422 (patch)
tree7b273c688ee3a21ddf2cd8ae5511fba6910b7917 /go/blscgo
parentfb2abdeec5ce179e70c198ffd500272ba0c33e13 (diff)
downloaddexon-bls-737475faeaca06f65f1a95db810ba2aa6f83e422.tar
dexon-bls-737475faeaca06f65f1a95db810ba2aa6f83e422.tar.gz
dexon-bls-737475faeaca06f65f1a95db810ba2aa6f83e422.tar.bz2
dexon-bls-737475faeaca06f65f1a95db810ba2aa6f83e422.tar.lz
dexon-bls-737475faeaca06f65f1a95db810ba2aa6f83e422.tar.xz
dexon-bls-737475faeaca06f65f1a95db810ba2aa6f83e422.tar.zst
dexon-bls-737475faeaca06f65f1a95db810ba2aa6f83e422.zip
rename go/blscgo to go/bls
Diffstat (limited to 'go/blscgo')
-rw-r--r--go/blscgo/bls.go366
1 files changed, 0 insertions, 366 deletions
diff --git a/go/blscgo/bls.go b/go/blscgo/bls.go
deleted file mode 100644
index ae16a4c..0000000
--- a/go/blscgo/bls.go
+++ /dev/null
@@ -1,366 +0,0 @@
-package blscgo
-
-/*
-#cgo CFLAGS:-I../../include -DBLS_MAX_OP_UNIT_SIZE=6
-#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
-#cgo LDFLAGS:-lbls -lbls_if -lmcl -lgmp -lgmpxx -L../lib -L../../lib -L../../../mcl/lib -L../../mcl/lib -lstdc++ -lcrypto
-#include "bls_if.h"
-*/
-import "C"
-import "fmt"
-import "unsafe"
-
-// CurveFp254BNb -- 254 bit curve
-const CurveFp254BNb = 0
-
-// CurveFp382_1 -- 382 bit curve 1
-const CurveFp382_1 = 1
-
-// CurveFp382_2 -- 382 bit curve 2
-const CurveFp382_2 = 2
-
-// Init --
-func Init(curve int) {
- C.blsInit(C.int(curve), C.BLS_MAX_OP_UNIT_SIZE)
-}
-
-// GetMaxOpUnitSize --
-func GetMaxOpUnitSize() int {
- return int(C.BLS_MAX_OP_UNIT_SIZE)
-}
-
-// GetOpUnitSize --
-func GetOpUnitSize() int {
- return int(C.blsGetOpUnitSize())
-}
-
-// ID --
-type ID struct {
- v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t
-}
-
-// getPointer --
-func (id *ID) getPointer() (p *C.blsId) {
- // #nosec
- return (*C.blsId)(unsafe.Pointer(&id.v[0]))
-}
-
-// String --
-func (id *ID) String() string {
- buf := make([]byte, 1024)
- // #nosec
- n := C.blsIdGetStr(id.getPointer(), (*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])
-}
-
-// SetStr --
-func (id *ID) SetStr(s string) error {
- buf := []byte(s)
- // #nosec
- err := C.blsIdSetStr(id.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if err > 0 {
- return fmt.Errorf("bad string:%s", s)
- }
- return nil
-}
-
-// Set --
-func (id *ID) Set(v []uint64) {
- expect := GetOpUnitSize()
- if len(v) != expect {
- panic(fmt.Errorf("bad size (%d), expected size %d", len(v), expect))
- }
- // #nosec
- C.blsIdSet(id.getPointer(), (*C.uint64_t)(unsafe.Pointer(&v[0])))
-}
-
-// SecretKey --
-type SecretKey struct {
- v [C.BLS_MAX_OP_UNIT_SIZE]C.uint64_t
-}
-
-// getPointer --
-func (sec *SecretKey) getPointer() (p *C.blsSecretKey) {
- // #nosec
- return (*C.blsSecretKey)(unsafe.Pointer(&sec.v[0]))
-}
-
-// String --
-func (sec *SecretKey) String() string {
- buf := make([]byte, 1024)
- // #nosec
- n := C.blsSecretKeyGetStr(sec.getPointer(), (*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])
-}
-
-// SetStr -- The string passed in is a number and can be either hex or decimal
-func (sec *SecretKey) SetStr(s string) error {
- buf := []byte(s)
- // #nosec
- err := C.blsSecretKeySetStr(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if err > 0 {
- return fmt.Errorf("bad string:%s", s)
- }
- return nil
-}
-
-// SetData --
-func (sec *SecretKey) SetData(buf []byte) error {
- // #nosec
- err := C.blsSecretKeySetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if err > 0 {
- return fmt.Errorf("bad buf:%s", buf)
- }
- return nil
-}
-
-// GetData --
-func (sec *SecretKey) GetData() []byte {
- fpSize := GetOpUnitSize() * 8
- buf := make([]byte, fpSize)
- n := C.blsSecretKeyGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if n != C.size_t(fpSize) {
- panic("implementation err. size of buf is small")
- }
- return buf
-}
-
-// IsSame --
-func (lhs *SecretKey) IsSame(rhs *SecretKey) bool {
- return C.blsSecretKeyIsSame(lhs.getPointer(), rhs.getPointer()) == 1
-}
-
-// SetArray --
-func (sec *SecretKey) SetArray(v []uint64) {
- expect := GetOpUnitSize()
- if len(v) != expect {
- panic(fmt.Errorf("bad size (%d), expected size %d", len(v), expect))
- }
- // #nosec
- C.blsSecretKeySetArray(sec.getPointer(), (*C.uint64_t)(unsafe.Pointer(&v[0])))
-}
-
-// Init --
-func (sec *SecretKey) Init() {
- C.blsSecretKeyInit(sec.getPointer())
-}
-
-// Add --
-func (sec *SecretKey) Add(rhs *SecretKey) {
- C.blsSecretKeyAdd(sec.getPointer(), rhs.getPointer())
-}
-
-// GetMasterSecretKey --
-func (sec *SecretKey) GetMasterSecretKey(k int) (msk []SecretKey) {
- msk = make([]SecretKey, k)
- msk[0] = *sec
- for i := 1; i < k; i++ {
- msk[i].Init()
- }
- return msk
-}
-
-// GetMasterPublicKey --
-func GetMasterPublicKey(msk []SecretKey) (mpk []PublicKey) {
- n := len(msk)
- mpk = make([]PublicKey, n)
- for i := 0; i < n; i++ {
- mpk[i] = *msk[i].GetPublicKey()
- }
- return mpk
-}
-
-// Set --
-func (sec *SecretKey) Set(msk []SecretKey, id *ID) {
- C.blsSecretKeySet(sec.getPointer(), msk[0].getPointer(), C.size_t(len(msk)), id.getPointer())
-}
-
-// Recover --
-func (sec *SecretKey) Recover(secVec []SecretKey, idVec []ID) {
- C.blsSecretKeyRecover(sec.getPointer(), secVec[0].getPointer(), idVec[0].getPointer(), C.size_t(len(secVec)))
-}
-
-// GetPop --
-func (sec *SecretKey) GetPop() (sign *Sign) {
- sign = new(Sign)
- C.blsSecretKeyGetPop(sec.getPointer(), sign.getPointer())
- return sign
-}
-
-// PublicKey --
-type PublicKey struct {
- v [C.BLS_MAX_OP_UNIT_SIZE * 2 * 3]C.uint64_t
-}
-
-// getPointer --
-func (pub *PublicKey) getPointer() (p *C.blsPublicKey) {
- // #nosec
- return (*C.blsPublicKey)(unsafe.Pointer(&pub.v[0]))
-}
-
-// String --
-func (pub *PublicKey) String() string {
- buf := make([]byte, 1024)
- // #nosec
- n := C.blsPublicKeyGetStr(pub.getPointer(), (*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])
-}
-
-// SetStr --
-func (pub *PublicKey) SetStr(s string) error {
- buf := []byte(s)
- // #nosec
- err := C.blsPublicKeySetStr(pub.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if err > 0 {
- return fmt.Errorf("bad string:%s", s)
- }
- return nil
-}
-
-// SetData --
-func (sec *PublicKey) SetData(buf []byte) error {
- // #nosec
- err := C.blsPublicKeySetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if err > 0 {
- return fmt.Errorf("bad buf:%s", buf)
- }
- return nil
-}
-
-// GetData --
-func (sec *PublicKey) GetData() []byte {
- fpSize := GetOpUnitSize() * 8
- buf := make([]byte, fpSize*2)
- n := C.blsPublicKeyGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if n != C.size_t(fpSize*2) {
- panic("implementation err. size of buf is small")
- }
- return buf
-}
-
-// IsSame --
-func (lhs *PublicKey) IsSame(rhs *PublicKey) bool {
- return C.blsPublicKeyIsSame(lhs.getPointer(), rhs.getPointer()) == 1
-}
-
-// Add --
-func (pub *PublicKey) Add(rhs *PublicKey) {
- C.blsPublicKeyAdd(pub.getPointer(), rhs.getPointer())
-}
-
-// Set --
-func (pub *PublicKey) Set(mpk []PublicKey, id *ID) {
- C.blsPublicKeySet(pub.getPointer(), mpk[0].getPointer(), C.size_t(len(mpk)), id.getPointer())
-}
-
-// Recover --
-func (pub *PublicKey) Recover(pubVec []PublicKey, idVec []ID) {
- C.blsPublicKeyRecover(pub.getPointer(), pubVec[0].getPointer(), idVec[0].getPointer(), C.size_t(len(pubVec)))
-}
-
-// Sign --
-type Sign struct {
- v [C.BLS_MAX_OP_UNIT_SIZE * 3]C.uint64_t
-}
-
-// getPointer --
-func (sign *Sign) getPointer() (p *C.blsSign) {
- // #nosec
- return (*C.blsSign)(unsafe.Pointer(&sign.v[0]))
-}
-
-// String --
-func (sign *Sign) String() string {
- buf := make([]byte, 1024)
- // #nosec
- n := C.blsSignGetStr(sign.getPointer(), (*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])
-}
-
-// SetStr --
-func (sign *Sign) SetStr(s string) error {
- buf := []byte(s)
- // #nosec
- err := C.blsSignSetStr(sign.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if err > 0 {
- return fmt.Errorf("bad string:%s", s)
- }
- return nil
-}
-
-// SetData --
-func (sec *Sign) SetData(buf []byte) error {
- // #nosec
- err := C.blsSignSetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if err > 0 {
- return fmt.Errorf("bad buf:%s", buf)
- }
- return nil
-}
-
-// GetData --
-func (sec *Sign) GetData() []byte {
- fpSize := GetOpUnitSize() * 8
- buf := make([]byte, fpSize)
- n := C.blsSignGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if n != C.size_t(fpSize) {
- panic("implementation err. size of buf is small")
- }
- return buf
-}
-
-// IsSame --
-func (lhs *Sign) IsSame(rhs *Sign) bool {
- return C.blsSignIsSame(lhs.getPointer(), rhs.getPointer()) == 1
-}
-
-// GetPublicKey --
-func (sec *SecretKey) GetPublicKey() (pub *PublicKey) {
- pub = new(PublicKey)
- C.blsSecretKeyGetPublicKey(sec.getPointer(), pub.getPointer())
- return pub
-}
-
-// Sign -- Constant Time version
-func (sec *SecretKey) Sign(m string) (sign *Sign) {
- sign = new(Sign)
- buf := []byte(m)
- // #nosec
- C.blsSecretKeySign(sec.getPointer(), sign.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- return sign
-}
-
-// Add --
-func (sign *Sign) Add(rhs *Sign) {
- C.blsSignAdd(sign.getPointer(), rhs.getPointer())
-}
-
-// Recover --
-func (sign *Sign) Recover(signVec []Sign, idVec []ID) {
- C.blsSignRecover(sign.getPointer(), signVec[0].getPointer(), idVec[0].getPointer(), C.size_t(len(signVec)))
-}
-
-// Verify --
-func (sign *Sign) Verify(pub *PublicKey, m string) bool {
- buf := []byte(m)
- // #nosec
- return C.blsSignVerify(sign.getPointer(), pub.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))) == 1
-}
-
-// VerifyPop --
-func (sign *Sign) VerifyPop(pub *PublicKey) bool {
- return C.blsSignVerifyPop(sign.getPointer(), pub.getPointer()) == 1
-}