prime

package
v0.0.0-...-3948e75 Latest Latest
Warning

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

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

Documentation

Overview

Package prime provides representations of classes of prime numbers.

Index

Constants

This section is empty.

Variables

View Source
var (
	// P2213 is the prime 2²²¹ - 3 used in curve M-221 [aranha].
	P2213 = NewCrandall(221, 3)

	// P222117 is the prime 2²²² - 117 used in curve E-222 [aranha].
	P222117 = NewCrandall(222, 117)

	// P2519 is the prime 2²⁵¹ - 9 used in Curve1174 [elligator].
	P2519 = NewCrandall(251, 9)

	// P25519 is the prime 2²⁵⁵ - 19 used in Curve25519 [curve25519].
	P25519 = NewCrandall(255, 19)

	// P382105 is the prime 2³⁸² - 105 used in curve E-382 [aranha].
	P382105 = NewCrandall(382, 105)

	// P383187 is the prime 2³⁸³ - 187 used in curves M-383 and Curve383187 [aranha].
	P383187 = NewCrandall(383, 187)

	// P41417 is the prime 2⁴¹⁴ - 17 used in Curve41417 [nistdanger].
	P41417 = NewCrandall(414, 17)

	// P511187 is the prime 2⁵¹¹ - 187 used in M-511 [aranha].
	P511187 = NewCrandall(511, 187)

	// NISTP192 is the P-192 prime 2¹⁹² - 2⁶⁴ - 1 defined in [fips186-2].
	NISTP192 = NewSolinas(polynomial.Polynomial{{A: -1, N: 0}, {A: -1, N: 1}, {A: 1, N: 3}}, 64)

	// NISTP224 is the P-224 prime 2²²⁴ - 2⁹⁶ + 1 defined in [fips186-2].
	NISTP224 = NewSolinas(polynomial.Polynomial{{A: 1, N: 0}, {A: -1, N: 3}, {A: 1, N: 7}}, 32)

	// NISTP256 is the P-256 prime 2²⁵⁶ - 2²²⁴ + 2¹⁹² + 2⁹⁶ - 1 defined in [fips186-2].
	NISTP256 = NewSolinas(polynomial.Polynomial{{A: -1, N: 0}, {A: +1, N: 3}, {A: +1, N: 6}, {A: -1, N: 7}, {A: +1, N: 8}}, 32)

	// NISTP384 is the P-384 prime 2³⁸⁴ - 2¹²⁸ - 2⁹⁶ + 2³² - 1 defined in [fips186-2].
	NISTP384 = NewSolinas(polynomial.Polynomial{{A: -1, N: 0}, {A: 1, N: 1}, {A: -1, N: 3}, {A: -1, N: 4}, {A: 1, N: 12}}, 32)

	// Goldilocks is the prime 2⁴⁴⁸ - 2²²⁴ - 1 defined in [goldilocks].
	Goldilocks = NewSolinas(polynomial.Polynomial{{A: -1, N: 0}, {A: -1, N: 1}, {A: 1, N: 2}}, 224)

	// Secp192k1 is the prime for the 192-bit Koblitz curve recommended in [sec2].
	Secp192k1 = MustHex("FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFE_FFFFEE37")

	// Secp192r1 is the prime for the 192-bit "random" curve recommended in [sec2].
	Secp192r1 = NISTP192

	// Secp224k1 is the prime for the 224-bit Koblitz curve recommended in [sec2].
	Secp224k1 = MustHex("FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFE_FFFFE56D")

	// Secp224r1 is the prime for the 224-bit "random" curve recommended in [sec2].
	Secp224r1 = NISTP224

	// Secp256k1 is the prime for the 256-bit Koblitz curve recommended in [sec2].
	Secp256k1 = MustHex("FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFE_FFFFFC2F")

	// Secp256r1 is the prime for the 256-bit "random" curve recommended in [sec2].
	Secp256r1 = NISTP256

	// Secp384r1 is the prime for the 384-bit "random" curve recommended in [sec2].
	Secp384r1 = NISTP384
)

Distinguished is a list of well-known primes.

Functions

This section is empty.

Types

type Crandall

type Crandall struct {
	N int
	C int
}

Crandall represents a prime of the form 2ⁿ - c. Named after Richard E. Crandall [crandallprime].

func NewCrandall

func NewCrandall(n, c int) Crandall

NewCrandall constructs a Crandall prime.

func (Crandall) Bits

func (p Crandall) Bits() int

Bits returns the number of bits required to represent p.

func (Crandall) Int

func (p Crandall) Int() *big.Int

Int returns the prime as a big integer.

func (Crandall) String

func (p Crandall) String() string

type Other

type Other struct {
	P *big.Int
}

Other is a prime whose structure does not match any of the other specific types in this package.

func MustHex

func MustHex(p string) Other

MustHex parses a prime from the hex literal p. Panics on error.

func NewOther

func NewOther(p *big.Int) Other

NewOther builds a prime from the provided integer.

func (Other) Bits

func (p Other) Bits() int

Bits returns the bit length of p.

func (Other) Int

func (p Other) Int() *big.Int

Int returns p as an integer.

func (Other) String

func (p Other) String() string

type Prime

type Prime interface {
	Bits() int
	Int() *big.Int
	fmt.Stringer
}

Prime is the interface for a prime number.

type Solinas

type Solinas struct {
	F polynomial.Polynomial
	K uint
}

Solinas is a "Generalized Mersenne Prime", as introduced by Jerome Solinas [solinasprime]. Such primes are of the form f( 2ᵏ ) for a low-degree polynomial f.

func NewSolinas

func NewSolinas(f polynomial.Polynomial, k uint) Solinas

NewSolinas constructs a Solinas prime.

func (Solinas) Bits

func (p Solinas) Bits() int

Bits returns the number of bits required to represent p.

func (Solinas) Int

func (p Solinas) Int() *big.Int

func (Solinas) String

func (p Solinas) String() string

Jump to

Keyboard shortcuts

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