nt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

nt - Number Theory

Foundational number theory primitives for cryptographic applications.

Subpackages

  • numct - Constant-time arbitrary precision integers (Nat, Int, Modulus)
  • num - Typed number structures with algebraic semantics (N, Z, Q, NatPlus, Uint, ZMod)
  • cardinal - Cardinal numbers for representing group orders (known, unknown, infinite)
  • modular - Modular arithmetic with CRT optimization for prime factorizations
  • crt - Machinery for Chinese Remainder Theorem
  • znstar - Multiplicative unit groups (Z/nZ)* for RSA and Paillier cryptosystems

Usage

// Generate RSA primes
p, q, _ := nt.GeneratePrimePair(num.NPlus(), 1024, rand.Reader)

// Create an RSA group
rsa, _ := znstar.NewRSAGroup(p, q)

// Create a Paillier group
paillier, _ := znstar.NewPaillierGroup(p, q)

Documentation

Overview

Package nt provides foundational number theory primitives for cryptographic applications.

See README.md for details.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSize = errs.New("invalid size")
	ErrIsNil       = errs.New("is nil")
)

Functions

func GeneratePrimePair

func GeneratePrimePair[N algebra.NatPlusLike[N]](set PrimeSamplable[N], bits uint, prng io.Reader) (p, q N, err error)

GeneratePrimePair generates two distinct prime numbers of the specified bit length using the provided PrimeSamplable set.

func GenerateSafePrime

func GenerateSafePrime[N algebra.NatPlusLike[N]](set PrimeSamplable[N], bits uint) (N, error)

GenerateSafePrime generates a safe prime of the specified bit length using the provided PrimeSamplable set.

func GenerateSafePrimePair

func GenerateSafePrimePair[N algebra.NatPlusLike[N]](set PrimeSamplable[N], bits uint) (p, q N, err error)

GenerateSafePrimePair generates two distinct safe primes of the specified bit length using the provided PrimeSamplable set.

func MillerRabinChecks

func MillerRabinChecks(bits uint) int

MillerRabinChecks returns the number of Miller-Rabin iterations required for a given bit length.

Types

type PrimeSamplable

type PrimeSamplable[E algebra.NatPlusLike[E]] interface {
	FromBig(*big.Int) (E, error)
}

PrimeSamplable is an interface for types that can sample prime numbers.

Directories

Path Synopsis
Package cardinal provides representations for cardinal numbers (cardinalities) used to express the size of algebraic structures such as groups, rings, and fields.
Package cardinal provides representations for cardinal numbers (cardinalities) used to express the size of algebraic structures such as groups, rings, and fields.
Package crt provides Chinese Remainder Theorem (CRT) reconstruction and decomposition for cryptographic applications.
Package crt provides Chinese Remainder Theorem (CRT) reconstruction and decomposition for cryptographic applications.
Package modular provides CRT-accelerated modular arithmetic for cryptographic applications such as RSA and Paillier.
Package modular provides CRT-accelerated modular arithmetic for cryptographic applications such as RSA and Paillier.
Package num provides arbitrary-precision arithmetic for cryptographic applications.
Package num provides arbitrary-precision arithmetic for cryptographic applications.
Package numct provides constant-time arbitrary-precision arithmetic for cryptographic applications.
Package numct provides constant-time arbitrary-precision arithmetic for cryptographic applications.
Package znstar provides multiplicative groups of units modulo n, denoted (Z/nZ)*, for cryptographic applications such as RSA and Paillier encryption.
Package znstar provides multiplicative groups of units modulo n, denoted (Z/nZ)*, for cryptographic applications such as RSA and Paillier encryption.

Jump to

Keyboard shortcuts

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