package math

import "github.com/cloudflare/circl/math"

Package math provides some utility functions for big integers.

Index

Functions

func IsSafePrime

func IsSafePrime(p *big.Int) bool

IsSafePrime reports whether p is (probably) a safe prime. The prime p=2*q+1 is safe prime if both p and q are primes. Note that ProbablyPrime is not suitable for judging primes that an adversary may have crafted to fool the test.

func NextPow2

func NextPow2(n uint) (N uint, k uint)

NextPow2 finds the next power of two (N=2^k, k>=0) greater than n. If n is already a power of two, then this function returns n, and log2(n).

func OmegaNAF

func OmegaNAF(n *big.Int, w uint) (L []int32)

OmegaNAF obtains the window-w Non-Adjacent Form of a positive number n and 1 < w < 32. The returned slice L holds n = sum( L[i]*2^i ).

Reference:

func SafePrime

func SafePrime(random io.Reader, bits int) (*big.Int, error)

SafePrime returns a number of the given bit length that is a safe prime with high probability. The number returned p=2*q+1 is a safe prime if both p and q are primes. SafePrime will return error for any error returned by rand.Read or if bits < 2.

func SignedDigit

func SignedDigit(n *big.Int, w, l uint) []int32

SignedDigit obtains the signed-digit recoding of n and returns a list L of digits such that n = sum( L[i]*2^(i*(w-1)) ), and each L[i] is an odd number in the set {±1, ±3, ..., ±2^(w-1)-1}. The third parameter ensures that the output has ceil(l/(w-1)) digits.

Restrictions:

References:

Source Files

integer.go primes.go wnaf.go

Directories

PathSynopsis
math/fp25519Package fp25519 provides prime field arithmetic over GF(2^255-19).
math/fp448Package fp448 provides prime field arithmetic over GF(2^448-2^224-1).
math/mlsbsetPackage mlsbset provides a constant-time exponentiation method with precomputation.
math/polynomialPackage polynomial provides representations of polynomials over the scalars of a group.
Version
v1.6.1 (latest)
Published
Apr 9, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
2 days ago

Tools for package owners.