Skip to content

Commit

Permalink
Enforce len assumption in reverse()
Browse files Browse the repository at this point in the history
  • Loading branch information
K1li4nL committed Sep 11, 2024
1 parent 4509c6b commit 071ab17
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions sign/bdn/bdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func hashPointToR(g kyber.Group, pubs []kyber.Point) ([]kyber.Scalar, error) {
return nil, err
}
if g.Scalar().ByteOrder() == kyber.BigEndian {
reverse(b, b)
// Safely ignore the err as len(b) == len(b)
_, _ = reverse(b, b)
}

coefs[i] = g.Scalar()
Expand All @@ -79,17 +80,21 @@ func hashPointToR(g kyber.Group, pubs []kyber.Point) ([]kyber.Scalar, error) {
// 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 {
func reverse(dst, src []byte) ([]byte, error) {
if dst == nil {
dst = make([]byte, len(src))
}

if len(dst) != len(src) {
return nil, errors.New("destination length doesn't match the source")
}

l := len(dst)
for i, j := 0, l-1; i < (l+1)/2; {
dst[i], dst[j] = src[j], src[i]
i++
j--
for left, right := 0, l-1; left < (l+1)/2; left, right = left+1, right-1 {
dst[left], dst[right] = src[right], src[left]
}
return dst

return dst, nil
}

type Scheme struct {
Expand Down

0 comments on commit 071ab17

Please sign in to comment.