Documentation ¶
Index ¶
- Variables
- func Close(o io.Closer)
- func Crt(a *big.Int, pa *big.Int, b *big.Int, pb *big.Int) *big.Int
- func FastRandomBigInt(limit *big.Int) *big.Int
- func GetHashNumber(a *big.Int, b *big.Int, index int, bitlen uint) *big.Int
- func HashCommit(values []*big.Int, issig bool) *big.Int
- func IntHashSha256(input []byte) *big.Int
- func LegendreSymbol(a, p *big.Int) int
- func ModInverse(a, n *big.Int) (ia *big.Int, ok bool)
- func ModPow(x, y, m *big.Int) (*big.Int, error)
- func ModSqrt(a *big.Int, factors []*big.Int) (*big.Int, bool)
- func PrimeSqrt(a *big.Int, pa *big.Int) (*big.Int, bool)
- func RandomBigInt(numBits uint) (*big.Int, error)
- func RandomPrimeInRange(rand io.Reader, start, length uint) (p *big.Int, err error)
- func RandomQR(n *big.Int) *big.Int
- func RepresentToBases(bases, exps []*big.Int, modulus *big.Int, maxMessageLength uint) *big.Int
- func SumFourSquares(n *big.Int) (*big.Int, *big.Int, *big.Int, *big.Int)
- type CPRNG
- type FastMod
Constants ¶
This section is empty.
Variables ¶
var ErrNoModInverse = errors.New("modular inverse does not exist")
var SmallPrimes = []uint8{
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
}
SmallPrimes is a list of small prime numbers that allows us to rapidly exclude some fraction of composite candidates when searching for a random prime. This list is truncated at the point where SmallPrimesProduct exceeds a uint64. It does not include two because we ensure that the candidates are odd by construction.
var SmallPrimesProduct = new(big.Int).SetUint64(16294579238595022365)
SmallPrimesProduct is the product of the values in SmallPrimes and allows us to reduce a candidate prime by this number and then determine whether it's coprime with all the elements of SmallPrimes without further big.Int operations.
Functions ¶
func FastRandomBigInt ¶
FastRandomBigInt derives a random number uniformly chosen below the given limit from a random 256 bit seed generated when the application starts.
func GetHashNumber ¶
GetHashNumber uses a hash to generate random numbers of a given bit-length in the fiat-shamir heuristic
func HashCommit ¶
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 ¶
IntHashSha256 is a utility function which computes the sha256 hash over a byte array and returns this hash as a big.Int.
func LegendreSymbol ¶
LegendreSymbol calculates the Legendre symbol (a/p).
func ModInverse ¶
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 ¶
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 ¶
ModSqrt calculates Sqrt modulo a number with given prime factors. Also allows 4 as a factor All factors should be relatively prime to each other!
func RandomBigInt ¶
RandomBigInt returns a random big integer value in the range [0,(2^numBits)-1], inclusive.
func RandomPrimeInRange ¶
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 RepresentToBases ¶
RepresentToBases 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.