diff --git a/ecdsa/signing/finalize.go b/ecdsa/signing/finalize.go index 995702fe..1bfa29dc 100644 --- a/ecdsa/signing/finalize.go +++ b/ecdsa/signing/finalize.go @@ -61,14 +61,20 @@ func (round *finalization) Start() *tss.Error { round.data.S = padToLengthBytesInPlace(sumS.Bytes(), bitSizeInBytes) round.data.Signature = append(round.data.R, round.data.S...) round.data.SignatureRecovery = []byte{byte(recid)} - round.data.M = round.temp.m.Bytes() + common.Logger.Infof("checkkkkkkk %v", round.temp.fullBytesLen == 0) + if round.data.M = round.temp.m.Bytes(); round.temp.fullBytesLen != 0 { + var mBytes = make([]byte, round.temp.fullBytesLen) + round.temp.m.FillBytes(mBytes) + round.data.M = mBytes + } pk := ecdsa.PublicKey{ Curve: round.Params().EC(), X: round.key.ECDSAPub.X(), Y: round.key.ECDSAPub.Y(), } - ok := ecdsa.Verify(&pk, round.temp.m.Bytes(), round.temp.rx, sumS) + + ok := ecdsa.Verify(&pk, round.data.M, round.temp.rx, sumS) if !ok { return round.WrapError(fmt.Errorf("signature verification failed")) } diff --git a/ecdsa/signing/local_party.go b/ecdsa/signing/local_party.go index ae34ad00..3de8ffd6 100644 --- a/ecdsa/signing/local_party.go +++ b/ecdsa/signing/local_party.go @@ -63,10 +63,11 @@ type ( sigma, keyDerivationDelta, gamma *big.Int - cis []*big.Int - bigWs []*crypto.ECPoint - pointGamma *crypto.ECPoint - deCommit cmt.HashDeCommitment + fullBytesLen int + cis []*big.Int + bigWs []*crypto.ECPoint + pointGamma *crypto.ECPoint + deCommit cmt.HashDeCommitment // round 2 betas, // return value of Bob_mid @@ -102,8 +103,19 @@ func NewLocalParty( params *tss.Parameters, key keygen.LocalPartySaveData, out chan<- tss.Message, - end chan<- *common.SignatureData) tss.Party { - return NewLocalPartyWithKDD(msg, params, key, nil, out, end) + end chan<- *common.SignatureData, + fullBytesLen ...int) tss.Party { + return NewLocalPartyWithKDD(msg, params, key, nil, out, end, 0) +} + +func NewLocalPartyWithLength( + msg *big.Int, + params *tss.Parameters, + key keygen.LocalPartySaveData, + out chan<- tss.Message, + end chan<- *common.SignatureData, + fullBytesLen int) tss.Party { + return NewLocalPartyWithKDD(msg, params, key, nil, out, end, fullBytesLen) } // NewLocalPartyWithKDD returns a party with key derivation delta for HD support @@ -114,6 +126,7 @@ func NewLocalPartyWithKDD( keyDerivationDelta *big.Int, out chan<- tss.Message, end chan<- *common.SignatureData, + fullBytesLen int, ) tss.Party { partyCount := len(params.Parties().IDs()) p := &LocalParty{ @@ -139,6 +152,7 @@ func NewLocalPartyWithKDD( // temp data init p.temp.keyDerivationDelta = keyDerivationDelta p.temp.m = msg + p.temp.fullBytesLen = fullBytesLen p.temp.cis = make([]*big.Int, partyCount) p.temp.bigWs = make([]*crypto.ECPoint, partyCount) p.temp.betas = make([]*big.Int, partyCount) diff --git a/ecdsa/signing/local_party_test.go b/ecdsa/signing/local_party_test.go index a1680b5f..dad377d1 100644 --- a/ecdsa/signing/local_party_test.go +++ b/ecdsa/signing/local_party_test.go @@ -8,6 +8,7 @@ package signing import ( "crypto/ecdsa" + "encoding/hex" "fmt" "math/big" "runtime" @@ -55,12 +56,11 @@ func TestE2EConcurrent(t *testing.T) { endCh := make(chan *common.SignatureData, len(signPIDs)) updater := test.SharedPartyUpdater - + msgData, _ := hex.DecodeString("00f163ee51bcaeff9cdff5e0e3c1a646abd19885fffbab0b3b4236e0cf95c9f5") // init the parties for i := 0; i < len(signPIDs); i++ { params := tss.NewParameters(tss.S256(), p2pCtx, signPIDs[i], len(signPIDs), threshold) - - P := NewLocalParty(big.NewInt(42), params, keys[i], outCh, endCh).(*LocalParty) + P := NewLocalPartyWithLength(new(big.Int).SetBytes(msgData), params, keys[i], outCh, endCh, len(msgData)).(*LocalParty) parties = append(parties, P) go func(P *LocalParty) { if err := P.Start(); err != nil { @@ -95,7 +95,7 @@ signing: go updater(parties[dest[0].Index], msg, errCh) } - case <-endCh: + case xx := <-endCh: atomic.AddInt32(&ended, 1) if atomic.LoadInt32(&ended) == int32(len(signPIDs)) { t.Logf("Done. Received signature data from %d participants", ended) @@ -120,8 +120,9 @@ signing: X: pkX, Y: pkY, } - ok := ecdsa.Verify(&pk, big.NewInt(42).Bytes(), R.X(), sumS) + ok := ecdsa.Verify(&pk, msgData, R.X(), sumS) assert.True(t, ok, "ecdsa verify must pass") + t.Logf("Message: %v", hex.EncodeToString(xx.M)) t.Log("ECDSA signing test done.") // END ECDSA verify @@ -164,12 +165,12 @@ func TestE2EWithHDKeyDerivation(t *testing.T) { endCh := make(chan *common.SignatureData, len(signPIDs)) updater := test.SharedPartyUpdater - + msg, _ := hex.DecodeString("00f163ee51bcaeff9cdff5e0e3c1a646abd19885fffbab0b3b4236e0cf95c9f5") // init the parties for i := 0; i < len(signPIDs); i++ { params := tss.NewParameters(tss.S256(), p2pCtx, signPIDs[i], len(signPIDs), threshold) - P := NewLocalPartyWithKDD(big.NewInt(42), params, keys[i], keyDerivationDelta, outCh, endCh).(*LocalParty) + P := NewLocalPartyWithKDD(new(big.Int).SetBytes(msg), params, keys[i], keyDerivationDelta, outCh, endCh, 0).(*LocalParty) parties = append(parties, P) go func(P *LocalParty) { if err := P.Start(); err != nil { @@ -228,7 +229,7 @@ signing: X: pkX, Y: pkY, } - ok := ecdsa.Verify(&pk, big.NewInt(42).Bytes(), R.X(), sumS) + ok := ecdsa.Verify(&pk, msg, R.X(), sumS) assert.True(t, ok, "ecdsa verify must pass") t.Log("ECDSA signing test done.") // END ECDSA verify