field

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: BSD-3-Clause Imports: 5 Imported by: 4

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.
	Polynomial() []*big.Int // Returns a polynomial representation 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.
	Sgn0(x Elt) int            // Returns the sign of x.
	// contains filtered or unexported methods
}

Field describes the operations required to implement a finite field.

func NewFp

func NewFp(name string, 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.

Jump to

Keyboard shortcuts

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