common

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crt

func Crt(a *big.Int, pa *big.Int, b *big.Int, pb *big.Int) *big.Int

Find a number x (mod pa*pb) such that x = a (mod pa) and x = b (mod pb)

func FastRandomBigInt

func FastRandomBigInt(limit *big.Int) *big.Int

Derives a random number uniformly chosen below the given limit from a random 256 bit seed generated when the application starts.

func GetHashNumber

func GetHashNumber(a *big.Int, b *big.Int, index int, bitlen uint) *big.Int

GetHashNumber uses a hash to generate random numbers of a given bitlength in the fiat-shamir heuristic

func HashCommit

func HashCommit(values []*big.Int, issig bool) *big.Int

hashCommit computes the sha256 hash over the asn1 representation of a slice of big integers and returns a positive big integer that can be represented with that hash.

func IntHashSha256

func IntHashSha256(input []byte) *big.Int

intHashSha256 is a utility function compute the sha256 hash over a byte array and return this hash as a big.Int.

func LegendreSymbol

func LegendreSymbol(a, p *big.Int) int

legendreSymbol calculates the Legendre symbol (a/p).

func ModInverse

func ModInverse(a, n *big.Int) (ia *big.Int, ok bool)

modInverse returns ia, the inverse of a in the multiplicative group of prime order n. It requires that a be a member of the group (i.e. less than n). This function was taken from Go's RSA implementation

func ModPow

func ModPow(x, y, m *big.Int) *big.Int

modPow computes x^y mod m. The exponent (y) can be negative, in which case it uses the modular inverse to compute the result (in contrast to Go's Exp function).

func ModSqrt

func ModSqrt(a *big.Int, factors []*big.Int) (*big.Int, bool)

Calculate Sqrt modulo a number with given prime factors. Also allows 4 as a factor All factors should be relatively prime to each other!

func PrimeSqrt

func PrimeSqrt(a *big.Int, pa *big.Int) (*big.Int, bool)

Calculate sqrt modulo a prime

func RandomBigInt

func RandomBigInt(numBits uint) (*big.Int, error)

RandomBigInt returns a random big integer value in the range [0,(2^numBits)-1], inclusive.

func RandomPrimeInRange

func RandomPrimeInRange(rand io.Reader, start, length uint) (p *big.Int, err error)

RandomPrimeInRange returns a random probable prime in the range [2^start, 2^start + 2^length] This code is an adaption of Go's own Prime function in rand/util.go

func RandomQR

func RandomQR(n *big.Int) *big.Int

func RepresentToBases

func RepresentToBases(bases, exps []*big.Int, modulus *big.Int, maxMessageLength uint) *big.Int

RepresentToPublicKey returns a representation of the given exponents in terms of the R bases from the public key. For example given exponents exps[1],...,exps[k] this function returns

R[1]^{exps[1]}*...*R[k]^{exps[k]} (mod N)

with R and N coming from the public key. The exponents are hashed if their length exceeds the maximum message length from the public key.

Types

type CPRNG

type CPRNG struct {
	// contains filtered or unexported fields
}

Simple threadsafe cryptographically secure pseudo-random number generator.

Implemented with AES in counter mode with the seed as key and an atomic uint64 as counter.

func NewCPRNG

func NewCPRNG(seed *[32]byte) (*CPRNG, error)

func (*CPRNG) Read

func (c *CPRNG) Read(buf []byte) (n int, err error)

type FastMod

type FastMod struct {
	// contains filtered or unexported fields
}

func (*FastMod) Mod

func (m *FastMod) Mod(ret, x *big.Int) *big.Int

func (*FastMod) Set

func (m *FastMod) Set(p *big.Int)

Jump to

Keyboard shortcuts

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