Skip to content

Commit

Permalink
add NewLocalPartyWithLength for leading zero in ecdsa
Browse files Browse the repository at this point in the history
  • Loading branch information
zargarzadehm committed Jan 11, 2024
1 parent f67a429 commit 2fa85bd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
10 changes: 8 additions & 2 deletions ecdsa/signing/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
26 changes: 20 additions & 6 deletions ecdsa/signing/local_party.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions ecdsa/signing/local_party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package signing

import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
"math/big"
"runtime"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2fa85bd

Please sign in to comment.