mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
edwards: add signature IsEqual and Verify methods
This commit is contained in:
parent
f0ef1e4e2c
commit
aa76fb64a1
@ -8,6 +8,8 @@ package edwards
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/agl/ed25519"
|
||||
)
|
||||
|
||||
// Signature is a type representing an ecdsa signature.
|
||||
@ -39,6 +41,27 @@ func (sig Signature) Serialize() []byte {
|
||||
return all
|
||||
}
|
||||
|
||||
// IsEqual compares this Signature instance to the one passed, returning true
|
||||
// if both Signatures are equivalent. A signature is equivalent to another, if
|
||||
// they both have the same scalar value for R and S.
|
||||
func (sig *Signature) IsEqual(otherSig *Signature) bool {
|
||||
return sig.R.Cmp(otherSig.R) == 0 &&
|
||||
sig.S.Cmp(otherSig.S) == 0
|
||||
}
|
||||
|
||||
// Verify verifies a message 'hash' using the given public keys and signature.
|
||||
func (sig *Signature) Verify(hash []byte, pubKey *PublicKey) bool {
|
||||
if pubKey == nil || hash == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
pubBytes := pubKey.Serialize()
|
||||
sigBytes := sig.Serialize()
|
||||
pubArray := copyBytes(pubBytes)
|
||||
sigArray := copyBytes64(sigBytes)
|
||||
return ed25519.Verify(pubArray, hash, sigArray)
|
||||
}
|
||||
|
||||
// parseSig is the default method of parsing a serialized Ed25519 signature.
|
||||
func parseSig(sigStr []byte, der bool) (*Signature, error) {
|
||||
if der {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user