Skip to content

Commit

Permalink
Allow empty proofFac, roll back rejectSample for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yycen committed Aug 10, 2023
1 parent dab835d commit 8cb8930
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
15 changes: 1 addition & 14 deletions common/hash_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,12 @@
package common

import (
"crypto/sha256"
"math/big"
)

// RejectionSample implements the rejection sampling logic for converting a
// SHA512/256 hash to a value between 0-q
func RejectionSample(q *big.Int, eHash *big.Int) *big.Int { // e' = eHash
auxiliary := new(big.Int).Set(eHash)
e := new(big.Int).Set(q)
qBytesLen := len(q.Bytes())
if qBytesLen > 32 {
panic("invalid q size")
}
one := new(big.Int).SetInt64(1)
for e.Cmp(q) != -1 {
eHashAdded := auxiliary.Add(auxiliary, one)
eHashReSample := sha256.Sum256(eHashAdded.Bytes())
// sample qBytesLen bytes
e = new(big.Int).SetBytes(eHashReSample[:qBytesLen])
}
e := eHash.Mod(eHash, q)
return e
}
5 changes: 3 additions & 2 deletions ecdsa/keygen/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ func NewKGRound2Message1(

func (m *KGRound2Message1) ValidateBasic() bool {
return m != nil &&
common.NonEmptyBytes(m.GetShare()) &&
common.NonEmptyMultiBytes(m.GetFacProof(), facproof.ProofFacBytesParts)
common.NonEmptyBytes(m.GetShare())
// This is commented for backward compatibility, which msg has no proof
// && common.NonEmptyMultiBytes(m.GetFacProof(), facproof.ProofFacBytesParts)
}

func (m *KGRound2Message1) UnmarshalShare() *big.Int {
Expand Down

0 comments on commit 8cb8930

Please sign in to comment.