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

Commit fc329c5

Browse files
committed
fix hashing to scalars for Curve25519 and Edwards25519
1 parent e6f408a commit fc329c5

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

group/curve25519/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (g Group) HashToGroup(input, dst []byte) internal.Point {
5353
func (g Group) HashToScalar(input, dst []byte) internal.Scalar {
5454
sc := hash2curve.HashToScalarXMD(crypto.SHA512, input, dst, canonicalEncodingLength)
5555

56-
s, err := edwards25519.NewScalar().SetUniformBytes(sc)
56+
s, err := edwards25519.NewScalar().SetCanonicalBytes(sc)
5757
if err != nil {
5858
panic(err)
5959
}

group/edwards25519/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (g Group) HashToGroup(input, dst []byte) internal.Point {
5353
func (g Group) HashToScalar(input, dst []byte) internal.Scalar {
5454
sc := hash2curve.HashToScalarXMD(crypto.SHA512, input, dst, canonicalEncodingLength)
5555

56-
s, err := edwards25519.NewScalar().SetUniformBytes(sc)
56+
s, err := edwards25519.NewScalar().SetCanonicalBytes(sc)
5757
if err != nil {
5858
panic(err)
5959
}

group/hash2curve/expand.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,25 @@ const (
2626
)
2727

2828
var errZeroLenDST = errors.New("zero-length DST")
29-
3029
// errShortDST = internal.ParameterError("DST is shorter than recommended length")
3130

32-
// ExpandXMD expands the input and dst using the given fixed length hash function.
33-
func ExpandXMD(id crypto.Hash, input, dst []byte, length int) []byte {
31+
func checkDST(dst []byte) {
3432
if len(dst) < recommendedMinLength {
3533
if len(dst) == minLength {
3634
panic(errZeroLenDST)
3735
}
3836
}
37+
}
3938

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

4345
// ExpandXOF expands the input and dst using the given extensible output hash function.
4446
func ExpandXOF(id x.Extensible, input, dst []byte, length int) []byte {
45-
if len(dst) < recommendedMinLength {
46-
if len(dst) == minLength {
47-
panic(errZeroLenDST)
48-
}
49-
}
50-
47+
checkDST(dst)
5148
return expandXOF(id, input, dst, length)
5249
}
5350

0 commit comments

Comments
 (0)