Documentation ¶
Overview ¶
Package operation allows for basic manipulation of scalars & group elements
Index ¶
- Constants
- Variables
- func CheckDuplicateScalarArray(arr []*Scalar) bool
- func Compare(sca, scb *Scalar) int
- func IsPointEqual(pa *Point, pb *Point) bool
- func IsScalarEqual(sc1, sc2 *Scalar) bool
- func Reverse(x [32]byte) (result [32]byte)
- type MultiScalarMultBuilder
- func (b *MultiScalarMultBuilder) Append(scLst []*Scalar, pLst []*Point) error
- func (b *MultiScalarMultBuilder) AppendSingle(sc *Scalar, p *Point)
- func (b *MultiScalarMultBuilder) Clone() *MultiScalarMultBuilder
- func (b *MultiScalarMultBuilder) ConcatScaled(b1 *MultiScalarMultBuilder, n *Scalar) error
- func (b MultiScalarMultBuilder) Debug()
- func (b *MultiScalarMultBuilder) Eval() (result *Point)
- func (b *MultiScalarMultBuilder) MustAppend(scLst []*Scalar, pLst []*Point)
- func (sb *MultiScalarMultBuilder) MustSetStatic(startIndex int, scLst ...*Scalar)
- func (sb *MultiScalarMultBuilder) SetStatic(startIndex int, scLst ...*Scalar) error
- func (sb *MultiScalarMultBuilder) WithStaticPoints(ppLst []PrecomputedPoint) *staticPointMultBuilder
- type PedersenCommitment
- type Point
- func (p *Point) Add(pa, pb *Point) *Point
- func (p *Point) AddPedersen(a *Scalar, A *Point, b *Scalar, B *Point) *Point
- func (p *Point) Derive(pa *Point, a *Scalar, b *Scalar) *Point
- func (p *Point) FromBytes(bArr [32]byte) (*Point, error)
- func (p *Point) FromBytesS(b []byte) (*Point, error)
- func (p Point) GetKey() [32]byte
- func (p *Point) Identity() *Point
- func (p Point) IsIdentity() bool
- func (p Point) MarshalText() []byte
- func (p *Point) MixedVarTimeMultiScalarMult(scalarLs []*Scalar, pointLs []*Point, staticScalarLs []*Scalar, ...) *Point
- func (p *Point) MultiScalarMult(scalarLs []*Scalar, pointLs []*Point) *Point
- func (p *Point) PointValid() bool
- func (p *Point) ScalarMult(pa *Point, a *Scalar) *Point
- func (p *Point) ScalarMultBase(a *Scalar) *Point
- func (p *Point) Set(q *Point) *Point
- func (p *Point) SetKey(bArr *[32]byte) (*Point, error)
- func (p Point) String() string
- func (p *Point) Sub(pa, pb *Point) *Point
- func (p *Point) ToBytes() (result [32]byte)
- func (p *Point) ToBytesS() (result []byte)
- func (p *Point) UnmarshalText(data []byte) (*Point, error)
- func (p *Point) VarTimeMultiScalarMult(scalarLs []*Scalar, pointLs []*Point) *Point
- type PrecomputedPoint
- type Scalar
- func (sc *Scalar) Add(a, b *Scalar) *Scalar
- func (sc *Scalar) FromBytes(bArr [32]byte) *Scalar
- func (sc *Scalar) FromBytesS(b []byte) *Scalar
- func (sc *Scalar) FromUint64(i uint64) *Scalar
- func (sc *Scalar) Invert(a *Scalar) *Scalar
- func (sc *Scalar) IsZero() bool
- func (sc Scalar) MarshalText() []byte
- func (sc *Scalar) Mul(a, b *Scalar) *Scalar
- func (sc *Scalar) MulAdd(a, b, c *Scalar) *Scalar
- func (sc *Scalar) Negate(a *Scalar) *Scalar
- func (sc *Scalar) ScalarValid() bool
- func (sc *Scalar) Set(a *Scalar) *Scalar
- func (sc *Scalar) SetKey(a *[32]byte) (*Scalar, error)
- func (sc Scalar) String() string
- func (sc *Scalar) Sub(a, b *Scalar) *Scalar
- func (sc Scalar) ToBytes() (result [32]byte)
- func (sc Scalar) ToBytesS() []byte
- func (sc *Scalar) ToUint64Little() uint64
- func (sc *Scalar) UnmarshalText(data []byte) (*Scalar, error)
Constants ¶
const ( Ed25519KeySize = 32 TxRandomIndexSize = 4 CStringBulletProof = "bulletproof" CStringAssetTag = "blindedassettag" CStringOTA = "onetimeaddress" )
Variables ¶
var ScMinusOne = NewScalar().Negate(ScOne)
var ScOne = NewScalar().FromUint64(1)
var ScZero = NewScalar()
Functions ¶
func CheckDuplicateScalarArray ¶
CheckDuplicateScalarArray is a legacy function
func IsPointEqual ¶
IsPointEqual checks the equality of 2 `Point`s
func IsScalarEqual ¶
IsScalarEqual checks if two Scalars are equal
Types ¶
type MultiScalarMultBuilder ¶
type MultiScalarMultBuilder struct {
// contains filtered or unexported fields
}
MultiScalarMultBuilder is a helper struct to make best use of MultiScalarMult functions. The idea is to delay the invocation of Point multiplications so we can combine them into 1 large `MultiScalarMult` operation, which is faster.
MultiScalarMultBuilder keeps track of lists of scalars & points of guaranteed matching length; it evaluates to `sum(scalars[i] * points[i]) + sum(static_scalars[i] * static_points[i])`. Static members are precomputed.
This struct assumes caller never passes "nil" scalars / points
func NewMultBuilder ¶
func NewMultBuilder(_useVarTime bool) *MultiScalarMultBuilder
NewMultBuilder returns a new instance of MultiScalarMultBuilder, with fields initialized to zero except static ones (which need a call to WithStaticPoints)
func (*MultiScalarMultBuilder) Append ¶
func (b *MultiScalarMultBuilder) Append(scLst []*Scalar, pLst []*Point) error
Append appends more scalars and points to b, making sure their lengths match. It does not clone but consumes its inputs.
This adds `sum(scLst[i] * pLst[i])` to evaluation of b.
func (*MultiScalarMultBuilder) AppendSingle ¶
func (b *MultiScalarMultBuilder) AppendSingle(sc *Scalar, p *Point)
AppendSingle appends 1 scalar & 1 point to b.
This adds `sc * p` to evaluation of b.
func (*MultiScalarMultBuilder) Clone ¶
func (b *MultiScalarMultBuilder) Clone() *MultiScalarMultBuilder
Clone returns an exact clone of b, with newly allocated members
func (*MultiScalarMultBuilder) ConcatScaled ¶
func (b *MultiScalarMultBuilder) ConcatScaled(b1 *MultiScalarMultBuilder, n *Scalar) error
ConcatScaled first scales the evaluation of `b1` by `n`, then concatenates it to the fields of b.
Dynamic members are appended, while static members are summed by-column.
This adds `sum(scalars_1[i] * points_1[i]) + sum(static_scalars_1[i] * static_points_1[i])` to the evaluation of b.
func (MultiScalarMultBuilder) Debug ¶
func (b MultiScalarMultBuilder) Debug()
func (*MultiScalarMultBuilder) Eval ¶
func (b *MultiScalarMultBuilder) Eval() (result *Point)
Eval invokes a multiscalar-mult function to finalize the builder `b`, returning the resulted Point.
It chooses the constant-time or variable-time variant of multiscalar-mult based on the contents of `b`; it clears `b` after execution.
func (*MultiScalarMultBuilder) MustAppend ¶
func (b *MultiScalarMultBuilder) MustAppend(scLst []*Scalar, pLst []*Point)
MustAppend appends more scalars and points to b. Caller must pass slices of matching lengths or it panics. It does not clone but consumes its inputs.
This adds `sum(scLst[i] * pLst[i])` to evaluation of b.
func (*MultiScalarMultBuilder) MustSetStatic ¶
MustSetStatic is the equivalent of MustAppend for static members. Static Points are identified using index.
func (*MultiScalarMultBuilder) SetStatic ¶
SetStatic is the equivalent of Append for static members. Static Points are identified using index.
func (*MultiScalarMultBuilder) WithStaticPoints ¶
func (sb *MultiScalarMultBuilder) WithStaticPoints(ppLst []PrecomputedPoint) *staticPointMultBuilder
WithStaticPoints sets the list of static Points for the builder.
The slice is not cloned since PrecomputedPoint is immutable.
type PedersenCommitment ¶
type PedersenCommitment struct {
G []*Point // generators
}
PedersenCommitment represents the parameters for the commitment
var PedCom PedersenCommitment = NewPedersenParams()
func NewPedersenParams ¶
func NewPedersenParams() PedersenCommitment
NewPedersenParams returns the generators used for Pedersen commitments
func (PedersenCommitment) CommitAll ¶
func (com PedersenCommitment) CommitAll(openings []*Scalar) (*Point, error)
CommitAll commits a list of PCM_CAPACITY value(s)
func (PedersenCommitment) CommitAtIndex ¶
func (com PedersenCommitment) CommitAtIndex(value, rand *Scalar, index byte) *Point
CommitAtIndex commits specific value with index and returns `g^v x h^rand`
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
Point is a wrapper for `edwards25519.Point`, representing a point on the curve. It needs to be instantiated via constructor; while `new(Point)` can only be used as receiver.
var GBase, HBase, RandomBase *Point
func HashToPoint ¶
HashToPoint is a legacy map-to-point implementation
func HashToPointFromIndex ¶
HashToPointFromIndex is a legacy function; it maps an index to a Point
func NewGeneratorPoint ¶
func NewGeneratorPoint() *Point
NewGeneratorPoint returns a new instance of the curve generator point
func NewIdentityPoint ¶
func NewIdentityPoint() *Point
NewIdentityPoint returns a new instance of the curve identity point
func RandomPoint ¶
func RandomPoint() *Point
RandomPoint returns a random point in the group, using `crypto/`'s randomness
func (*Point) AddPedersen ¶
AddPedersen computes a Pedersen commitment; it sets `p = aA + bB`, then returns `p`
func (*Point) Derive ¶
Derive is a privacy-v1 legacy function; it performs the SN-derivation algorithm, then sets and returns `p`
func (*Point) FromBytesS ¶
FromBytesS unmarshals `p` from a byte slice, then returns `p`
func (Point) IsIdentity ¶
IsIdentity checks if Point `p` is equal to identity
func (Point) MarshalText ¶
MarshalText returns the hex string representation of `p` but as bytes
func (*Point) MixedVarTimeMultiScalarMult ¶
func (p *Point) MixedVarTimeMultiScalarMult(scalarLs []*Scalar, pointLs []*Point, staticScalarLs []*Scalar, staticPointLs []PrecomputedPoint) *Point
MixedVarTimeMultiScalarMult is a multiscalar-mult variant that uses variable-time logic and takes static (precomputed) points in combination with dynamic points. The caller must pass scalar lists of matching length for dynamic & static points respectively.
func (*Point) MultiScalarMult ¶
MultiScalarMult performs a multi-scalar multiplication on the group; sets and returns `p = sum(scalarLs[i] * pointLs[i])`. The caller must pass inputs of matching length to it.
func (*Point) PointValid ¶
PointValid checks that `p` belongs to the group (p first needs to be a valid Point object)
func (*Point) ScalarMult ¶
ScalarMultBase sets `p = a * p_a`, then returns `p`
func (*Point) ScalarMultBase ¶
ScalarMultBase sets `p = a * G` where a is a scalar and G is the curve basepoint, then returns `p`
func (*Point) UnmarshalText ¶
UnmarshalText decodes a Point from its hex string form and sets `p` to it, then returns p
type PrecomputedPoint ¶
type PrecomputedPoint struct {
// contains filtered or unexported fields
}
PrecomputedPoint wraps the struct edwards25519.PrecomputedPoint which stores precomputed field elements to speed up computation
func (*PrecomputedPoint) From ¶
func (pp *PrecomputedPoint) From(q *Point) *PrecomputedPoint
From populates this PrecomputedPoint to the value of Point p
type Scalar ¶
type Scalar struct {
// contains filtered or unexported fields
}
Scalar is a wrapper for `edwards25519.Scalar`, representing an integer modulo group order
func HashToScalar ¶
HashToScalar creates a Scalar using the bytes from `data` by first hashing it
func RandomScalar ¶
func RandomScalar() *Scalar
RandomScalar returns a random Scalar, generated using `crypto/`'s randomness
func (*Scalar) FromBytesS ¶
FromBytesS unmarshals `sc` from a byte slice, then returns `sc`
func (*Scalar) FromUint64 ¶
FromUint64 sets the value of `sc` to that of `i`
func (Scalar) MarshalText ¶
MarshalText returns the hex string representation of `sc` but as bytes
func (*Scalar) ScalarValid ¶
ScalarValid checks the validity of `sc` for use in group operations
func (*Scalar) ToUint64Little ¶
ToUint64Little returns the value of `sc` as uint64. The value needs to be in range or this outputs zero.