Skip to content
Snippets Groups Projects
Commit e9658059 authored by lunfardo314's avatar lunfardo314
Browse files

added BLS-BDN signature scheme and address

parent 698b605e
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,6 @@ func RandBLS_BDN() SignatureScheme { ...@@ -36,7 +36,6 @@ func RandBLS_BDN() SignatureScheme {
} }
func (sigscheme *blsBdnSignatureScheme) Version() byte { func (sigscheme *blsBdnSignatureScheme) Version() byte {
suite.ScalarLen()
return address.VERSION_BLS_BDN return address.VERSION_BLS_BDN
} }
...@@ -57,10 +56,10 @@ func (sigscheme *blsBdnSignatureScheme) Sign(data []byte) Signature { ...@@ -57,10 +56,10 @@ func (sigscheme *blsBdnSignatureScheme) Sign(data []byte) Signature {
if err != nil { if err != nil {
panic(err) panic(err)
} }
return &blsBdnSignature{ ret := &blsBdnSignature{}
pubKey: pubKeyBin, copy(ret.pubKey[:], pubKeyBin)
signature: sig, copy(ret.signature[:], sig)
} return ret
} }
// interface contract (allow the compiler to check if the implementation has all of the required methods). // interface contract (allow the compiler to check if the implementation has all of the required methods).
...@@ -68,31 +67,36 @@ var _ SignatureScheme = &blsBdnSignatureScheme{} ...@@ -68,31 +67,36 @@ var _ SignatureScheme = &blsBdnSignatureScheme{}
// BLS-BDN signature, in binary marshaled form // BLS-BDN signature, in binary marshaled form
const (
BLS_SIGNATURE_SIZE = 64
BLS_PUBLIC_KEY_SIZE = 128
)
type blsBdnSignature struct { type blsBdnSignature struct {
pubKey []byte pubKey [BLS_PUBLIC_KEY_SIZE]byte
signature []byte signature [BLS_SIGNATURE_SIZE]byte
} }
func (sig *blsBdnSignature) IsValid(signedData []byte) bool { func (sig *blsBdnSignature) IsValid(signedData []byte) bool {
// unmarshal public key // unmarshal public key
pubKey := suite.G2().Point() pubKey := suite.G2().Point()
if err := pubKey.UnmarshalBinary(sig.pubKey); err != nil { if err := pubKey.UnmarshalBinary(sig.pubKey[:]); err != nil {
return false return false
} }
return bdn.Verify(suite, pubKey, signedData, sig.signature) == nil return bdn.Verify(suite, pubKey, signedData, sig.signature[:]) == nil
} }
func (sig *blsBdnSignature) Bytes() []byte { func (sig *blsBdnSignature) Bytes() []byte {
b := make([]byte, 1+len(sig.pubKey)+len(sig.signature)) b := make([]byte, 1+BLS_PUBLIC_KEY_SIZE+BLS_SIGNATURE_SIZE)
buf := bytes.NewBuffer(b) buf := bytes.NewBuffer(b)
buf.WriteByte(address.VERSION_BLS_BDN) buf.WriteByte(address.VERSION_BLS_BDN)
buf.Write(sig.pubKey) buf.Write(sig.pubKey[:])
buf.Write(sig.signature) buf.Write(sig.signature[:])
return b return b
} }
func (sig *blsBdnSignature) Address() address.Address { func (sig *blsBdnSignature) Address() address.Address {
return address.FromBLSPubKey(sig.pubKey) return address.FromBLSPubKey(sig.pubKey[:])
} }
// interface contract (allow the compiler to check if the implementation has all of the required methods). // interface contract (allow the compiler to check if the implementation has all of the required methods).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment