github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/singhdas/verifier.go (about)

     1  package singhdas
     2  
     3  import (
     4  	"github.com/ronperry/cryptoedge/eccutil"
     5  )
     6  
     7  // Verify verifies that a signature signs message by the signer defined in SignerClient
     8  func (client SignerClient) Verify(message []byte, signature *SignatureInt) (bool, error) {
     9  	Hm := client.curve.GenHash(message)
    10  	if Hm.Cmp(signature.Hm) != 0 {
    11  		return false, eccutil.ErrHashDif
    12  	}
    13  	SG := client.curve.ScalarBaseMult(signature.S.Bytes())
    14  	r2B := client.curve.ScalarMult(client.pubkey, signature.r2.Bytes())
    15  	HmR := client.curve.ScalarMult(signature.R, Hm.Bytes())
    16  	R2BHmR := client.curve.AddPoints(r2B, HmR)
    17  	if SG.X.Cmp(R2BHmR.X) != 0 || SG.Y.Cmp(R2BHmR.Y) != 0 {
    18  		return false, eccutil.ErrSigWrong
    19  	}
    20  	return true, nil
    21  }