r255

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package r255 implements Ristretto255 curve prime-order groups with backend "filippo.io/edwards25519"

Index

Constants

View Source
const (
	// H2C represents the hash-to-curve string identifier.
	// See https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-16.html#name-hashing-to-ristretto255
	H2C = "ristretto255_XMD:SHA-512_R255MAP_RO_"
)

Variables

View Source
var (
	// ErrInvalidEncoding returns when passed unsuitable data for unmarshaling
	ErrInvalidEncoding = errors.New("r255: invalid element encoding")
)

Functions

func R255

func R255() internal.Group

R255 returns a new instantiation of the Ristretto255 Group.

Types

type Element

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

Element represents Ristretto point

func (*Element) Add

Add sets the receiver to the sum of the input and the receiver, and returns the receiver.

func (*Element) Base

func (e *Element) Base() internal.Element

Base sets the element to the group's base point a.k.a. canonical generator.

func (*Element) Bytes

func (e *Element) Bytes() []byte

Bytes returns the 32 bytes canonical encoding of e.

func (*Element) Copy

func (e *Element) Copy() internal.Element

Copy returns a copy of the receiver.

func (*Element) Decode

func (e *Element) Decode(data []byte) error

Decode sets the receiver to a decoding of the input data, and returns an error on failure.

func (*Element) Double

func (e *Element) Double() internal.Element

Double sets the receiver to its double, and returns it.

func (*Element) Encode

func (e *Element) Encode() []byte

Encode returns the compressed byte encoding of the element.

func (*Element) Equal

func (e *Element) Equal(ee internal.Element) int

Equal returns 1 if e is equivalent to ee, and 0 otherwise.

Note that Elements must not be compared in any other way.

func (*Element) Identity

func (e *Element) Identity() internal.Element

Identity sets the element to the point at infinity of the Group's underlying curve.

func (*Element) IsIdentity

func (e *Element) IsIdentity() bool

IsIdentity returns whether the Element is the point at infinity of the Group's underlying curve.

func (*Element) MarshalBinary

func (e *Element) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Element) MarshalText

func (e *Element) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Element) Multiply

func (e *Element) Multiply(s internal.Scalar) internal.Element

Multiply sets the receiver to the scalar multiplication of the receiver with the given Scalar, and returns it. If s parameter is nil, then the receiver is not modified

func (*Element) Negate

func (e *Element) Negate() internal.Element

Negate sets the receiver to its negation, and returns it.

func (*Element) Set

Set sets the receiver to ee if not nil; else the receiver not modified; returns the receiver.

func (*Element) SetCanonicalBytes

func (e *Element) SetCanonicalBytes(in []byte) (*Element, error)

SetCanonicalBytes sets e to the decoded value of in. If in is not a canonical encoding of s, SetCanonicalBytes returns nil and an error and the receiver is unchanged.

func (*Element) SetUniformBytes

func (e *Element) SetUniformBytes(b []byte) (internal.Element, error)

SetUniformBytes deterministically sets e to an uniformly distributed value given 64 uniformly distributed random bytes.

This can be used for hash-to-group operations or to obtain a random element.

func (*Element) Subtract

func (e *Element) Subtract(ee internal.Element) internal.Element

Subtract subtracts the input from the receiver, and returns the receiver.

func (*Element) UnmarshalBinary

func (e *Element) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Element) UnmarshalText

func (e *Element) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Group

type Group struct{}

Group represents the Ristretto255 group. It exposes a prime-order group API with hash-to-curve operations.

func (*Group) Base

func (g *Group) Base() internal.Element

Base returns the group's base point a.k.a. canonical generator.

func (*Group) Ciphersuite

func (g *Group) Ciphersuite() string

Ciphersuite returns the hash-to-curve ciphersuite identifier.

func (*Group) ElementLength

func (g *Group) ElementLength() uint

ElementLength returns the byte size of an encoded element.

func (*Group) EncodeToGroup

func (g *Group) EncodeToGroup(input, dst []byte) internal.Element

EncodeToGroup returns a non-uniform mapping of the arbitrary input to an Element in the Group. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func (*Group) HashToGroup

