From 8cb89307b2a94239b1c7b98efc9ea1be8cc6a102 Mon Sep 17 00:00:00 2001 From: ycen Date: Thu, 10 Aug 2023 17:35:17 +0800 Subject: [PATCH] Allow empty proofFac, roll back rejectSample for compatibility --- common/hash_utils.go | 15 +-------------- ecdsa/keygen/messages.go | 5 +++-- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/common/hash_utils.go b/common/hash_utils.go index 9fa24e5b..4fd26196 100644 --- a/common/hash_utils.go +++ b/common/hash_utils.go @@ -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 } diff --git a/ecdsa/keygen/messages.go b/ecdsa/keygen/messages.go index 18da1dc9..e3f43d78 100644 --- a/ecdsa/keygen/messages.go +++ b/ecdsa/keygen/messages.go @@ -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 {