Skip to content

Commit

Permalink
Make bdn work with different suites
Browse files Browse the repository at this point in the history
  • Loading branch information
K1li4nL committed Sep 3, 2024
1 parent bd7268d commit 9b67b52
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 29 additions & 4 deletions sign/bdn/bdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var modulus128 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 128), big.NewI
// other words, find m' where H(m) == H(m')
// We also use the entire roster so that the coefficient will vary for the same
// public key used in different roster
func hashPointToR(pubs []kyber.Point) ([]kyber.Scalar, error) {
func hashPointToR(g kyber.Group, pubs []kyber.Point) ([]kyber.Scalar, error) {
peers := make([][]byte, len(pubs))
for i, pub := range pubs {
peer, err := pub.MarshalBinary()
Expand Down Expand Up @@ -61,12 +61,37 @@ func hashPointToR(pubs []kyber.Point) ([]kyber.Scalar, error) {

coefs := make([]kyber.Scalar, len(pubs))
for i := range coefs {
coefs[i] = mod.NewIntBytes(out[i*16:(i+1)*16], modulus128, kyber.LittleEndian)
b, err := mod.NewIntBytes(out[i*16:(i+1)*16], modulus128, kyber.LittleEndian).MarshalBinary()
if err != nil {
return nil, err
}
if g.Scalar().ByteOrder() == kyber.BigEndian {
reverse(b, b)
}

coefs[i] = g.Scalar()
coefs[i].SetBytes(b)
}

return coefs, nil
}

// reverse copies src into dst in byte-reversed order and returns dst,
// such that src[0] goes into dst[len-1] and vice versa.
// dst and src may be the same slice but otherwise must not overlap.
func reverse(dst, src []byte) []byte {
if dst == nil {
dst = make([]byte, len(src))
}
l := len(dst)
for i, j := 0, l-1; i < (l+1)/2; {
dst[i], dst[j] = src[j], src[i]
i++
j--
}
return dst
}

type Scheme struct {
blsScheme sign.Scheme
sigGroup kyber.Group
Expand Down Expand Up @@ -133,7 +158,7 @@ func (scheme *Scheme) AggregateSignatures(sigs [][]byte, mask *sign.Mask) (kyber
return nil, errors.New("length of signatures and public keys must match")
}

coefs, err := hashPointToR(mask.Publics())
coefs, err := hashPointToR(scheme.sigGroup, mask.Publics())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -166,7 +191,7 @@ func (scheme *Scheme) AggregateSignatures(sigs [][]byte, mask *sign.Mask) (kyber
// AggregateSignatures for signatures) using the hash function
// H: keyGroup -> R with R = {1, ..., 2^128}.
func (scheme *Scheme) AggregatePublicKeys(mask *sign.Mask) (kyber.Point, error) {
coefs, err := hashPointToR(mask.Publics())
coefs, err := hashPointToR(scheme.keyGroup, mask.Publics())
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sign/bdn/bdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestBDN_HashPointToR_BN256(t *testing.T) {
p2 := suite.Point().Mul(two, suite.Point().Base())
p3 := suite.Point().Mul(three, suite.Point().Base())

coefs, err := hashPointToR([]kyber.Point{p1, p2, p3})
coefs, err := hashPointToR(suite, []kyber.Point{p1, p2, p3})

require.NoError(t, err)
require.Equal(t, "35b5b395f58aba3b192fb7e1e5f2abd3", coefs[0].String())
Expand Down

0 comments on commit 9b67b52

Please sign in to comment.