func (g *Group) HashToGroup(input, dst []byte) internal.Element

HashToGroup returns a safe mapping of the arbitrary input to an Element in the Group. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func (*Group) HashToScalar

func (g *Group) HashToScalar(input, dst []byte) internal.Scalar

HashToScalar returns a safe mapping of the arbitrary input to a Scalar. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func (*Group) NewElement

func (g *Group) NewElement() internal.Element

NewElement returns the identity element (point at infinity).

func (*Group) NewScalar

func (g *Group) NewScalar() internal.Scalar

NewScalar returns a new, empty, scalar.

func (*Group) RandomElement

func (g *Group) RandomElement() internal.Element

RandomElement returns randomly generated element.

func (*Group) RandomScalar

func (g *Group) RandomScalar() internal.Scalar

RandomScalar returns randomly generated scalar.

func (*Group) ScalarLength

func (g *Group) ScalarLength() uint

ScalarLength returns the byte size of an encoded scalar.

type Scalar

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

Scalar represents the Ristretto255 curve Scalar point

func (*Scalar) Add

func (s *Scalar) Add(ss internal.Scalar) internal.Scalar

Add sets the receiver to the sum of the input and the receiver, and returns the receiver.

func (*Scalar) Copy

func (s *Scalar) Copy() internal.Scalar

Copy returns a copy of the receiver.

func (*Scalar) Decode

func (s *Scalar) Decode(in []byte) error

Decode sets the receiver to a decoding of the input data, and returns an error on failure.

func (*Scalar) Encode

func (s *Scalar) Encode() []byte

Encode returns the compressed byte encoding of the scalar.

func (*Scalar) Equal

func (s *Scalar) Equal(ss internal.Scalar) int

Equal returns 1 if the scalars are equal, and 0 otherwise.

func (*Scalar) Invert

func (s *Scalar) Invert() internal.Scalar

Invert sets the receiver to the scalar's modular inverse ( 1 / scalar ), and returns it.

func (*Scalar) IsZero

func (s *Scalar) IsZero() bool

IsZero returns whether the scalar is 0.

func (*Scalar) MarshalBinary

func (s *Scalar) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Scalar) MarshalText

func (s *Scalar) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Scalar) Multiply

func (s *Scalar) Multiply(ss internal.Scalar) internal.Scalar

Multiply multiplies the receiver with the input, and returns the receiver. If s parameter is nil, then the receiver is not modified

func (*Scalar) One

func (s *Scalar) One() internal.Scalar

One sets the scalar to 1, and returns it.

func (*Scalar) Random

func (s *Scalar) Random() internal.Scalar

Random sets the current scalar to a new random scalar and returns it. The random source is crypto/rand, and this functions is guaranteed to return a non-zero scalar.

func (*Scalar) Set

func (s *Scalar) Set(ss internal.Scalar) internal.Scalar

Set sets the receiver to the value of the argument scalar, and returns the receiver.

func (*Scalar) SetCanonicalBytes

func (s *Scalar) SetCanonicalBytes(x []byte) (*Scalar, error)

SetCanonicalBytes sets s = x, where x is a 32 bytes little-endian encoding of s. If x is not a canonical encoding of s, SetCanonicalBytes returns nil and an error and the receiver is unchanged.

func (*Scalar) SetUniformBytes

func (s *Scalar) SetUniformBytes(x []byte) (*Scalar, error)

SetUniformBytes sets s to an uniformly distributed value given 64 uniformly distributed random bytes. If x is not of the right length, SetUniformBytes returns nil and an error, and the receiver is unchanged.

func (*Scalar) Subtract

func (s *Scalar) Subtract(ss internal.Scalar) internal.Scalar

Subtract subtracts the input from the receiver, and returns the receiver.

func (*Scalar) UnmarshalBinary

func (s *Scalar) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Scalar) UnmarshalText

func (s *Scalar) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Scalar) Zero

func (s *Scalar) Zero() internal.Scalar

Zero sets the scalar to 0, and returns it.

Jump to

Keyboard shortcuts

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