ecmath

package
v0.0.0-...-ff6bfbe Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Zero is the number 0.
	Zero Scalar

	// One is the number 1.
	One = Scalar{1}

	Cofactor = Scalar{8}

	// NegOne is the number -1 mod L
	NegOne = Scalar{
		0xec, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
		0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
	}

	// L is the subgroup order:
	// 2^252 + 27742317777372353535851937790883648493
	L = Scalar{
		0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
		0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
	}
)

Functions

This section is empty.

Types

type Point

Point is a point on the ed25519 curve.

var ZeroPoint Point

ZeroPoint is the zero point on the ed25519 curve (not the zero value of Point).

func (*Point) Add

func (z *Point) Add(x, y *Point) *Point

Add adds the points in x and y, storing the result in z and returning that. Any or all of x, y, and z may be the same pointers.

func (*Point) Bytes

func (p *Point) Bytes() []byte

Bytes returns binary representation of a EC point (32-byte slice)

func (*Point) ConstTimeEqual

func (z *Point) ConstTimeEqual(x *Point) bool

func (*Point) Decode

func (z *Point) Decode(e [32]byte) (*Point, bool)

func (*Point) Encode

func (z *Point) Encode() [32]byte

func (*Point) MarshalBinary

func (p *Point) MarshalBinary() ([]byte, error)

MarshalBinary encodes the receiver into a binary form and returns the result (32-byte slice).

func (*Point) MarshalText

func (p *Point) MarshalText() ([]byte, error)

MarshalText returns a hex-encoded point.

func (*Point) ReadFrom

func (p *Point) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom attempts to read 32 bytes and decode a point.

func (*Point) ScMul

func (z *Point) ScMul(x *Point, y *Scalar) *Point

ScMul multiplies the EC point x by the scalar y, placing the result in z and returning that. X and z may be the same pointer.

func (*Point) ScMulAdd

func (z *Point) ScMulAdd(a *Point, x, y *Scalar) *Point

ScMulAdd computes xa+yB, where B is the ed25519 base point, and places the result in z, returning that.

func (*Point) ScMulBase

func (z *Point) ScMulBase(x *Scalar) *Point

ScMulBase multiplies the ed25519 base point by x and places the result in z, returning that.

func (*Point) ScMulCofactor

func (z *Point) ScMulCofactor(p *Point) *Point

ScMulCofactor computes 8*p, where p is the ed25519 point and 8 is a cofactor, and places the result in z, returning that.

func (*Point) String

func (p *Point) String() string

String returns hex representation of a EC point

func (*Point) Sub

func (z *Point) Sub(x, y *Point) *Point

Sub subtracts y from x, storing the result in z and returning that. Any or all of x, y, and z may be the same pointers.

func (*Point) UnmarshalBinary

func (p *Point) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes point for a given slice. Returns error if the slice is not 32-bytes long or the encoding is invalid.

func (*Point) UnmarshalText

func (p *Point) UnmarshalText(b []byte) error

UnmarshalText decodes a point from a hex-encoded buffer.

func (*Point) WriteTo

func (p *Point) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes 32-byte encoding of a point.

type Scalar

type Scalar [32]byte

Scalar is a 256-bit little-endian scalar.

func (*Scalar) Add

func (z *Scalar) Add(x, y *Scalar) *Scalar

Add computes x+y (mod L) and places the result in z, returning that. Any or all of x, y, and z may be the same pointer.

func (*Scalar) Equal

func (z *Scalar) Equal(x *Scalar) bool

func (*Scalar) Mul

func (z *Scalar) Mul(x, y *Scalar) *Scalar

Mul computes x*y (mod L) and places the result in z, returning that. Any or all of x, y, and z may be the same pointer.

func (*Scalar) MulAdd

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

MulAdd computes ab+c (mod L) and places the result in z, returning that. Any or all of the pointers may be the same.

func (*Scalar) Neg

func (z *Scalar) Neg(x *Scalar) *Scalar

Neg negates x (mod L) and places the result in z, returning that. X and z may be the same pointer.

func (*Scalar) Prune

func (z *Scalar) Prune()

Prune performs the pruning operation in-place.

func (*Scalar) Reduce

func (z *Scalar) Reduce(x *[64]byte) *Scalar

Reduce takes a 512-bit scalar and reduces it mod L, placing the result in z and returning that.

func (*Scalar) SetInt64

func (s *Scalar) SetInt64(n int64) *Scalar

SetInt64 sets the scalar to a given integer value.

func (*Scalar) SetUint64

func (s *Scalar) SetUint64(n uint64) *Scalar

SetUint64 sets the scalar to a given integer value. One-liner: s := (&ecmath.Scalar{}).SetUint64(n)

func (*Scalar) String

func (s *Scalar) String() string

func (*Scalar) Sub

func (z *Scalar) Sub(x, y *Scalar) *Scalar

Sub computes x-y (mod L) and places the result in z, returning that. Any or all of x, y, and z may be the same pointer.

Jump to

Keyboard shortcuts

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