ristretto255

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: BSD-3-Clause Imports: 5 Imported by: 87

README

ristretto255

GoDoc

Package ristretto255 implements the group operations from RFC 9496, Section 4.3 and the scalar field from RFC 9496, Section 4.4.

Documentation

Overview

Package ristretto255 implements the group of prime order

2**252 + 27742317777372353535851937790883648493

and its scalar field, as specified in RFC 9496, Section 4.

All operations are constant time unless otherwise specified.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

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

Element is an element of the ristretto255 prime-order group.

func NewElement deprecated

func NewElement() *Element

NewElement returns a new Element set to the identity value.

Deprecated: use NewIdentityElement. This API will be removed before v1.0.0.

func NewGeneratorElement added in v0.2.0

func NewGeneratorElement() *Element

NewGeneratorElement returns a new Element set to the canonical generator.

func NewIdentityElement added in v0.2.0

func NewIdentityElement() *Element

NewIdentityElement returns a new Element set to the identity value.

func (*Element) Add

func (e *Element) Add(p, q *Element) *Element

Add sets e = p + q, and returns e.

func (*Element) Base deprecated

func (e *Element) Base() *Element

Base sets e to the canonical generator, and returns e.

Deprecated: use NewGeneratorElement and Set. This API will be removed before v1.0.0.

func (*Element) Bytes added in v0.2.0

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

Bytes returns the 32 bytes canonical encoding of e.

Bytes implements the Encode operation from RFC 9496, Section 4.3.2.

func (*Element) Decode deprecated

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

Decode sets e to the decoded value of in. If in is not a 32 byte canonical encoding, Decode returns an error, and the receiver is unchanged.

Deprecated: use SetCanonicalBytes. This API will be removed before v1.0.0.

func (*Element) Encode deprecated

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

Encode appends the 32 bytes canonical encoding of e to b and returns the result.

Deprecated: use Bytes. This API will be removed before v1.0.0.

func (*Element) Equal

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

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

Equal implements the Equals operation from RFC 9496, Section 4.3.3.

func (*Element) FromUniformBytes deprecated

func (e *Element) FromUniformBytes(b []byte) *Element

FromUniformBytes maps the 64-byte slice b to e uniformly and deterministically, and returns e. This can be used for hash-to-group operations or to obtain a random element.

Deprecated: use SetUniformBytes. This API will be removed before v1.0.0.

func (*Element) MarshalText added in v0.1.1

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

MarshalText implements encoding/TextMarshaler interface

func (*Element) MultiScalarMult

func (e *Element) MultiScalarMult(s []*Scalar, p []*Element) *Element

MultiScalarMult sets e = sum(s[i] * p[i]), and returns e.

Execution time depends only on the lengths of the two slices, which must match.

func (*Element) Negate

func (e *Element) Negate(p *Element) *Element

Negate sets e = -p, and returns e.

func (*Element) ScalarBaseMult

func (e *Element) ScalarBaseMult(s *Scalar) *Element

ScalarBaseMult sets e = s * B, where B is the canonical generator, and returns e.

func (*Element) ScalarMult

func (e *Element) ScalarMult(s *Scalar, p *Element) *Element

ScalarMult sets e = s * p, and returns e.

func (*Element) Set added in v0.2.0

func (e *Element) Set(x *Element) *Element

Set sets the value of e to x and returns e.

func (*Element) SetCanonicalBytes added in v0.2.0

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.

SetCanonicalBytes implements the Decode operation from RFC 9496, Section 4.3.1.

func (*Element) SetUniformBytes added in v0.2.0

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

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

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

SetUniformBytes implements the Element Derivation operation from RFC 9496, Section 4.3.4.

func (*Element) String added in v0.1.1

func (e *Element) String() string

String implements the Stringer interface

func (*Element) Subtract

func (e *Element) Subtract(p, q *Element) *Element

Subtract sets e = p - q, and returns e.

