Selectively expose types and functions from the inner x/crypto implementation

This commit is contained in:
Filippo Valsorda 2019-01-20 17:30:08 -05:00
parent e93531adad
commit 268ae6be59
2 changed files with 24 additions and 8 deletions

View File

@ -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)
}

View File

@ -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