Skip to content

Commit

Permalink
Fix legacy ed25519
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Jul 10, 2024
1 parent 6186aa3 commit 27808c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions protocol/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ func (e *LegacyED25519Signature) Verify(sig Signature, msg Signable) bool {
if len(e.PublicKey) != 32 || len(e.Signature) != 64 {
return false
}
return verifySig(e, sig, true, msg, func(msg []byte) bool {
return ed25519.Verify(e.PublicKey, msg, e.Signature)
return verifySigSplit(e, sig, true, msg, func(sig, msg []byte) bool {
hash := doSha256(sig, common.Uint64Bytes(e.Timestamp), msg)
return ed25519.Verify(e.PublicKey, hash, e.Signature)
})
}

Expand Down
10 changes: 8 additions & 2 deletions protocol/signature_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ type SignableHash [32]byte
func (h SignableHash) Hash() [32]byte { return h }

func verifySig(inner, outer Signature, merkle bool, msg interface{ Hash() [32]byte }, verify func([]byte) bool) bool {
return verifySigSplit(inner, outer, merkle, msg, func(sig, msg []byte) bool {
return verify(doSha256(sig, msg))
})
}

func verifySigSplit(inner, outer Signature, merkle bool, msg interface{ Hash() [32]byte }, verify func(_, _ []byte) bool) bool {
if outer == nil {
outer = inner
}
msgHash := msg.Hash()
if verify(doSha256(outer.Metadata().Hash(), msgHash[:])) {
if verify(outer.Metadata().Hash(), msgHash[:]) {
return true
}
if !merkle {
Expand All @@ -32,7 +38,7 @@ func verifySig(inner, outer Signature, merkle bool, msg interface{ Hash() [32]by
if err != nil {
return false
}
return verify(doSha256(h.MerkleHash(), msgHash[:]))
return verify(h.MerkleHash(), msgHash[:])
}

func signatureHash(sig Signature) []byte {
Expand Down

0 comments on commit 27808c6

Please sign in to comment.