Math Utilities

The math/ directory provides small numeric helpers and constants used across cdough.

Contents:

  • math.h – Convenience umbrella header that includes primes.h and util.h.

  • primes.h – Named prime-number constants (including Mersenne primes) used by the protocols.

  • util.h – Numeric utilities such as div_ceil, log2, and NTL-backed big-integer helpers.

Defines prime number constants used throughout the codebase.

This file provides named constants for commonly used primes, including Mersenne primes which are useful for cryptographic operations.

namespace cdough
namespace math
namespace primes

Functions

std::pair<NTL::ZZ, int> primorial_gt_bits(int reqBits)

Return the first primorial with more than reqBits bits; that is, the smallest \(n#\) such that \(\log2(n#)>\mathtt{reqBits}-1\).

Only consider primes < 256, or primorials with fewer than 335 bits.

Parameters:

reqBits

Returns:

std::pair<NTL::ZZ, int> The primorial and the number of primes, or zero and negative one if no such primorial was found.

Variables

const std::vector<uint8_t> PRIMES_WITHIN_BYTE{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251}

All primes that fit within 8 bits (1 byte).

uint64_t MERSENNE_61 = (1ULL << 61) - 1

Mersenne primes of the form 2^p - 1.

Mersenne primes are primes of the form M_p = 2^p - 1, where p itself must be prime. Mersenne prime M_61 = 2^61 - 1

__uint128_t MERSENNE_127 = ((__uint128_t)1 << 127) - 1

Mersenne prime M_127 = 2^127 - 1.

namespace cdough
namespace math

Functions

double log2(NTL::ZZ x)
template<typename T>
T div_ceil(T x, T y)
template<typename T>
NTL::ZZ to_ZZ(T x)

Convert a T to an arbitrary-precision NTL integer.

Template Parameters:

T

Parameters:

x

Returns:

NTL::ZZ

template<typename T>
T from_ZZ(NTL::ZZ x)

Convert an NTL ZZ integer to a T, possibly destructively.

Template Parameters:

T

Parameters:

x

Returns:

T

Variables

const NTL::ZZ pow_128 = NTL::ZZ(1) << 128