Random
The random/ directory provides all randomness and correlation generators required by cdough’s protocols.
Below is an overview of its immediate contents:
permutations/– Families of permutation generators for sharded permutations.pooled/– A pooled randomness wrapper generator that allows for separating generation from retrieval.correlation/- correlation generators, including beaver triples, OPRFs, and OTsprg/- local and shared PRG interfaces
Permutations
-
namespace cdough
-
namespace random
Functions
Set up a pair of DMShardedPermutation correlations with shared CommonPRG.
- Parameters:
perm1 – The first permutation in the pair.
perm2 – The second permutation in the pair.
-
class PermutationManager
- #include <permutation_manager.h>
Singleton class for managing permutation correlations.
Manages queues of individual permutations and pairs of permutations for efficient batch generation and retrieval.
Public Functions
-
inline PermutationManager()
Empty constructor for the PermutationManager.
-
void operator=(const PermutationManager&) = delete
Delete assignment operator (singleton pattern).
-
inline size_t size()
Get the number of sharded permutations in the queue.
- Returns:
The number of sharded permutations in the queue.
-
inline size_t size_pairs()
Get the number of pairs of sharded permutations in the queue.
- Returns:
The number of pairs of sharded permutations in the queue.
-
template<typename Engine>
inline void reserve(size_t size_permutation, size_t num_permutations, Engine &engine, size_t num_pairs = 0) Reserve a number of sharded permutations in the queue.
- Parameters:
size_permutation – The size of each sharded permutation.
num_permutations – The number of sharded permutations to reserve.
engine – The engine used to generate the permutations.
num_pairs – (2PC only) how many pairs of correlated permutations to reserve.
Get the next sharded permutation in the queue.
- Parameters:
size_permutation – The size of the permutation to get.
engine – The engine used to get the permutation.
dm_encoding – The encoding type for the permutation.
- Returns:
The next sharded permutation in the queue.
Get a pair of sharded permutations.
- Parameters:
size_permutation – The size of the permutation to get.
engine – The engine used to get the permutations.
dm_encoding_1 – The encoding type for the first permutation.
dm_encoding_2 – The encoding type for the second permutation.
- Returns:
A pair containing two sharded permutations.
Public Static Functions
-
static inline std::shared_ptr<PermutationManager> get()
Get the singleton instance of the PermutationManager.
- Returns:
The singleton instance of the PermutationManager.
Private Members
-
std::queue<std::shared_ptr<ShardedPermutation>> queue
-
std::queue<std::pair<std::shared_ptr<ShardedPermutation>, std::shared_ptr<ShardedPermutation>>> pair_queue
-
size_t stored_size = 0
-
bool have_shown_warning = false
Private Static Attributes
-
static std::shared_ptr<PermutationManager> instance = nullptr
-
inline PermutationManager()
-
namespace random
-
class ShardedPermutation
An abstract base class for sharded permutations.
Subclassed by cdough::random::DMShardedPermutation< T >, cdough::random::HMShardedPermutation, cdough::random::ZeroPermutation
Public Functions
-
virtual ~ShardedPermutation() = default
-
virtual size_t size() = 0
-
virtual std::shared_ptr<ShardedPermutation> clone() = 0
-
virtual ~ShardedPermutation() = default
-
class HMShardedPermutation : public cdough::random::ShardedPermutation
Honest Majority Sharded Permutation
A map from permutation groups to local permutaitons.
Public Functions
-
inline HMShardedPermutation()
Empty constructor that makes an empty map.
A constructor that takes an existing map and assigns it to the underlying data.
- Parameters:
_perm – The sharded permutation to set the underlying permutation to.
-
inline HMShardedPermutation(size_t _size)
-
inline std::shared_ptr<std::map<Group, LocalPermutation>> getPermMap()
Expose the underlying permutation map.
-
inline virtual size_t size()
Get the size of the permutation.
- Returns:
The size of the permutation.
-
inline virtual std::shared_ptr<ShardedPermutation> clone()
Create a copy of the permutation.
- Returns:
A shared pointer to the cloned permutation.
-
inline HMShardedPermutation()
-
template<typename T>
class DMShardedPermutation : public cdough::random::ShardedPermutation Dishonest Majority Sharded Permutation
A tuple of a pair of local permutations and three random vectors subject to pi(A) = B + C.
- Template Parameters:
T – The data type for the permutation correlation elements
Public Functions
-
inline DMShardedPermutation(size_t n)
Constructor that takes the size of the permutation correlation (the minimal amount of information) and defaults to binary encoding.
- Parameters:
n – The size of the permutation correlation.
-
inline DMShardedPermutation(size_t n, cdough::Encoding _encoding)
Constructor that takes the size of the permutation correlation and an encoding type.
- Parameters:
n – The size of the permutation correlation.
_encoding – The encoding type of the permutation correlation.
-
inline DMShardedPermutation(dm_perm_t _perm, cdough::Encoding _encoding)
Constructor that takes an existing permutation correlation and an encoding type.
- Parameters:
_perm – The existing permutation correlation.
_encoding – The encoding type of the permutation correlation.
-
inline std::shared_ptr<dm_perm_t> getTuple()
Expose the underlying data through a getter function.
- Returns:
A shared pointer to the underlying data.
-
inline cdough::Encoding getEncoding()
Expose the type of the correlation through a getter function.
- Returns:
The encoding type of the permutation correlation.
-
inline bool hasCommonPRG()
Expose the existence of a CommonPRG through a getter function.
- Returns:
True if a CommonPRG is set, false otherwise.
-
inline std::shared_ptr<CommonPRG> getCommonPRG()
Expose the CommonPRG through a getter function.
- Returns:
A shared pointer to the CommonPRG.
-
inline virtual size_t size()
Get the size of the permutation.
- Returns:
The size of the permutation.
-
inline virtual std::shared_ptr<ShardedPermutation> clone()
Create a deep copy of the permutation.
- Returns:
A shared pointer to the cloned permutation.
-
template<typename T>
class DMShardedPermutationGenerator : public cdough::random::ShardedPermutationGenerator Dishonest Majority Sharded Permutation Generator
Currently only supports 2PC
Public Functions
-
inline DMShardedPermutationGenerator(int _rank, std::optional<Communicator*> _comm = std::nullopt)
Constructor for DMShardedPermutationGenerator.
- Parameters:
_rank – The rank of the current party.
_comm – An optional pointer to a Communicator instance for communication purposes. Defaults to std::nullopt if not provided.
-
inline virtual std::shared_ptr<ShardedPermutation> getNext(const size_t n)
Generate and return a DMShardedPermutation.
- Parameters:
n – The size of the permutation.
- Returns:
The DMShardedPermutation.
-
inline virtual std::vector<std::shared_ptr<ShardedPermutation>> allocate(size_t num_permutations, size_t size_permutation)
Allocate memory for many DMShardedPermutations so they can be passed to and generated by the runtime.
- Parameters:
num_permutations – The number of permutations to allocate memory for.
size_permutation – The size of the permutations.
- Returns:
A vector of empty DMShardedPermutations.
Generate a batch of DMShardedPermutations, invoked by the runtime.
- Parameters:
ret – A vector of DMShardedPermutations to fill.
Verify that the permutation correlation is correct.
- Parameters:
perm – The permutation to verify.
-
inline Communicator *getComm() const
Expose the Communicator through a getter function.
Protected Attributes
-
std::optional<Communicator*> comm
-
inline DMShardedPermutationGenerator(int _rank, std::optional<Communicator*> _comm = std::nullopt)
Warning
doxygenclass: Cannot find class “cdough::random::DMDummyGenerator” in doxygen xml output for project “cdough” from directory: xml
Warning
doxygenclass: Cannot find class “cdough::random::DMPermutationCorrelationGenerator” in doxygen xml output for project “cdough” from directory: xml
-
namespace cdough
-
namespace random
-
class ZeroPermutation : public cdough::random::ShardedPermutation
- #include <zero_permutation_generator.h>
Public Functions
-
inline ZeroPermutation()
Default constructor.
-
inline ZeroPermutation(size_t size)
Constructor with size.
- Parameters:
size – The size of the permutation.
-
inline virtual size_t size()
Get the size of the permutation.
- Returns:
The size of the permutation.
-
inline virtual std::shared_ptr<ShardedPermutation> clone()
Create a copy of the permutation.
- Returns:
A shared pointer to the cloned permutation.
Private Members
-
size_t m_size
-
inline ZeroPermutation()
-
class ZeroPermutationGenerator : public cdough::random::ShardedPermutationGenerator
- #include <zero_permutation_generator.h>
Zero “Permutation” Generator. DOES NOT generate permutations. For cost model purposes only.
Public Functions
Constructor for the zero permutation generator.
- Parameters:
_rank – The rank of this party.
_commonPRGManager – The CommonPRGManager (unused).
_groups – The groups (unused).
-
inline virtual std::shared_ptr<ShardedPermutation> getNext(const size_t n)
Generate a mapping of permutations for the given size.
- Parameters:
n – The size of the permutations to generate.
- Returns:
A set of permutations, one for each group.
-
inline virtual std::vector<std::shared_ptr<ShardedPermutation>> allocate(size_t num_permutations, size_t size_permutation)
Allocate memory for zero permutations.
- Parameters:
num_permutations – The number of permutations to allocate.
size_permutation – The size of each permutation.
- Returns:
A vector of zero permutations.
Generate a batch of zero permutations (no-op).
- Parameters:
ret – A vector of permutations.
-
class ZeroPermutation : public cdough::random::ShardedPermutation
-
namespace random
Randomness Generators
-
namespace cdough
-
namespace random
-
class RandomGenerator
- #include <random_generator.h>
Base class for random number generators.
Provides a common interface for generating pseudorandom numbers.
Subclassed by cdough::random::CorrelationGenerator< TensorT >, cdough::random::CorrelationGenerator< std::tuple< TensorT, TensorT, TensorT > >, cdough::random::CorrelationGenerator< std::tuple< S< T >, S< T >, S< T > > >, cdough::random::CorrelationGenerator< std::tuple< Vector< T >, Vector< T > > >, cdough::random::CorrelationGenerator< std::tuple< Vector< uint8_t >, Vector< uint16_t > > >, cdough::random::CorrelationGenerator< std::tuple< Vector< Ts >… > >, cdough::random::CorrelationGenerator< Corr >, cdough::random::PseudoRandomGenerator, cdough::random::ShardedPermutationGenerator
Public Functions
-
inline RandomGenerator()
Default constructor that generates a seed automatically.
-
inline RandomGenerator(unsigned short _seed)
Constructor with provided seed.
- Parameters:
_seed – The seed randomness.
-
inline virtual ~RandomGenerator()
Virtual destructor.
Private Members
-
unsigned short seed
Private Static Functions
-
static inline unsigned short generate_seed()
Helper function to generate a secure seed.
- Returns:
A seed value (currently returns 0 - TODO: implement).
-
inline RandomGenerator()
-
class RandomGenerator
-
namespace random
Defines
-
__DEFAULT_PRGALGORITHM_BUFFER_SIZE
-
__MAX_AES_QUERY_BYTES
-
__MAX_DEV_URANDOM_QUERY_BYTES
-
__MAX_XCHACHA20_QUERY_BYTES
-
namespace cdough
-
namespace random
-
class AESPRGAlgorithm : public cdough::random::DeterministicPRGAlgorithm
- #include <prg_algorithm.h>
AES-based deterministic PRG implementation.
Uses AES-256-GCM for pseudorandom number generation with nonce management.
Public Functions
-
inline AESPRGAlgorithm(std::vector<unsigned char> &_seed)
Creates an AESPRGAlgorithm object.
- Parameters:
_seed – The seed shared between the parties.
-
inline virtual void fillBytes(std::span<uint8_t> dest) override
Fill destination with AES-generated random bytes.
- Parameters:
dest – The span to fill with random bytes.
-
inline virtual void setSeed(std::vector<unsigned char> &_seed) override
Set the AES key from seed bytes.
- Parameters:
_seed – The seed bytes to use as AES key.
-
inline virtual void incrementNonce() override
Increment the nonce counter.
Public Static Functions
-
static inline void aesKeyGen(std::span<unsigned char> key)
Generate a random AES key.
- Parameters:
key – The span to fill with the generated key.
Public Static Attributes
-
static const size_t MAX_AES_QUERY_BYTES = (1 << 20)
Protected Functions
-
inline virtual size_t getPreferredBufferSize() override
Returns the size of the buffer allocated to temporarily store random numbers before they are copied to Vectors.
- Returns:
The preferred buffer size in bytes.
Private Functions
-
inline void aesGenerateValues(std::span<uint8_t> dest)
Generate random bytes using AES-256-GCM.
- Parameters:
dest – The span to fill with random bytes.
-
inline AESPRGAlgorithm(std::vector<unsigned char> &_seed)
-
class DeterministicPRGAlgorithm : public cdough::random::PRGAlgorithm
- #include <prg_algorithm.h>
Base class for deterministic PRG algorithms.
Extends PRGAlgorithm with seed management and nonce functionality.
Subclassed by cdough::random::AESPRGAlgorithm, cdough::random::XChaCha20PRGAlgorithm
Public Functions
-
virtual void setSeed(std::vector<unsigned char> &seed) = 0
Sets the seed for generation of random numbers.
- Parameters:
seed – The seed bytes to use.
-
virtual ~DeterministicPRGAlgorithm() = default
Virtual destructor.
-
virtual void incrementNonce() = 0
Increment the algorithm’s nonce, if applicable.
If this algorithm has no nonce, this is a nop. Used to keep PRGs in sync when shared by multiple parties.
-
virtual void setSeed(std::vector<unsigned char> &seed) = 0
-
class DevUrandomPRGAlgorithm : public cdough::random::PRGAlgorithm
- #include <prg_algorithm.h>
PRG implementation using /dev/urandom.
Generates random numbers by reading from the system’s /dev/urandom device.
Public Functions
-
inline virtual void fillBytes(std::span<uint8_t> dest) override
Fill destination with random bytes from /dev/urandom.
- Parameters:
dest – The span to fill with random bytes.
Protected Functions
-
inline virtual size_t getPreferredBufferSize() override
Returns the size of the buffer allocated to temporarily store random numbers before they are copied to Vectors.
- Returns:
The preferred buffer size in bytes.
Private Static Attributes
-
static const size_t MAX_DEV_URANDOM_QUERY_BYTES = (1 << 20)
-
inline virtual void fillBytes(std::span<uint8_t> dest) override
-
class PRGAlgorithm
- #include <prg_algorithm.h>
Base class for pseudorandom generation algorithms.
Provides a common interface for different PRG implementations.
Subclassed by cdough::random::DeterministicPRGAlgorithm, cdough::random::DevUrandomPRGAlgorithm
Public Functions
-
virtual void fillBytes(std::span<uint8_t> dest) = 0
Fills dest with random data.
- Parameters:
dest – The span to fill with random bytes.
Protected Functions
-
inline virtual size_t getPreferredBufferSize()
Returns the size of the buffer allocated to temporarily store random numbers before they are copied to Vectors.
- Returns:
The preferred buffer size in bytes.
Protected Static Attributes
-
static thread_local std::vector<uint8_t> thread_buffer
Private Functions
-
template<typename T>
inline void getNextBuffered(Vector<T> &nums, std::span<uint8_t> buffer) Fills nums with random data.
- Template Parameters:
T – The data type for the vector elements.
- Parameters:
nums – The Vector to fill.
buffer – A buffer to hold the randomly generated values before they are copied into the Vector. It must be large enough to contain at least one element (
sizeof(T)). This buffer is necessary because the Vector may be a non-contiguous view of a block of memory, and therefore that memory can’t be filled directly with the random data.
-
virtual void fillBytes(std::span<uint8_t> dest) = 0
-
class XChaCha20PRGAlgorithm : public cdough::random::DeterministicPRGAlgorithm
- #include <prg_algorithm.h>
XChaCha20-based deterministic PRG implementation.
Uses XChaCha20 stream cipher for pseudorandom number generation with nonce management.
Public Functions
-
inline XChaCha20PRGAlgorithm(std::vector<unsigned char> &_seed)
Creates an XChaCha20PRGAlgorithm object.
- Parameters:
_seed – The seed shared between the parties.
-
inline virtual void fillBytes(std::span<uint8_t> dest) override
Fill destination with XChaCha20-generated random bytes.
- Parameters:
dest – The span to fill with random bytes.
-
inline virtual void setSeed(std::vector<unsigned char> &_seed) override
Set the XChaCha20 key from seed bytes.
- Parameters:
_seed – The seed bytes to use as XChaCha20 key.
-
inline virtual void incrementNonce() override
Increment the nonce counter.
Public Static Functions
-
static inline void xchacha20KeyGen(std::span<unsigned char> key)
Generate a random XChaCha20 key.
- Parameters:
key – The span to fill with the generated key.
Public Static Attributes
-
static const size_t MAX_XCHACHA20_QUERY_BYTES = (1 << 20)
Protected Functions
-
inline virtual size_t getPreferredBufferSize() override
Returns the size of the buffer allocated to temporarily store random numbers before they are copied to Vectors.
- Returns:
The preferred buffer size in bytes.
Private Functions
-
inline void xchacha20GenerateValues(std::span<uint8_t> dest)
-
inline XChaCha20PRGAlgorithm(std::vector<unsigned char> &_seed)
-
class AESPRGAlgorithm : public cdough::random::DeterministicPRGAlgorithm
-
namespace random
-
namespace cdough
-
namespace random
-
class CommonPRG
- #include <common_prg.h>
Subclassed by cdough::random::ZeroRandomGenerator
Public Functions
-
inline CommonPRG()
Default constructor with rank -1.
-
inline CommonPRG(int rank)
Constructor that generates a random seed.
- Parameters:
rank – The rank of this party.
-
inline CommonPRG(std::unique_ptr<DeterministicPRGAlgorithm> _prg_algorithm, int rank, std::optional<Communicator*> _comm = std::nullopt)
Constructor with provided PRG algorithm.
- Parameters:
_prg_algorithm – The PRG algorithm to use.
rank – The rank of this party.
_comm – Optional communicator.
-
template<typename T>
inline void getNext(T &num) Generates random bytes to fill one T.
- Parameters:
num – The reference to fill with random bytes.
-
template<typename T>
inline void getNext(Vector<T> &nums) Generate many next elements from the PRF.
- Parameters:
nums – The vector to fill with pseudorandom numbers.
-
inline void getNext(Vector<NTL::GF2E> &nums)
Generate many random GF2E elements using the CommonPRG. Use NTL’s bytes-to-GF2X conversion followed by a modular reduction. This is only secure as long as the polynomial modulus has degree 8k for some integer k (thus fitting cleanly into a span of random bytes).
param nums
- Tparam :
-
inline void incrementNonce()
Increment nonce if required.
Private Members
-
std::unique_ptr<DeterministicPRGAlgorithm> prg_algorithm
-
inline CommonPRG()
-
class CommonPRGManager
- #include <common_prg.h>
Manages CommonPRG objects for multiple parties and groups.
Maps party ranks and groups to their corresponding CommonPRG instances.
Public Functions
-
inline CommonPRGManager()
Construct an empty CommonPRG manager with one party (i.e., local PRG only.)
-
inline CommonPRGManager(int _num_parties)
Initializes the CommonPRGManager object with the current party index.
- Parameters:
_num_parties – The number of parties.
Add a CommonPRG object to the manager. The manager handles the index mapping.
- Parameters:
common_prg – A pointer to the CommonPRG to be added to the manager.
relative_rank – The relative rank of the party the prg is shared with.
Add a CommonPRG object to the manager by group. The manager handles the group mapping.
-
inline CommonPRGManager()
-
class CommonPRG
-
namespace random
Implements PRG via CommonPRG with random seed.
- Date
2024-10-29
Defines
-
SEED_NUM_BYTES
-
namespace cdough
-
namespace random
-
class PseudoRandomGenerator : public cdough::random::RandomGenerator
- #include <seeded_prg.h>
PRG implementation using CommonPRG with seed.
Wraps CommonPRG with automatic seed generation or allows fixed seeding.
Public Functions
-
inline PseudoRandomGenerator()
Constructor with automatic random seed generation.
-
inline PseudoRandomGenerator(std::vector<unsigned char> _seed)
Constructor with fixed seed.
- Parameters:
_seed – The fixed seed to use.
-
inline PseudoRandomGenerator()
-
class PseudoRandomGenerator : public cdough::random::RandomGenerator
-
namespace random
-
namespace cdough
-
namespace random
-
class CommittedSeedsQueue
- #include <committed_seeds_queue.h>
Manages a queue of committed seeds.
This class implements the commitment protocol for fresh seed generation that prevents malicious parties from pre-computing attack strategies. Seeds are committed in batches to reduce communication overhead.
Public Functions
Constructor for CommittedSeedsQueue.
- Parameters:
_communicator – Reference to the communicator for network operations.
_localPRG – Pointer to local PRG for generating seeds and commitments.
_partyID – The ID of this party.
_numParties – Total number of parties in the protocol.
_toPartyIDs – Vector of party IDs for outgoing communication.
_fromPartyIDs – Vector of party IDs for incoming communication.
-
inline void repopulateQueue()
Repopulate the queue with new committed seeds.
Generates a batch of fresh seeds, commits to them, and exchanges commitments with all other parties in a single communication round.
Private Types
Private Members
-
std::vector<Commitment> commitments
-
Communicator &communicator
-
size_t currentSeedIndex = BATCH_SIZE
-
class CommittedSeedsQueue
-
namespace random
-
namespace cdough
-
namespace random
-
class ZeroRandomGenerator : public cdough::random::CommonPRG
- #include <zero_rg.h>
Random generator that outputs all zeros.
Used for testing and benchmarking where actual randomness is not required.
Public Functions
-
inline ZeroRandomGenerator(unsigned short _seed = 0, int rank = 0)
Constructor with seed parameter.
- Parameters:
_seed – The seed (unused).
rank – The rank of this party.
-
inline ZeroRandomGenerator(std::vector<unsigned char> _seed, int rank = 0)
Constructor with seed vector.
- Parameters:
_seed – The seed vector (unused).
rank – The rank of this party.
-
inline ZeroRandomGenerator(unsigned short _seed = 0, int rank = 0)
-
class ZeroRandomGenerator : public cdough::random::CommonPRG
-
namespace random
Correlation Generators
-
namespace cdough
-
namespace random
-
template<typename Corr>
class CorrelationGenerator : public cdough::random::RandomGenerator - #include <correlation_generator.h>
Base correlation generator class. This is non-functional and just used for organizational purposes. All correlation generators should inherit from this class, and implement (at least) the
getNext()andassertCorrelated()methods, with the property that.CG.assertCorrelated(CG.getNext())
always succeeds.
- Template Parameters:
Corr – the type of the correlation for a single party.
Public Functions
-
inline CorrelationGenerator(int _rank)
Constructor for the base correlation generator.
- Parameters:
_rank – The rank of this party.
-
virtual Corr getNext(const size_t n) = 0
Get a new, random correlation of length n.
- Parameters:
n –
- Returns:
Corr
Public Members
-
const int rank
The rank of this party in the MPC. Equivalent to party ID.
-
template<typename Corr>
-
namespace random
-
namespace cdough
-
namespace random
Functions
-
template<typename Impl>
DerivedOLEmodP(const Impl&) -> DerivedOLEmodP<typename Impl::value_type, Impl>
-
template<typename T, typename Impl>
class DerivedOLEmodP : public Impl, public cdough::random::OLEmodPrimeInterface<T> - #include <ole_generator.h>
Abstract class for OLE mod prime, derived from a larger mod 2^k OLE.
- Template Parameters:
T –
Public Types
-
using Prime = OLEmodPrimeInterface<T>
Public Functions
-
inline virtual void randomize(Vector<T> &x) override
Insecure default implementation: randomize, then reduce mod prime.
This version introduces some bias and should be fixed with rejection sampling.
-
inline virtual const int getRank() const override
-
inline virtual Communicator *getComm() const override
-
inline virtual Vector<wide_t> getNext(Vector<T> &mul_share, std::optional<Vector<T>> add_share) override
Get an OLE correlation mod prime using the underlying implementation, then reduce.
-
inline virtual ole_t getNext(size_t n) override
-
template<typename T, typename I = T>
class OLEGenerator : public cdough::random::CorrelationGenerator<std::tuple<Vector<T>, Vector<T>>> - #include <ole_generator.h>
Base class for Oblivious Linear Evaluation generators. By default, arithmetic correlations.
- Template Parameters:
T – The data type of the correlation
I – The intermediate data type (may be larger to prevent overflow)
Subclassed by cdough::random::GilboaCRT< T >, cdough::random::GilboaOLE< T >, cdough::random::OTGenerator< T >
Public Types
Public Functions
Constructor for the OLE generator.
- Parameters:
rank – The rank of this party.
_comm – Optional communicator for verification. If no communicator is provided, the base class will skip verification.
-
inline virtual void randomize(Vector<T> &x)
Default implementation: full randomization.
- Parameters:
x –
-
inline virtual ole_t getNext(const size_t n)
Generate random OLE correlations by calling the
randomizefunction.- Parameters:
n – The number of OLEs to generate.
- Returns:
A tuple of two vectors representing the OLE correlation.
Check if the vectors have an OLE correlation.
Subclasses can overload with pdutheir own correlation.
- Parameters:
A – additive share
B – additive share
C – multiplicative share
D – multiplicative share
- Returns:
true
- Returns:
false
Verify that the OLE correlation is correct. Aborts if not correlated.
- Parameters:
ole – The OLE correlation to verify.
-
template<typename T>
class OLEmodPrimeInterface - #include <ole_generator.h>
Minimal type-erased interface for mod-prime OLE generators.
Any concrete
DerivedOLEmodP<T, Impl>should implement this interface, allowing GilboaCRT to operate uniformly without knowingImpl.Subclassed by cdough::random::DerivedOLEmodP< T, Impl >
Public Types
-
template<typename Impl>
-
namespace random
-
namespace cdough
-
namespace random
-
template<typename T>
class OTGenerator : public cdough::random::OLEGenerator<T> - #include <ot_generator.h>
OT Generator subclasses OLE Generator just by providing a different correlation. Other abstract functionality is the same.
- Template Parameters:
T –
Subclassed by cdough::random::DummyOT< T >, cdough::random::SilentOT< T >, cdough::random::ZeroOLE< T >
Public Functions
Check if the vectors have an OLE correlation.
Subclasses can overload with pdutheir own correlation.
- Parameters:
A – additive share
B – additive share
C – multiplicative share
D – multiplicative share
- Returns:
true
- Returns:
false
-
template<typename T>
-
namespace random
-
namespace cdough
-
namespace random
Variables
-
bool dummy_showed_warning = false
-
template<typename T, typename I = T>
class DummyBase - #include <dummy_ole.h>
Insecure dummy OLE generator base class for testing. Uses a common-seed PRG to choose a random OLE correlation,
Y = A * X - B, where party 0 gets {A, B} and party 1 gets {X, Y}.- Template Parameters:
T – underlying datatype
Subclassed by cdough::random::DummyOT< T >
Public Functions
Constructor for the dummy OLE generator.
- Parameters:
rank – The rank of this party.
common – The CommonPRGManager for shared randomness.
communicator – The communicator for this party.
-
inline OLEGenerator<T, I>::ole_t getNext(const size_t n)
Generate dummy OLE correlations.
- Parameters:
n – The number of OLE pairs to generate.
- Returns:
A tuple of two vectors representing the OLE correlation.
Private Functions
Virtual method to get the resulting correlated value given three others.
- Parameters:
B – additive shared
C – multiplicative share
D – multiplicative share
- Returns:
Vector
-
template<typename T, typename I = T>
class DummyOLE : public cdough::random::OLEGenerator<T, T>, private cdough::random::DummyBase<T, T> - #include <dummy_ole.h>
Specialization for arbitrary OLE. Works for any type T over which *, - are defined.
- Template Parameters:
T –
I –
Public Functions
Virtual method to get the resulting correlated value given three others.
- Parameters:
B – additive shared
C – multiplicative share
D – multiplicative share
- Returns:
Vector
-
inline virtual OLEGenerator<T, I>::ole_t getNext(const size_t n)
Generate dummy OLE correlations.
- Parameters:
n – The number of OLE pairs to generate.
- Returns:
A tuple of two vectors representing the OLE correlation.
-
bool dummy_showed_warning = false
-
namespace random
Like Dummy OLE, but actually outputs all zero.
-
namespace cdough
-
namespace random
Variables
-
bool zero_showed_warning = false
-
template<typename T>
class ZeroOLE : public cdough::random::OTGenerator<T> - #include <zero_ole.h>
OLE generator that outputs all zeros.
Used for testing and benchmarking where actual security is not required.
ZeroOLE inherits from OTGenerator so that it can be used as both an OLE and OT Generator.
- Template Parameters:
T – The data type for the OLE elements
Public Functions
-
inline ZeroOLE(int rank, Communicator *communicator)
Constructor for the zero OLE generator.
- Parameters:
rank – The rank of this party.
communicator – The communicator for this party.
-
inline virtual void randomize(Vector<T> &x) override
Default implementation: full randomization.
- Parameters:
x –
-
inline virtual OTGenerator<T>::ole_t getNext(const size_t n) override
Generate zero OLE correlations.
- Parameters:
n – The number of OLE pairs to generate.
- Returns:
A tuple of two zero vectors.
-
bool zero_showed_warning = false
-
namespace random
Variables
-
const int SILENT_OT_BASE_PORT = GILBOA_OLE_BASE_PORT + (MAX_POSSIBLE_THREADS * 16)
-
namespace cdough
-
namespace random
Variables
-
const size_t OT_BLOCK_SIZE_BITS = 128
-
const size_t LOG_OT_BLOCK_SIZE = std::bit_width(OT_BLOCK_SIZE_BITS) - 1
-
template<typename T>
class SilentOT : public cdough::random::OTGenerator<T> - #include <silent_ot.h>
Typed Silent OT generator. Outputs correlations of the form A = B ^ C & D where one party gets (A, C) and the other gets (B, D)
- Template Parameters:
T – output correlation type
-
const size_t OT_BLOCK_SIZE_BITS = 128
-
namespace random
-
namespace cdough
-
namespace random
-
template<typename T>
class GilboaOLE : public cdough::random::OLEGenerator<T> - #include <gilboa_ole.h>
Gilboa Oblivious Linear Evaluation generator.
- Template Parameters:
T – The data type for the correlation elements
-
template<typename T>
-
namespace random
Gilboa mod a prime, for small primes (currently implemented for 8 bits.)
Variables
-
const int GILBOA_PRIME_BASE_PORT = GILBOA_OLE_BASE_PORT - MAX_POSSIBLE_THREADS
-
namespace cdough
-
namespace random
-
class GilboaModPrime : public cdough::random::OLEGenerator<uint8_t, uint16_t>, public cdough::random::OLEmodPrimeInterface<uint8_t>
- #include <gilboa_mod_p.h>
-
class GilboaModPrime : public cdough::random::OLEGenerator<uint8_t, uint16_t>, public cdough::random::OLEmodPrimeInterface<uint8_t>
-
namespace random
Variables
-
int STATISTICAL_SECURITY_PR = 40
Statistical security parameter \(\lambda\), with failure probability \(2^-\lambda\).
-
namespace cdough
-
namespace random
-
template<typename T>
class GilboaCRT : public cdough::random::OLEGenerator<T> - #include <gilboa_crt.h>
Gilboa OLE generator using CRT protocol of Doerner et al.
Paper: https://eprint.iacr.org/2025/1722
We implement the semihonest protocol (Protocol 4.7) below, and call down to the smooth-integer version (Protocol 4.5)
Underlying OLEs are currently fixed to 8 bits. This means that, while the protocol works for
T=int8_t, it is advisable to use the base quadratic protocol for concrete efficiency.- Template Parameters:
T –
Public Functions
Private Types
-
using OLEBase = OLEGenerator<T>
-
template<typename T>
-
namespace random
Warning
doxygenfile: Cannot find file “dpf.h
Warning
doxygenfile: Cannot find file “shprg.h
Variables
-
const int MAX_TRIPLES_RESERVE_BATCH = 1 << 24
-
namespace cdough
-
namespace random
Typedefs
-
template<typename T, cdough::Encoding E>
class BeaverTripleGenerator : public cdough::random::CorrelationGenerator<std::tuple<S<T>, S<T>, S<T>>> - #include <beaver_triple_generator.h>
Generates Beaver multiplication triples.
- Template Parameters:
T – The data type for the triple elements
E – The encoding type (BShared or AShared)
Public Functions
Constructor with OLE generator.
- Parameters:
v – The OLE generator to use.
Constructor that takes a PooledGenerator.
- Parameters:
p – shared_ptr to a PooledGenerator object.
_comm – Optional communicator object for correctness tests.
-
inline void reserve(size_t n)
A function to generate Beaver triples and store them for use later.
- Parameters:
n – The number of triples to generate.
-
inline virtual triple_t getNext(const size_t n)
Generate Beaver triples.
- Parameters:
n – The number of triples to generate.
- Returns:
A tuple of three vectors representing the Beaver triple.
Check the beaver triple is correct.
Since
CorrelationGenerators don’t have access to the runtime, we need to manually “open” the shared vector here.- Parameters:
bt –
Private Functions
-
inline auto generatorGetNext(size_t n)
A wrapper around getNext that works with either an OLEGenerator or a PooledGenerator.
- Parameters:
n – The number of triples to get.
Private Members
-
bool pooled
-
std::shared_ptr<OLEGenerator<T>> vg
-
std::shared_ptr<PooledGenerator<T, T>> pg
-
std::optional<Communicator*> comm
-
template<typename T, cdough::Encoding E>
-
namespace random
-
namespace cdough
-
namespace random
-
template<typename T, typename TensorT>
class AuthTripleGeneratorBase : public cdough::random::CorrelationGenerator<std::tuple<TensorT, TensorT, TensorT>> - #include <dummy_auth_triple_generator.h>
Base class for authenticated triple generators.
- Template Parameters:
T – The data type for the authenticated triple elements
TensorT – The tensor type for holding authenticated values
Subclassed by cdough::random::DummyAuthTripleGenerator< T, TensorT >, cdough::random::ZeroAuthTripleGenerator< T, TensorT >
Public Functions
-
inline AuthTripleGeneratorBase(PartyID rank)
Constructor for the base class.
- Parameters:
rank – The rank of this party.
-
virtual ~AuthTripleGeneratorBase() = default
-
virtual triple_t getNext(const size_t n) = 0
Generate authenticated triples.
- Parameters:
n – The number of triples to generate.
- Returns:
A tuple of three EVectors representing the authenticated triple.
Verify the authenticated triples are correct.
- Parameters:
bt – The authenticated triples to verify.
-
template<typename T, typename TensorT>
class DummyAuthTripleGenerator : public cdough::random::AuthTripleGeneratorBase<T, TensorT> - #include <dummy_auth_triple_generator.h>
Dummy generator for authenticated beaver triples.
Generates authenticated beaver triples using a dummy approach for testing purposes. Takes a party key share [key]_i and generates {([a]_i, [a*key]_i), ([b]_i, [b*key]_i), ([c]_i, [c*key]_i)} where c = a * b. Works for any number of parties.
- Template Parameters:
T – The data type for the authenticated triple elements
TensorT – The tensor type for holding authenticated values
Public Functions
Constructor for the dummy authenticated triple generator.
- Parameters:
partiesNum – The number of parties.
keyShare – The key share for this party.
rank – The rank of this party.
localPRG – The local PRG for generating randomness.
zeroSharingGenerator – The zero sharing generator.
comm – The communicator for this party.
-
inline virtual triple_t getNext(const size_t n) override
Generate dummy authenticated beaver triples.
- Parameters:
n – The number of triples to generate.
- Returns:
A tuple of three EVectors representing the authenticated triple (a, b, c).
Verify that the authenticated triples are correct.
- Parameters:
bt – The authenticated triples to verify.
-
template<typename T, typename TensorT>
class ZeroAuthTripleGenerator : public cdough::random::AuthTripleGeneratorBase<T, TensorT> - #include <dummy_auth_triple_generator.h>
Authenticated triple generator that outputs zeros.
Used for testing where authenticated zero triples are needed.
- Template Parameters:
T – The data type for the authenticated triple elements
TensorT – The tensor type for holding authenticated values
Public Functions
-
inline ZeroAuthTripleGenerator(PartyID rank)
Constructor for the zero authenticated triple generator.
- Parameters:
rank – The rank of this party.
-
inline virtual triple_t getNext(const size_t n) override
Generate zero authenticated triples.
- Parameters:
n – The number of zero triples to generate.
- Returns:
A tuple of three EVectors containing zero values and zero MACs.
Verify that all triple values are zero.
- Parameters:
bt – The authenticated triples to verify.
-
template<typename T, typename TensorT>
-
namespace random
-
namespace cdough
-
namespace random
-
template<typename T, typename TensorT>
class AuthRandomGeneratorBase : public cdough::random::CorrelationGenerator<TensorT> - #include <dummy_auth_random_generator.h>
Base class for authenticated random generators.
- Template Parameters:
T – The data type for the authenticated values
TensorT – The tensor type for holding authenticated values
Subclassed by cdough::random::DummyAuthRandomGenerator< T, TensorT >, cdough::random::ZeroAuthRandomGenerator< T, TensorT >
Public Functions
-
inline AuthRandomGeneratorBase(PartyID rank)
Constructor for the base class.
- Parameters:
rank – The rank of this party.
-
virtual ~AuthRandomGeneratorBase() = default
-
virtual tensor_t getNext(const size_t n) = 0
Generate authenticated random values.
- Parameters:
n – The number of values to generate.
- Returns:
A tensor containing values and their MACs.
-
virtual std::pair<tensor_t, Vector<T>> getNextMask(const size_t n, const PartyID inputParty) = 0
Generate authenticated random values along with their opened values. Ideally this returns authenticated random numbers of size
kbits.- Parameters:
n – The number of values to generate.
inputParty – The party that will receive the opened values.
- Returns:
A pair containing a tensor of authenticated values and a vector of opened values.
Verify the authenticated values are correct.
- Parameters:
bt – The authenticated values to verify.
-
template<typename T, typename TensorT>
class DummyAuthRandomGenerator : public cdough::random::AuthRandomGeneratorBase<T, TensorT> - #include <dummy_auth_random_generator.h>
Dummy generator for authenticated random numbers.
Generates authenticated random numbers insecurely for testing purposes. Takes a party key share [key]_i and generates ([x]_i, [x*key]_i). Works for any number of parties.
- Template Parameters:
T – The data type for the authenticated values
TensorT – The tensor type for holding authenticated values
Public Functions
Constructor for the dummy authenticated random generator.
- Parameters:
partiesNum – The number of parties.
keyShare – The key share for this party.
rank – The rank of this party.
localPRG – The local PRG for generating randomness.
zeroSharingGenerator – The zero sharing generator.
comm – The communicator for this party.
-
inline virtual tensor_t getNext(const size_t n) override
Generate dummy authenticated random numbers.
- Parameters:
n – The number of authenticated values to generate.
- Returns:
A tensor containing the values and their MACs.
-
inline virtual std::pair<tensor_t, Vector<T>> getNextMask(const size_t n, const PartyID inputParty) override
Generate dummy authenticated random numbers along with their opened values.
- Parameters:
n – The number of authenticated values to generate.
inputParty – The party that will receive the opened values.
- Returns:
A pair containing a tensor of authenticated values and a vector of opened values.
Verify that the authenticated values are correct.
- Parameters:
a – The authenticated values to verify.
-
template<typename T, typename TensorT>
class ZeroAuthRandomGenerator : public cdough::random::AuthRandomGeneratorBase<T, TensorT> - #include <dummy_auth_random_generator.h>
Authenticated random generator that outputs zeros.
Used for testing where authenticated zero values are needed.
- Template Parameters:
T – The data type for the authenticated values
TensorT – The tensor type for holding authenticated values
Public Functions
-
inline ZeroAuthRandomGenerator(PartyID rank)
Constructor for the zero authenticated random generator.
- Parameters:
rank – The rank of this party.
-
inline virtual tensor_t getNext(const size_t n) override
Generate zero authenticated values.
- Parameters:
n – The number of zero values to generate.
- Returns:
A tensor containing zero values and zero MACs.
-
inline virtual std::pair<tensor_t, Vector<T>> getNextMask(const size_t n, const PartyID inputParty) override
Generate zero authenticated values along with their opened values.
- Parameters:
n – The number of zero values to generate.
inputParty – The party that will receive the opened values.
- Returns:
A pair containing a tensor of zero authenticated values and a vector of zero opened
Verify that all values are zero.
- Parameters:
a – The authenticated values to verify.
-
namespace testing
Functions
Open additive shares across all parties.
- Parameters:
shares – The local shares to open.
pID – The party ID.
pNum – The number of parties.
communicator – The communicator for exchanging shares.
- Returns:
The opened values.
Open a single additive share across all parties.
- Parameters:
share – The local share to open.
pID – The party ID.
pNum – The number of parties.
communicator – The communicator for exchanging shares.
- Returns:
The opened value.
-
template<typename T, typename TensorT>
-
namespace random
-
namespace cdough
-
namespace random
-
class ZeroSharingGenerator
- #include <zero_sharing_generator.h>
Generates zero sharings for secure computation.
Creates sharings of zero for arithmetic and binary operations.
Public Functions
Creates a ZeroSharingGenerator object.
- Parameters:
_num_parties – The number of parties.
_commonPRGManager – The CommonPRGManager used to access CommonPRGs.
_rank – The rank of this party.
_comm – Optional communicator.
-
template<typename T>
inline void getNextArithmetic(T &num) Generate the next pseudorandom arithmetic zero sharing.
- Parameters:
num – The variable to fill with a random number.
-
template<typename T>
inline void getNextBinary(T &num) Generate the next pseudorandom binary zero sharing.
- Parameters:
num – The variable to fill with a random number.
-
template<typename T>
inline void getNextArithmetic(Vector<T> &nums) Generate many next pseudorandom arithmetic zero sharings.
- Parameters:
nums – The vector to fill with random numbers.
-
template<typename T>
inline void getNextBinary(Vector<T> &nums) Generate many next pseudorandom binary zero sharings.
- Parameters:
nums – The vector to fill with random numbers.
-
template<typename T>
inline void groupGetNextArithmetic(std::vector<Vector<T>> &nums, std::set<int> group) Generate many next pseudorandom arithmetic zero sharings.
Since this algorithm works over a group, it natively supports 2PC, and does not require correction (as above) by
arithmeticFlip.- Parameters:
nums – The vector of vectors to fill with random numbers.
group – The group of parties generating the zero sharing.
Private Functions
-
inline bool arithmeticFlip()
Check if arithmetic sharing needs sign flip for 2PC.
- Returns:
True if Party 0 in 2PC, false otherwise.
-
inline bool returnPlaintextZero()
Check if plaintext zero should be returned.
- Returns:
True if single party computation, false otherwise.
Private Members
-
int num_parties
-
std::shared_ptr<cdough::random::CommonPRGManager> commonPRGManager
-
int rank
-
std::optional<Communicator*> comm
-
class ZeroSharingGenerator
-
namespace random
Variables
-
const int OPRF_BASE_PORT = GILBOA_OLE_BASE_PORT + (MAX_POSSIBLE_THREADS * 32)
-
namespace cdough
-
namespace random
-
class OPRF
- #include <mock.h>
-
class OPRF
-
namespace random
-
namespace cdough
-
namespace random
Typedefs
-
template<typename T>
using TypedCorrelations_t = std::tuple<T> A tuple of shared pointers to correlations. Access via type-indexing.
- Template Parameters:
T –
-
using CorrRegistry_t = std::tuple<TypedCorrelations_t<int8_t>, TypedCorrelations_t<int16_t>, TypedCorrelations_t<int32_t>, TypedCorrelations_t<int64_t>, TypedCorrelations_t<__int128_t>>
A tuple of all types used by the system. Access the correlation registry by type first, then look up the specific correlation (from the resulting TypedCorrelations_t).
-
template<typename T>
-
namespace random
Utilities
-
namespace cdough
-
namespace random
Functions
Internal function to actually create a pooled object.
- Template Parameters:
Tuple – the inferred tuple type of the correlation’s output
Generator – the generator itself
Is – an index sequence corresponding to the number of tuple elements in the correlation
- Parameters:
generator – the actual generation object which should be pooled. Pass in a shared pointer.
- Returns:
A shared pointer to the new PooledGenerator object.
-
template<typename Generator, typename ...Args>
auto make_pooled(Args&&... args) Create a new PooledGenerator object.
- Parameters:
args – The arguments to pass to the Generator constructor.
- Returns:
A shared pointer to the new PooledGenerator object.
Create a pooled generator from an existing generator instance. This overload avoids reconstructing the generator and works with shared ownership.
-
template<typename ...Ts>
class PooledGenerator : public cdough::random::CorrelationGenerator<std::tuple<Vector<Ts>...>> - #include <pooled_generator.h>
A wrapper that pools correlations from another generator.
Manages a queue of pre-generated correlations for efficient batch processing.
- Template Parameters:
Ts – The types of the correlation elements
Public Functions
Constructor for the pooled generator.
- Parameters:
_generator – The underlying generator to pool.
-
inline void reserve(size_t count)
Generate and store correlations for later use.
- Parameters:
count – The number of correlations to generate and store.
-
inline std::size_t size() const
Get the size of the pool of randomness.
- Returns:
The number of correlations currently in the pool.
Check that the batch is correlated with the generator.
- Parameters:
batch – The batch to check.
Private Functions
-
template<std::size_t... I>
inline void addToQueueImpl(std::tuple<Vector<Ts>...> &batch, std::index_sequence<I...>) Private implementation method for adding a generated batch to the object’s queue.
- Parameters:
batch – The generated batch of randomness.
- Template Parameters:
I – Index sequence.
-
template<std::size_t... I>
inline void addToQueueImpl(std::tuple<std::vector<Ts>...> &batch, std::index_sequence<I...>) Private implementation method for adding a generated batch to the object’s queue.
- Parameters:
batch – The generated batch of randomness.
- Template Parameters:
I – Index sequence.
-
inline void addToQueue(std::tuple<Vector<Ts>...> &batch)
Private method to allow reserve() to add randomness to the pool.
- Parameters:
batch – The generated batch of randomness.
-
inline void addToQueue(std::tuple<std::vector<Ts>...> &batch)
Private method to allow reserve() to add randomness to the pool.
- Parameters:
batch – The generated batch of randomness.
-
template<std::size_t I, template<typename...> class VectorType = Vector>
inline VectorType<typename std::tuple_element<I, std::tuple<Ts...>>::type> extractElements(std::size_t count) Private helper function to get elements from a specific deque in the tuple of deques.
- Parameters:
count – The number of elements to extract.
- Returns:
A vector containing the extracted elements.
-
template<std::size_t... I, template<typename...> class VectorType = Vector>
inline std::tuple<VectorType<Ts>...> getNextImpl(std::size_t count, std::index_sequence<I...>) Private implementation function to get the next elements from the pool.
- Parameters:
count – The number of elements to get.
- Template Parameters:
I – Index sequence.
- Returns:
A tuple of vectors containing the extracted elements.
-
namespace random
Defines
-
__typeid(T)
-
namespace cdough
-
namespace random
-
class RandomnessManager
- #include <manager.h>
Manages various sources of randomness and correlations.
Coordinates local PRGs, common PRGs, zero sharing generators, and correlation generators.
Public Functions
Constructor for the randomness manager.
- Parameters:
_localPRG – The local PRG for this party.
_commonPRGManager – The manager for common PRGs.
_zeroSharingGenerator – The zero sharing generator.
_corrGen – Registry of correlation generators.
Overload that accepts a sharded permutation generator.
-
template<typename T>
inline void generate_local(Vector<T> &nums) Fills a vector with local randomness.
- Template Parameters:
T – The data type for the random values.
- Parameters:
nums – The vector to fill.
-
template<typename T>
inline void generate_common(Vector<T> &nums, std::set<int> group) Fills a vector with randomness common among a group.
- Template Parameters:
T – The data type for the random values.
- Parameters:
nums – The vector to fill.
group – The group that shares the CommonPRG seed.
-
template<typename T>
inline void reserve_mul_triples(size_t n) Calls the arithmetic Beaver triple generator’s reserve() function.
- Template Parameters:
T – The data type for the triple elements.
- Parameters:
n – The number of triples to generate.
-
template<typename T>
inline void reserve_and_triples(size_t n) Calls the binary Beaver triple generator’s reserve() function.
- Template Parameters:
T – The data type for the triple elements.
- Parameters:
n – The number of triples to generate.
-
template<typename T, typename Corr>
inline auto &getCorrelation() Get a correlation generator for the specified type and correlation.
- Template Parameters:
T – The data type for the correlation elements.
C – The correlation type.
- Returns:
A shared pointer to the correlation generator.
Public Members
-
std::shared_ptr<CommonPRGManager> commonPRGManager
-
std::shared_ptr<ZeroSharingGenerator> zeroSharingGenerator
-
CorrRegistry_t corr_registry
Private Members
-
std::shared_ptr<ShardedPermutationGenerator> sharded_perm_generator
-
class RandomnessManager
-
namespace random