crypto

package
v1.0.1-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Ed25519KeySize     = 32
	TxRandomIndexSize  = 4
	CStringBulletProof = "bulletproof"
	CStringAssetTag    = "blindedassettag"
	CStringOTA         = "onetimeaddress"
)
View Source
const (
	PedersenPrivateKeyIndex = byte(0x00)
	PedersenValueIndex      = byte(0x01)
	PedersenSndIndex        = byte(0x02)
	PedersenShardIDIndex    = byte(0x03)
	PedersenRandomnessIndex = byte(0x04)
)

Variables

PedCom represents the parameters used in the Pedersen commitment scheme.

Functions

func Compare

func Compare(a, b *Scalar) int

Compare returns -1 if a < b, 0 if a = b, and 1 if a > b.

func IsPointEqual

func IsPointEqual(pa *Point, pb *Point) bool

IsPointEqual checks if pa = pb.

func IsScalarEqual

func IsScalarEqual(sc1, sc2 *Scalar) bool

IsScalarEqual checks if two scalars are the same.

func Reverse

func Reverse(x C25519.Key) (result C25519.Key)

Reverse returns the reverse byte-array of a C25519.Key x.

Types

type PedersenCommitment

type PedersenCommitment struct {
	G []*Point // generators
}

PedersenCommitment represents the base points for the Pedersen commitment scheme.

  • G[0]: the base point for key-related commitments.
  • G[1]: the base point for value commitments.
  • G[2]: the base point for SNDerivator commitments.
  • G[3]: the base point for shardID commitments.
  • G[4]: the base point for randomness factor.

func NewPedersenParams

func NewPedersenParams() PedersenCommitment

NewPedersenParams creates new PedersenCommitment parameters. It also sets GBase as G[1] and HBase as G[4].

func (PedersenCommitment) CommitAll

func (com PedersenCommitment) CommitAll(openings []*Scalar) (*Point, error)

CommitAll commits a list of values using the corresponding base points.

func (PedersenCommitment) CommitAtIndex

func (com PedersenCommitment) CommitAtIndex(value, rand *Scalar, index byte) *Point

CommitAtIndex commits specific value using the base point at the given index.

type Point

type Point struct {
	// contains filtered or unexported fields
}

Point represents an elliptic curve point. It only needs 32 bytes to represent a point.

var GBase *Point

GBase is the base point for committing UTXOs' value.

var HBase *Point

HBase is the base point for randomness factor.

func HashToPoint

func HashToPoint(b []byte) *Point

HashToPoint returns the Point value of the hash of b.

func HashToPointFromIndex

func HashToPointFromIndex(index int64, padStr string) *Point

HashToPointFromIndex returns the hash of the concatenation of padStr and index.

func RandomPoint

func RandomPoint() *Point

RandomPoint returns a random Point on the elliptic curve.

func (*Point) Add

func (p *Point) Add(pa, pb *Point) *Point

Add sets p = pa + pb and returns p.

func (*Point) AddPedersen

func (p *Point) AddPedersen(a *Scalar, A *Point, b *Scalar, B *Point) *Point

AddPedersen sets p = aA + bB and returns p.

func (*Point) Derive

func (p *Point) Derive(pa *Point, a *Scalar, b *Scalar) *Point

Derive sets p = 1/(a+b) * pa and returns p.

func (*Point) FromBytes

func (p *Point) FromBytes(b [Ed25519KeySize]byte) (*Point, error)

FromBytes sets an array of 32 bytes to a Point.

func (*Point) FromBytesS

func (p *Point) FromBytesS(b []byte) (*Point, error)

FromBytesS sets a slice of bytes to a Point.

func (Point) GetKey

func (p Point) GetKey() C25519.Key

GetKey returns the key of a Point.

func (*Point) Identity

func (p *Point) Identity() *Point

Identity sets p to the identity point and returns p.

func (*Point) InvertScalarMult

func (p *Point) InvertScalarMult(pa *Point, a *Scalar) *Point

InvertScalarMult sets p = (1/a) * pa and returns p.

func (*Point) InvertScalarMultBase

func (p *Point) InvertScalarMultBase(a *Scalar) *Point

InvertScalarMultBase sets p = (1/a) * G and returns p.

func (Point) IsIdentity

func (p Point) IsIdentity() bool

IsIdentity checks if p is the identity point.

func (*Point) MultiScalarMult

func (p *Point) MultiScalarMult(sList []*Scalar, pList []*Point) *Point

MultiScalarMult sets p = sum(sList[i] * pList[i]) and returns p.

