field

package
v0.0.0-...-3c8af55 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package field provides implementations of finite fields of large-prime characteristic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromType

func FromType(in interface{}) *big.Int

FromType converts an int, uint or string to a big.Int.

Types

type Elt

type Elt interface {
	Copy() Elt // Makes a copy of the element.
}

Elt represents a finite field element.

type Field

type Field interface {
	// Constructing elements
	Zero() Elt            // Returns the Zero element.
	One() Elt             // Returns the One element.
	Elt(interface{}) Elt  // Constructor of elements from an int, uint, or string.
	Rand(r io.Reader) Elt // Returns an elements chosen at random.
	Generator() Elt       // Returns an additive generator.
	// Properties
	P() *big.Int     // Characteristic of the field.
	Order() *big.Int // Size of the field.
	Ext() uint       // Extension degree of field.
	BitLen() int     // Bit length of modulus.
	// Predicates
	AreEqual(Elt, Elt) bool // Returns true if both elements are equivalent.
	IsZero(Elt) bool        // Returns true if the element is equivalent to zero.
	IsSquare(Elt) bool      // Returns true if the element is a quadratic residue.
	IsEqual(Field) bool     // Returns true if the input field is equal to the receiver.
	// Arithmetic operations
	Neg(x Elt) Elt             // Returns -x.
	Add(x, y Elt) Elt          // Returns x+y.
	Sub(x, y Elt) Elt          // Returns x-y.
	Mul(x, y Elt) Elt          // Returns x*y.
	Sqr(x Elt) Elt             // Returns x^2.
	Inv(x Elt) Elt             // Returns 1/x.
	Exp(x Elt, n *big.Int) Elt // Returns x^n.
	Inv0(Elt) Elt              // Returns 1/x, and 0 if x=0.
	CMov(x, y Elt, b bool) Elt // Returns x if b=false, otherwise, returns y.
	GetSgn0(Sgn0ID) func(Elt) int
	// contains filtered or unexported methods
}

Field describes the operations required to implement a finite field.

func NewFp

func NewFp(id ID, p interface{}) Field

NewFp creates a prime field as Z/pZ given p as an int, uint, *big.Int or string.

func NewFp2

func NewFp2(name string, p interface{}) Field

NewFp2 creates a quadratic extension field Z/pZ[x] with irreducible polynomial x^2=-1 and given p as an int, uint, *big.Int or string.

type ID

type ID int

ID is an identifier of a well-known prime modulus.

const (
	// P25519 is 2^255-19
	P25519 ID = iota + 1
	// P256 is 2^256-2^224+2^192+2^96-1
	P256
	// P256K1 is 2^256-2^32-977
	P256K1
	// P384 is 2^384-2^128-2^96+2^32-1
	P384
	// P448 is 2^448-2^224-1
	P448
	// P521 is 2^521-1
	P521
	// BLS12381 is a 381-bit prime,
	BLS12381
)

func (ID) Get

func (id ID) Get() Field

Get returns an implementation of a field corresponding to the identifier.

func (ID) String

func (id ID) String() string

type Sgn0ID

type Sgn0ID int

Sgn0ID is an identifier of a sign function.

const (
	// SignLE denotes little-endian sign function.
	SignLE Sgn0ID = iota
	// SignBE denotes big-endian sign function.
	SignBE
)

Jump to

Keyboard shortcuts

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