diff --git a/internal/edwards25519/fe.go b/internal/edwards25519/fe.go index 3feb298..76e5364 100644 --- a/internal/edwards25519/fe.go +++ b/internal/edwards25519/fe.go @@ -9,30 +9,29 @@ import ( "crypto/subtle" "math/big" - // This is exactly as horrible as it should be. - . "github.com/gtank/ristretto255/internal/edwards25519/internal/edwards25519" + x "github.com/gtank/ristretto255/internal/edwards25519/internal/edwards25519" ) // FeEqual returns 1 if a and b are equal, and 0 otherwise. func FeEqual(a, b *FieldElement) int { var sa, sb [32]byte - FeToBytes(&sa, a) - FeToBytes(&sb, b) + x.FeToBytes(&sa, a) + x.FeToBytes(&sb, b) return subtle.ConstantTimeCompare(sa[:], sb[:]) } // FeSelect sets out to v if cond == 1, and to u if cond == 0. // out, v and u are allowed to overlap. func FeSelect(out, v, u *FieldElement, cond int) { - FeCMove(out, u, int32(cond^1)) - FeCMove(out, v, int32(cond)) + x.FeCMove(out, u, int32(cond^1)) + x.FeCMove(out, v, int32(cond)) } // FeCondNeg sets u to -u if cond == 1, and to u if cond == 0. func FeCondNeg(u *FieldElement, cond int) { var neg FieldElement FeNeg(&neg, u) - FeCMove(u, &neg, int32(cond)) + x.FeCMove(u, &neg, int32(cond)) } // FeAbs sets out to |u|. out and u are allowed to overlap. @@ -49,5 +48,5 @@ func feFromBig(dst *FieldElement, n *big.Int) { for i := range buf[:len(buf)/2] { buf[i], buf[len(buf)-1] = buf[len(buf)-1], buf[i] } - FeFromBytes(dst, &buf) + x.FeFromBytes(dst, &buf) } diff --git a/internal/edwards25519/xcrypto.go b/internal/edwards25519/xcrypto.go new file mode 100644 index 0000000..7e3e2fa --- /dev/null +++ b/internal/edwards25519/xcrypto.go @@ -0,0 +1,17 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Copyright 2019 George Tankersley. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package edwards25519 + +import x "github.com/gtank/ristretto255/internal/edwards25519/internal/edwards25519" + +// Expose some types and functions from the x/crypto code to ristretto255. + +type ExtendedGroupElement = x.ExtendedGroupElement +type FieldElement = x.FieldElement + +var FeMul = x.FeMul +var FeNeg = x.FeNeg +var FeIsNegative = x.FeIsNegative