Imports #
_ "crypto/internal/fips140/check"
"crypto/internal/fips140/edwards25519/field"
"errors"
"crypto/internal/fips140deps/byteorder"
"errors"
"math/bits"
"sync"
"crypto/internal/fips140/subtle"
_ "crypto/internal/fips140/check"
"crypto/internal/fips140/edwards25519/field"
"errors"
"crypto/internal/fips140deps/byteorder"
"errors"
"math/bits"
"sync"
"crypto/internal/fips140/subtle"
d is a constant in the curve equation.
var _identity is the point at infinity.
var _generator is the canonical curve basepoint. See TestGenerator for the correspondence of this encoding with the values in RFC 8032.
var _var basepointNafTablePrecomp struct{...}var basepointTablePrecomp struct{...}d is a constant in the curve equation.
var d = *ast.CallExprvar d2 = *ast.CallExprvar feOne = *ast.CallExprgenerator is the canonical curve basepoint. See TestGenerator for the correspondence of this encoding with the values in RFC 8032.
var generator = *ast.CallExpridentity is the point at infinity.
var identity = *ast.CallExprscalarMinusOneBytes is l - 1 in little endian.
var scalarMinusOneBytes = [32]byte{...}scalarTwo168 and scalarTwo336 are 2^168 and 2^336 modulo l, encoded as a fiatScalarMontgomeryDomainFieldElement, which is a little-endian 4-limb value in the 2^256 Montgomery domain.
var scalarTwo168 = *ast.UnaryExprvar scalarTwo336 = *ast.UnaryExprtype fiatScalarInt1 int64The type fiatScalarMontgomeryDomainFieldElement is a field element in the Montgomery domain. Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
type fiatScalarMontgomeryDomainFieldElement [4]uint64The type fiatScalarNonMontgomeryDomainFieldElement is a field element NOT in the Montgomery domain. Bounds: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]]
type fiatScalarNonMontgomeryDomainFieldElement [4]uint64type fiatScalarUint1 uint64type incomparable [0]func()Point represents a point on the edwards25519 curve. This type works similarly to math/big.Int, and all arguments and receivers are allowed to alias. The zero value is NOT valid, and it may be used only as a receiver.
type Point struct {
_ incomparable
x field.Element
y field.Element
z field.Element
t field.Element
}A Scalar is an integer modulo l = 2^252 + 27742317777372353535851937790883648493 which is the prime order of the edwards25519 group. This type works similarly to math/big.Int, and all arguments and receivers are allowed to alias. The zero value is a valid zero element.
type Scalar struct {
s fiatScalarMontgomeryDomainFieldElement
}type affineCached struct {
YplusX field.Element
YminusX field.Element
T2d field.Element
}A precomputed lookup table for fixed-base, constant-time scalar muls.
type affineLookupTable struct {
points [8]affineCached
}A dynamic lookup table for variable-base, variable-time scalar muls.
type nafLookupTable5 struct {
points [8]projCached
}A precomputed lookup table for fixed-base, variable-time scalar muls.
type nafLookupTable8 struct {
points [64]affineCached
}type projCached struct {
YplusX field.Element
YminusX field.Element
Z field.Element
T2d field.Element
}A dynamic lookup table for variable-base, constant-time scalar muls.
type projLookupTable struct {
points [8]projCached
}type projP1xP1 struct {
X field.Element
Y field.Element
Z field.Element
T field.Element
}type projP2 struct {
X field.Element
Y field.Element
Z field.Element
}func (v *projP1xP1) Add(p *Point, q *projCached) *projP1xP1Add sets v = p + q, and returns v.
func (v *Point) Add(p *Point, q *Point) *PointAdd sets s = x + y mod l, and returns s.
func (s *Scalar) Add(x *Scalar, y *Scalar) *Scalarfunc (v *projP1xP1) AddAffine(p *Point, q *affineCached) *projP1xP1Bytes returns the canonical 32-byte little-endian encoding of s.
func (s *Scalar) Bytes() []byteBytes returns the canonical 32-byte encoding of v, according to RFC 8032, Section 5.1.2.
func (v *Point) Bytes() []byteCondNeg negates v if cond == 1 and leaves it unchanged if cond == 0.
func (v *affineCached) CondNeg(cond int) *affineCachedCondNeg negates v if cond == 1 and leaves it unchanged if cond == 0.
func (v *projCached) CondNeg(cond int) *projCachedfunc (v *projP1xP1) Double(p *projP2) *projP1xP1Equal returns 1 if v is equivalent to u, and 0 otherwise.
func (v *Point) Equal(u *Point) intEqual returns 1 if s and t are equal, and 0 otherwise.
func (s *Scalar) Equal(t *Scalar) intfunc (v *projP2) FromP1xP1(p *projP1xP1) *projP2func (v *projCached) FromP3(p *Point) *projCachedfunc (v *projP2) FromP3(p *Point) *projP2func (v *affineCached) FromP3(p *Point) *affineCachedBuilds a lookup table at runtime. Fast.
func (v *projLookupTable) FromP3(q *Point)This is not optimised for speed; fixed-base tables should be precomputed.
func (v *affineLookupTable) FromP3(q *Point)Builds a lookup table at runtime. Fast.
func (v *nafLookupTable5) FromP3(q *Point)This is not optimised for speed; fixed-base tables should be precomputed.
func (v *nafLookupTable8) FromP3(q *Point)Multiply sets s = x * y mod l, and returns s.
func (s *Scalar) Multiply(x *Scalar, y *Scalar) *ScalarMultiplyAdd sets s = x * y + z mod l, and returns s. It is equivalent to using Multiply and then Add.
func (s *Scalar) MultiplyAdd(x *Scalar, y *Scalar, z *Scalar) *ScalarNegate sets s = -x mod l, and returns s.
func (s *Scalar) Negate(x *Scalar) *ScalarNegate sets v = -p, and returns v.
func (v *Point) Negate(p *Point) *PointNewGeneratorPoint returns a new Point set to the canonical generator.
func NewGeneratorPoint() *PointNewIdentityPoint returns a new Point set to the identity.
func NewIdentityPoint() *PointNewScalar returns a new zero Scalar.
func NewScalar() *ScalarScalarBaseMult sets v = x * B, where B is the canonical generator, and returns v. The scalar multiplication is done in constant time.
func (v *Point) ScalarBaseMult(x *Scalar) *PointScalarMult sets v = x * q, and returns v. The scalar multiplication is done in constant time.
func (v *Point) ScalarMult(x *Scalar, q *Point) *PointSelect sets v to a if cond == 1 and to b if cond == 0.
func (v *projCached) Select(a *projCached, b *projCached, cond int) *projCachedSelect sets v to a if cond == 1 and to b if cond == 0.
func (v *affineCached) Select(a *affineCached, b *affineCached, cond int) *affineCachedSet dest to x*Q, where -8 <= x <= 8, in constant time.
func (v *projLookupTable) SelectInto(dest *projCached, x int8)Given odd x with 0 < x < 2^7, return x*Q (in variable time).
func (v *nafLookupTable8) SelectInto(dest *affineCached, x int8)Given odd x with 0 < x < 2^4, return x*Q (in variable time).
func (v *nafLookupTable5) SelectInto(dest *projCached, x int8)Set dest to x*Q, where -8 <= x <= 8, in constant time.
func (v *affineLookupTable) SelectInto(dest *affineCached, x int8)Set sets s = x, and returns s.
func (s *Scalar) Set(x *Scalar) *ScalarSet sets v = u, and returns v.
func (v *Point) Set(u *Point) *PointSetBytes sets v = x, where x is a 32-byte encoding of v. If x does not represent a valid point on the curve, SetBytes returns nil and an error and the receiver is unchanged. Otherwise, SetBytes returns v. Note that SetBytes accepts all non-canonical encodings of valid points. That is, it follows decoding rules that match most implementations in the ecosystem rather than RFC 8032.
func (v *Point) SetBytes(x []byte) (*Point, error)SetBytesWithClamping applies the buffer pruning described in RFC 8032, Section 5.1.5 (also known as clamping) and sets s to the result. The input must be 32 bytes, and it is not modified. If x is not of the right length, SetBytesWithClamping returns nil and an error, and the receiver is unchanged. Note that since Scalar values are always reduced modulo the prime order of the curve, the resulting value will not preserve any of the cofactor-clearing properties that clamping is meant to provide. It will however work as expected as long as it is applied to points on the prime order subgroup, like in Ed25519. In fact, it is lost to history why RFC 8032 adopted the irrelevant RFC 7748 clamping, but it is now required for compatibility.
func (s *Scalar) SetBytesWithClamping(x []byte) (*Scalar, error)SetCanonicalBytes sets s = x, where x is a 32-byte little-endian encoding of s, and returns s. If x is not a canonical encoding of s, SetCanonicalBytes returns nil and an error, and the receiver is unchanged.
func (s *Scalar) SetCanonicalBytes(x []byte) (*Scalar, error)SetUniformBytes sets s = x mod l, where x is a 64-byte little-endian integer. If x is not of the right length, SetUniformBytes returns nil and an error, and the receiver is unchanged. SetUniformBytes can be used to set s to a uniformly distributed value given 64 uniformly distributed random bytes.
func (s *Scalar) SetUniformBytes(x []byte) (*Scalar, error)func (v *projP1xP1) Sub(p *Point, q *projCached) *projP1xP1func (v *projP1xP1) SubAffine(p *Point, q *affineCached) *projP1xP1Subtract sets s = x - y mod l, and returns s.
func (s *Scalar) Subtract(x *Scalar, y *Scalar) *ScalarSubtract sets v = p - q, and returns v.
func (v *Point) Subtract(p *Point, q *Point) *PointVarTimeDoubleScalarBaseMult sets v = a * A + b * B, where B is the canonical generator, and returns v. Execution time depends on the inputs.
func (v *Point) VarTimeDoubleScalarBaseMult(a *Scalar, A *Point, b *Scalar) *Pointfunc (v *projCached) Zero() *projCachedfunc (v *affineCached) Zero() *affineCachedfunc (v *projP2) Zero() *projP2basepointNafTable is the nafLookupTable8 for the basepoint. It is precomputed the first time it's used.
func basepointNafTable() *nafLookupTable8basepointTable is a set of 32 affineLookupTables, where table i is generated from 256i * basepoint. It is precomputed the first time it's used.
func basepointTable() *[32]affineLookupTablefunc (v *Point) bytes(buf *[32]byte) []bytefunc (s *Scalar) bytes(out *[32]byte) []bytefunc checkInitialized(points ...*Point)func copyFieldElement(buf *[32]byte, v *field.Element) []bytefiatScalarAdd adds two field elements in the Montgomery domain. Preconditions: 0 ≤ eval arg1 < m 0 ≤ eval arg2 < m Postconditions: eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) + eval (from_montgomery arg2)) mod m 0 ≤ eval out1 < m
func fiatScalarAdd(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement, arg2 *fiatScalarMontgomeryDomainFieldElement)fiatScalarCmovznzU64 is a single-word conditional move. Postconditions: out1 = (if arg1 = 0 then arg2 else arg3) Input Bounds: arg1: [0x0 ~> 0x1] arg2: [0x0 ~> 0xffffffffffffffff] arg3: [0x0 ~> 0xffffffffffffffff] Output Bounds: out1: [0x0 ~> 0xffffffffffffffff]
func fiatScalarCmovznzU64(out1 *uint64, arg1 fiatScalarUint1, arg2 uint64, arg3 uint64)fiatScalarFromBytes deserializes a field element NOT in the Montgomery domain from bytes in little-endian order. Preconditions: 0 ≤ bytes_eval arg1 < m Postconditions: eval out1 mod m = bytes_eval arg1 mod m 0 ≤ eval out1 < m Input Bounds: arg1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1f]] Output Bounds: out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0x1fffffffffffffff]]
func fiatScalarFromBytes(out1 *[4]uint64, arg1 *[32]uint8)fiatScalarFromMontgomery translates a field element out of the Montgomery domain. Preconditions: 0 ≤ eval arg1 < m Postconditions: eval out1 mod m = (eval arg1 * ((2^64)⁻¹ mod m)^4) mod m 0 ≤ eval out1 < m
func fiatScalarFromMontgomery(out1 *fiatScalarNonMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement)fiatScalarMul multiplies two field elements in the Montgomery domain. Preconditions: 0 ≤ eval arg1 < m 0 ≤ eval arg2 < m Postconditions: eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) * eval (from_montgomery arg2)) mod m 0 ≤ eval out1 < m
func fiatScalarMul(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement, arg2 *fiatScalarMontgomeryDomainFieldElement)fiatScalarNonzero outputs a single non-zero word if the input is non-zero and zero otherwise. Preconditions: 0 ≤ eval arg1 < m Postconditions: out1 = 0 ↔ eval (from_montgomery arg1) mod m = 0 Input Bounds: arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] Output Bounds: out1: [0x0 ~> 0xffffffffffffffff]
func fiatScalarNonzero(out1 *uint64, arg1 *[4]uint64)fiatScalarOpp negates a field element in the Montgomery domain. Preconditions: 0 ≤ eval arg1 < m Postconditions: eval (from_montgomery out1) mod m = -eval (from_montgomery arg1) mod m 0 ≤ eval out1 < m
func fiatScalarOpp(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement)fiatScalarSub subtracts two field elements in the Montgomery domain. Preconditions: 0 ≤ eval arg1 < m 0 ≤ eval arg2 < m Postconditions: eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) - eval (from_montgomery arg2)) mod m 0 ≤ eval out1 < m
func fiatScalarSub(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarMontgomeryDomainFieldElement, arg2 *fiatScalarMontgomeryDomainFieldElement)fiatScalarToBytes serializes a field element NOT in the Montgomery domain to bytes in little-endian order. Preconditions: 0 ≤ eval arg1 < m Postconditions: out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..31] Input Bounds: arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0x1fffffffffffffff]] Output Bounds: out1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0x1f]]
func fiatScalarToBytes(out1 *[32]uint8, arg1 *[4]uint64)fiatScalarToMontgomery translates a field element into the Montgomery domain. Preconditions: 0 ≤ eval arg1 < m Postconditions: eval (from_montgomery out1) mod m = eval arg1 mod m 0 ≤ eval out1 < m
func fiatScalarToMontgomery(out1 *fiatScalarMontgomeryDomainFieldElement, arg1 *fiatScalarNonMontgomeryDomainFieldElement)func (v *Point) fromP1xP1(p *projP1xP1) *Pointfunc (v *Point) fromP2(p *projP2) *PointisReduced returns whether the given scalar in 32-byte little endian encoded form is reduced modulo l.
func isReduced(s []byte) boolnonAdjacentForm computes a width-w non-adjacent form for this scalar. w must be between 2 and 8, or nonAdjacentForm will panic.
func (s *Scalar) nonAdjacentForm(w uint) [256]int8setShortBytes sets s = x mod l, where x is a little-endian integer shorter than 32 bytes.
func (s *Scalar) setShortBytes(x []byte) *Scalarfunc (s *Scalar) signedRadix16() [64]int8Generated with Arrow