Skip to content

Commit

Permalink
Rename GroupPublicKey->VerificationKey (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: bytemare <3641580+bytemare@users.noreply.github.com>
  • Loading branch information
bytemare authored Oct 7, 2024
1 parent 04af7b4 commit 23ea4d5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[![dkg](https://github.com/bytemare/dkg/actions/workflows/code-scan.yml/badge.svg)](https://github.com/bytemare/dkg/actions/workflows/code-scan.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/bytemare/dkg.svg)](https://pkg.go.dev/github.com/bytemare/dkg)
[![codecov](https://codecov.io/gh/bytemare/dkg/branch/main/graph/badge.svg?token=5bQfB0OctA)](https://codecov.io/gh/bytemare/dkg)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/bytemare/dkg/badge)](https://securityscorecards.dev/viewer/?uri=github.com/bytemare/dkg)

```
import "github.com/bytemare/dkg"
Expand Down
16 changes: 8 additions & 8 deletions dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (p *Participant) Finalize(r1DataSet []*Round1Data, r2DataSet []*Round2Data)
}

secretKey := p.group.NewScalar()
groupPublic := p.group.NewElement()
verificationKey := p.group.NewElement()

for _, data := range r2DataSet {
peerCommitment, err := p.verifyRound2Data(r1DataSet, data)
Expand All @@ -304,15 +304,15 @@ func (p *Participant) Finalize(r1DataSet []*Round1Data, r2DataSet []*Round2Data)
}

secretKey.Add(data.SecretShare)
groupPublic.Add(peerCommitment)
verificationKey.Add(peerCommitment)
}

secretKey.Add(p.secretShare)
p.secretShare.Zero()

return &keys.KeyShare{
Secret: secretKey,
GroupPublicKey: groupPublic.Add(p.commitment[0]),
Secret: secretKey,
VerificationKey: verificationKey.Add(p.commitment[0]),
PublicKeyShare: keys.PublicKeyShare{
PublicKey: p.group.Base().Multiply(secretKey),
VssCommitment: p.commitment,
Expand All @@ -335,8 +335,8 @@ func (p *Participant) verifyCommitmentPublicKey(id uint16, share *ecc.Scalar, co
return nil
}

// GroupPublicKeyFromRound1 returns the global public key, usable to verify signatures produced in a threshold scheme.
func GroupPublicKeyFromRound1(c Ciphersuite, r1DataSet []*Round1Data) (*ecc.Element, error) {
// VerificationKeyFromRound1 returns the global public key, usable to verify signatures produced in a threshold scheme.
func VerificationKeyFromRound1(c Ciphersuite, r1DataSet []*Round1Data) (*ecc.Element, error) {
if !c.Available() {
return nil, errInvalidCiphersuite
}
Expand All @@ -351,9 +351,9 @@ func GroupPublicKeyFromRound1(c Ciphersuite, r1DataSet []*Round1Data) (*ecc.Elem
return pubKey, nil
}

// GroupPublicKeyFromCommitments returns the threshold's setup group public key, given all the commitments from all the
// VerificationKeyFromCommitments returns the threshold's setup group public key, given all the commitments from all the
// participants.
func GroupPublicKeyFromCommitments(c Ciphersuite, commitments [][]*ecc.Element) (*ecc.Element, error) {
func VerificationKeyFromCommitments(c Ciphersuite, commitments [][]*ecc.Element) (*ecc.Element, error) {
if !c.Available() {
return nil, errInvalidCiphersuite
}
Expand Down
17 changes: 10 additions & 7 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,28 @@ func Example_dkg() {
}

// Optional: There are multiple ways on how you can get the group's public key (the one used for signature validation)
// 1. Participant's Finalize() function returns a KeyShare, which contains the GroupPublicKey, which can be sent to
// 1. Participant's Finalize() function returns a KeyShare, which contains the VerificationKey, which can be sent to
// the coordinator or registry.
// 2. Using the commitments in the Round1 data, this is convenient during protocol execution.
// 3. Using the participants' commitments in their public key share, this is convenient after protocol execution.
groupPublicKey1 := keyShares[0].GroupPublicKey
groupPublicKey2, err := dkg.GroupPublicKeyFromRound1(c, decodedRound1Data)
verificationKey1 := keyShares[0].VerificationKey
verificationKey2, err := dkg.VerificationKeyFromRound1(c, decodedRound1Data)
if err != nil {
panic(err)
}
groupPublicKey3, err := dkg.GroupPublicKeyFromCommitments(c, dkg.VSSCommitmentsFromRegistry(PublicKeyShareRegistry))
verificationKey3, err := dkg.VerificationKeyFromCommitments(
c,
dkg.VSSCommitmentsFromRegistry(PublicKeyShareRegistry),
)
if err != nil {
panic(err)
}

if !groupPublicKey1.Equal(groupPublicKey2) || !groupPublicKey1.Equal(groupPublicKey3) {
if !verificationKey1.Equal(verificationKey2) || !verificationKey2.Equal(verificationKey3) {
panic("group public key recovery failed")
}

PublicKeyShareRegistry.GroupPublicKey = groupPublicKey3
PublicKeyShareRegistry.VerificationKey = verificationKey3

// A registry can be encoded for backup or transmission.
encodedRegistry := PublicKeyShareRegistry.Encode()
Expand Down Expand Up @@ -159,7 +162,7 @@ func Example_dkg() {
}

groupPubKey := g.Base().Multiply(recombinedSecret)
if !groupPubKey.Equal(groupPublicKey3) {
if !groupPubKey.Equal(verificationKey3) {
panic("failed to recover the correct group secret")
}

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ go 1.23.1

require (
filippo.io/edwards25519 v1.1.0
github.com/bytemare/ecc v0.8.1
github.com/bytemare/ecc v0.8.2
github.com/bytemare/hash v0.3.0
github.com/bytemare/secret-sharing v0.6.0
github.com/bytemare/secret-sharing v0.7.0
github.com/gtank/ristretto255 v0.1.2
)

require (
filippo.io/nistec v0.0.3 // indirect
github.com/bytemare/hash2curve v0.3.0 // indirect
github.com/bytemare/secp256k1 v0.1.6 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/sys v0.26.0 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
filippo.io/nistec v0.0.3 h1:h336Je2jRDZdBCLy2fLDUd9E2unG32JLwcJi0JQE9Cw=
filippo.io/nistec v0.0.3/go.mod h1:84fxC9mi+MhC2AERXI4LSa8cmSVOzrFikg6hZ4IfCyw=
github.com/bytemare/ecc v0.8.1 h1:uX3G+Q2f52vy65R/+fzs2Mo4V+Z+hNSdSm1qMooWFuc=
github.com/bytemare/ecc v0.8.1/go.mod h1:dvkSikSCejw8YaTdJs6lZSN4qz9B4PC5PtGq+CRDmHk=
github.com/bytemare/ecc v0.8.2 h1:MN+Ah48hApFpzJgIMa1xOrK7/R5uwCV06dtJyuHAi3Y=
github.com/bytemare/ecc v0.8.2/go.mod h1:dvkSikSCejw8YaTdJs6lZSN4qz9B4PC5PtGq+CRDmHk=
github.com/bytemare/hash v0.3.0 h1:RqFMt3mqpF7UxLdjBrsOZm/2cz0cQiAOnYc9gDLopWE=
github.com/bytemare/hash v0.3.0/go.mod h1:YKOBchL0l8hRLFinVCL8YUKokGNIMhrWEHPHo3EV7/M=
github.com/bytemare/hash2curve v0.3.0 h1:41Npcbc+u/E252A5aCMtxDcz7JPkkX1QzShneTFm4eg=
github.com/bytemare/hash2curve v0.3.0/go.mod h1:itj45U8uqvCtWC0eCswIHVHswXcEHkpFui7gfJdPSfQ=
github.com/bytemare/secp256k1 v0.1.6 h1:5pOA84UBBTPTUmCkjtH6jHrbvZSh2kyxG0mW/OjSih0=
github.com/bytemare/secp256k1 v0.1.6/go.mod h1:Zr7o3YCog5jKx5JwgYbj984gRIqVioTDZMSDo1y0zgE=
github.com/bytemare/secret-sharing v0.6.0 h1:/gQhsC3BY2pn7nIl+1sQDtI4c9IfkjuTbBXsvh922UM=
github.com/bytemare/secret-sharing v0.6.0/go.mod h1:CQ7ALe5CIbvnEGhcF50LKu9brAki7efQPT3d/UUhzQQ=
github.com/bytemare/secret-sharing v0.7.0 h1:ayJWEhwQzeChtavB4WrqufRJPnG5u2IePe1MEeJJEgs=
github.com/bytemare/secret-sharing v0.7.0/go.mod h1:Qzrf83Sk36D2NGJpk1/0H6YJx0SnsiOtrS6zaiISL2o=
github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc=
github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
12 changes: 6 additions & 6 deletions tests/dkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func TestCompleteDKG(t *testing.T) {
quals := []uint16{1, 3, 5}
keyShares := make([]*keys.KeyShare, 0, len(quals))
registry := keys.NewPublicKeyShareRegistry(c.group, c.threshold, c.maxParticipants)
pubKey, _ := dkg.GroupPublicKeyFromRound1(c.ciphersuite, r1)
pubKey, _ := dkg.VerificationKeyFromRound1(c.ciphersuite, r1)
for _, participant := range p {
keyShare, err := participant.Finalize(r1, r2[participant.Identifier])
if err != nil {
t.Fatal(err)
}

if !keyShare.GroupPublicKey.Equal(pubKey) {
if !keyShare.VerificationKey.Equal(pubKey) {
t.Fatalf("expected same public key")
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func makeRegistry(t *testing.T, c *testCase, keyShares []*keys.KeyShare) *keys.P
}

var err error
registry.GroupPublicKey, err = dkg.GroupPublicKeyFromCommitments(
registry.VerificationKey, err = dkg.VerificationKeyFromCommitments(
c.ciphersuite,
dkg.VSSCommitmentsFromRegistry(registry),
)
Expand Down Expand Up @@ -808,15 +808,15 @@ func TestComputeParticipantPublicKey_Bad_CommitmentNilElement(t *testing.T) {
})
}

func TestGroupPublicKey_BadCipher(t *testing.T) {
func TestVerificationKey_BadCipher(t *testing.T) {
errInvalidCiphersuite := errors.New("invalid ciphersuite")

if _, err := dkg.GroupPublicKeyFromRound1(dkg.Ciphersuite(2), nil); err == nil ||
if _, err := dkg.VerificationKeyFromRound1(dkg.Ciphersuite(2), nil); err == nil ||
err.Error() != errInvalidCiphersuite.Error() {
t.Fatalf("expected %q, got %q", errInvalidCiphersuite, err)
}

if _, err := dkg.GroupPublicKeyFromCommitments(dkg.Ciphersuite(2), nil); err == nil ||
if _, err := dkg.VerificationKeyFromCommitments(dkg.Ciphersuite(2), nil); err == nil ||
err.Error() != errInvalidCiphersuite.Error() {
t.Fatalf("expected %q, got %q", errInvalidCiphersuite, err)
}
Expand Down

0 comments on commit 23ea4d5

Please sign in to comment.