diff --git a/internal/radix51/fe.go b/internal/radix51/fe.go index f6a6522..1c09245 100644 --- a/internal/radix51/fe.go +++ b/internal/radix51/fe.go @@ -239,8 +239,8 @@ func (v *FieldElement) FromBytes(x []byte) *FieldElement { return v } -// AppendBytes appends a 32 bytes little-endian encoding of v to b. -func (v *FieldElement) AppendBytes(b []byte) []byte { +// Bytes appends a 32 bytes little-endian encoding of v to b. +func (v *FieldElement) Bytes(b []byte) []byte { t := new(FieldElement).Reduce(v) res, out := sliceForAppend(b, 32) @@ -300,7 +300,7 @@ func (v *FieldElement) FromBig(n *big.Int) *FieldElement { // ToBig returns v as a big.Int. func (v *FieldElement) ToBig() *big.Int { - buf := v.AppendBytes(nil) + buf := v.Bytes(nil) words := make([]big.Word, 32*8/bits.UintSize) for n := range words { @@ -319,8 +319,8 @@ func (v *FieldElement) ToBig() *big.Int { // Equal returns 1 if v and u are equal, and 0 otherwise. func (v *FieldElement) Equal(u *FieldElement) int { var sa, sv [32]byte - u.AppendBytes(sa[:0]) - v.AppendBytes(sv[:0]) + u.Bytes(sa[:0]) + v.Bytes(sv[:0]) return subtle.ConstantTimeCompare(sa[:], sv[:]) } @@ -346,7 +346,7 @@ func (v *FieldElement) CondNeg(u *FieldElement, cond int) *FieldElement { // IsNegative returns 1 if v is negative, and 0 otherwise. func (v *FieldElement) IsNegative() int { var b [32]byte - v.AppendBytes(b[:0]) + v.Bytes(b[:0]) return int(b[0] & 1) } diff --git a/internal/radix51/fe_test.go b/internal/radix51/fe_test.go index 413cce7..17cfaeb 100644 --- a/internal/radix51/fe_test.go +++ b/internal/radix51/fe_test.go @@ -122,7 +122,7 @@ func BenchmarkWideMultCall(t *testing.B) { func TestFromBytesRoundTrip(t *testing.T) { f1 := func(in, out [32]byte, fe FieldElement) bool { fe.FromBytes(in[:]) - fe.AppendBytes(out[:0]) + fe.Bytes(out[:0]) // Mask the most significant bit as it's ignored by FromBytes. (Now // instead of earlier so we check the masking in FromBytes is working.) @@ -141,10 +141,10 @@ func TestFromBytesRoundTrip(t *testing.T) { } f2 := func(fe, r FieldElement, out [32]byte) bool { - fe.AppendBytes(out[:0]) + fe.Bytes(out[:0]) r.FromBytes(out[:]) - // Intentionally not using Equal not to go through AppendBytes again. + // Intentionally not using Equal not to go through Bytes again. // Calling Reduce because both Generate and FromBytes can produce // non-canonical representations. fe.Reduce(&fe) @@ -175,7 +175,7 @@ func TestBytesBigEquivalence(t *testing.T) { return false } - fe.AppendBytes(out[:0]) + fe.Bytes(out[:0]) buf := make([]byte, 32) // pad with zeroes copy(buf, swapEndianness(fe1.ToBig().Bytes())) @@ -189,7 +189,7 @@ func TestBytesBigEquivalence(t *testing.T) { func TestFromBytesRoundTripEdgeCases(t *testing.T) { // TODO: values close to 0, close to 2^255-19, between 2^255-19 and 2^255-1, // and between 2^255 and 2^256-1. Test both the documented FromBytes - // behavior, and that AppendBytes reduces them. + // behavior, and that Bytes reduces them. } // Tests self-consistency between FeMul and FeSquare.