func (*Element) UnmarshalText added in v0.1.1

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

UnmarshalText implements encoding/TextMarshaler interface

func (*Element) VarTimeDoubleScalarBaseMult

func (e *Element) VarTimeDoubleScalarBaseMult(a *Scalar, A *Element, b *Scalar) *Element

VarTimeDoubleScalarBaseMult sets e = a * A + b * B, where B is the canonical generator, and returns e.

Execution time depends on the inputs.

func (*Element) VarTimeMultiScalarMult

func (e *Element) VarTimeMultiScalarMult(s []*Scalar, p []*Element) *Element

VarTimeMultiScalarMult sets e = sum(s[i] * p[i]), and returns e.

Execution time depends on the inputs.

func (*Element) Zero deprecated

func (e *Element) Zero() *Element

Zero sets e to the identity element of the group, and returns e.

Deprecated: use NewIdentityElement and Set. This API will be removed before v1.0.0.

type Scalar

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

A Scalar is an element of the ristretto255 scalar field, as specified in RFC 9496, Section 4.4. That is, an integer modulo

l = 2^252 + 27742317777372353535851937790883648493

The zero value is a valid zero element.

func NewScalar

func NewScalar() *Scalar

NewScalar returns a Scalar set to the value 0.

func (*Scalar) Add

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

Add sets s = x + y mod l and returns s.

func (*Scalar) Bytes added in v0.2.0

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

Bytes returns the 32 bytes little-endian canonical encoding of s.

func (*Scalar) Decode deprecated

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

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

Deprecated: use SetCanonicalBytes. This API will be removed before v1.0.0.

func (*Scalar) Encode deprecated

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

Encode appends a 32 bytes little-endian encoding of s to b.

Deprecated: use Bytes. This API will be removed before v1.0.0.

func (*Scalar) Equal

func (s *Scalar) Equal(u *Scalar) int

Equal returns 1 if v and u are equal, and 0 otherwise.

func (*Scalar) FromUniformBytes deprecated

func (s *Scalar) FromUniformBytes(x []byte) *Scalar

FromUniformBytes sets s to a uniformly distributed value given 64 uniformly distributed random bytes.

Deprecated: use SetUniformBytes. This API will be removed before v1.0.0.

func (*Scalar) Invert

func (s *Scalar) Invert(x *Scalar) *Scalar

Invert sets s = 1 / x such that s * x = 1 mod l and returns s.

If x is 0, the result is undefined.

func (*Scalar) MarshalText added in v0.1.1

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

MarshalText implements encoding/TextMarshaler interface

func (*Scalar) Multiply

func (s *Scalar) Multiply(x, y *Scalar) *Scalar

Multiply sets s = x * y mod l and returns s.

func (*Scalar) Negate

func (s *Scalar) Negate(x *Scalar) *Scalar

Negate sets s = -x mod l and returns s.

func (*Scalar) Set added in v0.2.0

func (s *Scalar) Set(x *Scalar) *Scalar

Set sets the value of s to x and returns s.

func (*Scalar) SetCanonicalBytes added in v0.2.0

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 added in v0.2.0

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

SetUniformBytes sets s to a uniformly distributed value given 64 uniformly distributed random bytes by interpreting the 64-byte string as a 512-bit unsigned integer in little-endian order and reducing the integer modulo l.

If x is not of the right length, SetUniformBytes returns nil and an error, and the receiver is unchanged.

func (*Scalar) String added in v0.1.1

func (s *Scalar) String() string

String implements the Stringer interface

func (*Scalar) Subtract

func (s *Scalar) Subtract(x, y *Scalar) *Scalar

Subtract sets s = x - y mod l and returns s.

func (*Scalar) UnmarshalText added in v0.1.1

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

UnmarshalText implements encoding/TextMarshaler interface

func (*Scalar) Zero

func (s *Scalar) Zero() *Scalar

Zero sets s = 0 and returns s.

Jump to

Keyboard shortcuts

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