Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
fix hashing to scalars for Curve25519 and Edwards25519
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemare committed Aug 15, 2021
1 parent e6f408a commit fc329c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion group/curve25519/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (g Group) HashToGroup(input, dst []byte) internal.Point {
func (g Group) HashToScalar(input, dst []byte) internal.Scalar {
sc := hash2curve.HashToScalarXMD(crypto.SHA512, input, dst, canonicalEncodingLength)

s, err := edwards25519.NewScalar().SetUniformBytes(sc)
s, err := edwards25519.NewScalar().SetCanonicalBytes(sc)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion group/edwards25519/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (g Group) HashToGroup(input, dst []byte) internal.Point {
func (g Group) HashToScalar(input, dst []byte) internal.Scalar {
sc := hash2curve.HashToScalarXMD(crypto.SHA512, input, dst, canonicalEncodingLength)

s, err := edwards25519.NewScalar().SetUniformBytes(sc)
s, err := edwards25519.NewScalar().SetCanonicalBytes(sc)
if err != nil {
panic(err)
}
Expand Down
15 changes: 6 additions & 9 deletions group/hash2curve/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,25 @@ const (
)

var errZeroLenDST = errors.New("zero-length DST")

// errShortDST = internal.ParameterError("DST is shorter than recommended length")

// ExpandXMD expands the input and dst using the given fixed length hash function.
func ExpandXMD(id crypto.Hash, input, dst []byte, length int) []byte {
func checkDST(dst []byte) {
if len(dst) < recommendedMinLength {
if len(dst) == minLength {
panic(errZeroLenDST)
}
}
}

// ExpandXMD expands the input and dst using the given fixed length hash function.
func ExpandXMD(id crypto.Hash, input, dst []byte, length int) []byte {
checkDST(dst)
return expandXMD(id, input, dst, length)
}

// ExpandXOF expands the input and dst using the given extensible output hash function.
func ExpandXOF(id x.Extensible, input, dst []byte, length int) []byte {
if len(dst) < recommendedMinLength {
if len(dst) == minLength {
panic(errZeroLenDST)
}
}

checkDST(dst)
return expandXOF(id, input, dst, length)
}

Expand Down

0 comments on commit fc329c5

Please sign in to comment.