func (Point) PointValid

func (p Point) PointValid() bool

PointValid checks if a Point is valid.

func (*Point) ScalarMult

func (p *Point) ScalarMult(pa *Point, a *Scalar) *Point

ScalarMult sets p = a * pa and returns p.

func (*Point) ScalarMultBase

func (p *Point) ScalarMultBase(a *Scalar) *Point

ScalarMultBase set p = a * G, where a is a scalar and G is the curve base point and returns p.

func (*Point) Set

func (p *Point) Set(q *Point) *Point

Set sets p = q and returns p.

func (*Point) SetKey

func (p *Point) SetKey(v *C25519.Key) (*Point, error)

SetKey sets v as the key of a Point.

func (Point) String

func (p Point) String() string

String returns the hex-encoded string of a Point.

func (*Point) Sub

func (p *Point) Sub(pa, pb *Point) *Point

Sub sets p = pa - pb and returns p.

func (Point) ToBytes

func (p Point) ToBytes() [Ed25519KeySize]byte

ToBytes returns an 32-byte long array from a Point.

func (Point) ToBytesS

func (p Point) ToBytesS() []byte

ToBytesS returns a slice of bytes from a Point.

type Scalar

type Scalar struct {
	// contains filtered or unexported fields
}

Scalar represents a scalar of an elliptic curve.

func HashToScalar

func HashToScalar(msg []byte) *Scalar

HashToScalar returns the hash of msg in the form of a scalar.

func RandomScalar

func RandomScalar() *Scalar

RandomScalar returns a random Scalar.

func (*Scalar) Add

func (sc *Scalar) Add(a, b *Scalar) *Scalar

Add returns (a + b) % CurveOrder.

func (*Scalar) Exp

func (sc *Scalar) Exp(a *Scalar, v uint64) *Scalar

Exp returns a^v % CurveOrder.

func (*Scalar) FromBytes

func (sc *Scalar) FromBytes(b [Ed25519KeySize]byte) *Scalar

FromBytes sets an array of 32 bytes to a Scalar.

func (*Scalar) FromBytesS

func (sc *Scalar) FromBytesS(b []byte) *Scalar

FromBytesS sets a slice of bytes to a Scalar.

func (*Scalar) FromUint64

func (sc *Scalar) FromUint64(v uint64) *Scalar

FromUint64 sets the value of a Scalar to v.

func (Scalar) GetKey

func (sc Scalar) GetKey() C25519.Key

GetKey returns the key of a Scalar.

func (*Scalar) Invert

func (sc *Scalar) Invert(a *Scalar) *Scalar

Invert returns the a^-1.

func (*Scalar) IsOne

func (sc *Scalar) IsOne() bool

IsOne checks if a Scalar equals to 1.

func (*Scalar) IsZero

func (sc *Scalar) IsZero() bool

IsZero checks if a scalar equals to 0.

func (*Scalar) Mul

func (sc *Scalar) Mul(a, b *Scalar) *Scalar

Mul returns a * b % CurveOrder.

func (*Scalar) MulAdd

func (sc *Scalar) MulAdd(a, b, c *Scalar) *Scalar

MulAdd return (a * b + c) % CurveOrder.

func (*Scalar) ScalarValid

func (sc *Scalar) ScalarValid() bool

ScalarValid checks if a Scalar is valid.

func (*Scalar) Set

func (sc *Scalar) Set(v *Scalar) *Scalar

Set sets v to a Scalar.

func (*Scalar) SetKey

func (sc *Scalar) SetKey(v *C25519.Key) (*Scalar, error)

SetKey sets v as the key of a Scalar.

func (*Scalar) SetKeyUnsafe

func (sc *Scalar) SetKeyUnsafe(v *C25519.Key) *Scalar

SetKeyUnsafe sets v as the key of Scalar (without caching errors).

func (Scalar) String

func (sc Scalar) String() string

String returns the hex-encoded string of a Scalar.

func (*Scalar) Sub

func (sc *Scalar) Sub(a, b *Scalar) *Scalar

Sub returns (a - b) % CurveOrder.

func (Scalar) ToBytes

func (sc Scalar) ToBytes() [Ed25519KeySize]byte

ToBytes returns an 32-byte long array from a Scalar.

func (Scalar) ToBytesS

func (sc Scalar) ToBytesS() []byte

ToBytesS returns a slice of bytes from a Scalar.

func (*Scalar) ToUint64Little

func (sc *Scalar) ToUint64Little() uint64

ToUint64Little returns the uint64 value of a Scalar.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL