Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions curve/ecgfp5/scalar_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"encoding/binary"
"math/big"

"github.com/elliottech/poseidon_crypto/field/goldilocks"
gFp5 "github.com/elliottech/poseidon_crypto/field/goldilocks_quintic_extension"
. "github.com/elliottech/poseidon_crypto/int"
)
Expand All @@ -13,6 +14,18 @@
// p = 1067993516717146951041484916571792702745057740581727230159139685185762082554198619328292418486241
type ECgFp5Scalar [5]uint64

func (s ECgFp5Scalar) IsCanonical() bool {
for _, elem := range s {
if elem >= goldilocks.ORDER {
return false
}
}
if ToNonCanonicalBigInt(s).Cmp(ORDER) >= 0 {

Check failure on line 23 in curve/ecgfp5/scalar_field.go

View workflow job for this annotation

GitHub Actions / Lint

S1008: should use 'return ToNonCanonicalBigInt(s).Cmp(ORDER) < 0' instead of 'if ToNonCanonicalBigInt(s).Cmp(ORDER) >= 0 { return false }; return true' (gosimple)
return false
}
return true
}

var (
ORDER, _ = new(big.Int).SetString("1067993516717146951041484916571792702745057740581727230159139685185762082554198619328292418486241", 10)
ZERO = ECgFp5Scalar{}
Expand Down
8 changes: 8 additions & 0 deletions signature/schnorr/schnorr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type Signature struct {
E curve.ECgFp5Scalar
}

func (s Signature) IsCanonical() bool {
return s.E.IsCanonical() && s.S.IsCanonical()
}

var ZERO_SIG = Signature{
S: curve.ZERO,
E: curve.ZERO,
Expand Down Expand Up @@ -102,6 +106,10 @@ func Validate(pubKey, hashedMsg, sig []byte) error {
}

func IsSchnorrSignatureValid(pubKey, hashedMsg gFp5.Element, sig Signature) bool {
if !sig.IsCanonical() {
return false
}

pubKeyWs, ok := curve.DecodeFp5AsWeierstrass(pubKey)
if !ok {
return false
Expand Down
Loading