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 OTs

  • prg/ - local and shared PRG interfaces

Permutations

namespace cdough
namespace random

Functions

template<typename T>
void setup_dm_pair(std::shared_ptr<ShardedPermutation> &perm1, std::shared_ptr<ShardedPermutation> &perm2)

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.

template<typename T, typename Engine>
inline std::shared_ptr<ShardedPermutation> getNext(size_t size_permutation, Engine &engine, std::optional<cdough::Encoding> dm_encoding = cdough::Encoding::BShared)

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.

template<typename T1, typename T2, typename Engine>
inline std::pair<std::shared_ptr<ShardedPermutation>, std::shared_ptr<ShardedPermutation>> getNextPair(size_t size_permutation, Engine &engine, std::optional<cdough::Encoding> dm_encoding_1 = cdough::Encoding::BShared, std::optional<cdough::Encoding> dm_encoding_2 = cdough::Encoding::BShared)

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
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
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.

inline HMShardedPermutation(std::shared_ptr<std::map<Group, LocalPermutation>> _perm)

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.

Private Members

size_t m_size
std::shared_ptr<std::map<Group, LocalPermutation>> perm
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 void setCommonPRG(std::shared_ptr<CommonPRG> _common_prg)

Set the CommonPRG.

Parameters:

_common_prg – The CommonPRG to set.

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.

Private Types

using dm_perm_t = std::tuple<Vector<int>, Vector<T>, Vector<T>, Vector<T>>

Private Members

std::shared_ptr<std::tuple<Vector<int>, Vector<T>, Vector<T>, Vector<T>>> perm
cdough::Encoding encoding
bool has_common_prg
std::shared_ptr<CommonPRG> common_prg
template<typename T>
class DMShardedPermutationGenerator : public cdough::random::ShardedPermutationGenerator

Dishonest Majority Sharded Permutation Generator

Currently only supports 2PC

Public Types

using dm_perm_t = std::tuple<Vector<int>, Vector<T>, Vector<T>, Vector<T>>

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.

inline virtual void generateBatch(std::vector<std::shared_ptr<ShardedPermutation>> &ret)

Generate a batch of DMShardedPermutations, invoked by the runtime.

Parameters:

ret – A vector of DMShardedPermutations to fill.

inline void assertCorrelated(std::shared_ptr<DMShardedPermutation<T>> &perm)

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

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
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

inline ZeroPermutationGenerator(int _rank, std::shared_ptr<CommonPRGManager> _commonPRGManager, std::vector<std::set<int>> _groups)

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.

inline virtual void generateBatch(std::vector<std::shared_ptr<ShardedPermutation>> &ret)

Generate a batch of zero permutations (no-op).

Parameters:

ret – A vector of permutations.

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.

template<typename T>
inline void getNext(T &num)

Generate the next element of some Pseudo Random Numbers Queue.

Parameters:

num – The variable to fill with a random number.

template<typename T>
inline void getNext(Vector<T> &nums)

Generate many next elements of some Pseudo Random Numbers Queue.

Parameters:

nums – The vector to fill with random numbers.

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).

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.

Private Members

unsigned char seed[crypto_aead_aes256gcm_KEYBYTES] = {}
unsigned long nonce
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.

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)
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.

template<typename T>
inline void getNext(T &num)

Generates random bytes to fill one T.

Template Parameters:

T – The data type to fill.

Parameters:

num – The reference to fill with random bytes.

template<typename T>
inline void getNext(Vector<T> &nums)

Fills nums with random data.

This function creates a buffer to hold the random values before copying them to the Vector.

Template Parameters:

T – The data type for the vector elements.

Parameters:

nums – The vector to fill with random data.

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.

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)

Private Members

unsigned char seed[crypto_stream_xchacha20_KEYBYTES] = {}
unsigned long nonce
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
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.

inline void add(std::shared_ptr<CommonPRG> &common_prg, int relative_rank)

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.

inline void add(std::shared_ptr<CommonPRG> &common_prg, std::set<int> group)

Add a CommonPRG object to the manager by group. The manager handles the group mapping.

Parameters:
  • common_prg – A pointer to the CommonPRG to be added to the manager.

  • group – The group that shares the CommonPRG.

inline std::shared_ptr<CommonPRG> get(int relative_rank)

Get the CommonPRG object shared with the party given by relative rank.

Parameters:

relative_rank – The rank of the other party relative to the current party.

Returns:

A pointer to the CommonPRG shared with the other party.

inline std::shared_ptr<CommonPRG> get(std::set<int> group)

Get the CommonPRG object shared with the group.

Parameters:

group – The group that shares the CommonPRG.

Returns:

A pointer to the CommonPRG shared with the other party.

Private Members

int num_parties
std::vector<std::shared_ptr<CommonPRG>> common_prgs
std::map<std::set<int>, std::shared_ptr<CommonPRG>> common_prg_group_map

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.

template<typename T>
inline void getNext(T &nums)

Generate a random value.

Template Parameters:

T – The data type to generate.

Parameters:

nums – The variable to fill with a random value.

template<typename T>
inline void getNext(Vector<T> &nums)

Generate random values for a vector.

Template Parameters:

T – The data type for vector elements.

Parameters:

nums – The vector to fill with random values.

Private Members

std::unique_ptr<CommonPRG> cprg
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

inline CommittedSeedsQueue(Communicator &_communicator, std::shared_ptr<random::CommonPRG> _localPRG, PartyID _partyID, PartyID _numParties, const std::vector<PartyID> &_toPartyIDs, const std::vector<PartyID> &_fromPartyIDs)

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.

inline std::shared_ptr<CommonPRG> getNextPRG()

Private Types

template<typename T>
using Vector = cdough::Vector<T>
using Seed = Vector<unsigned char>
using Commitment = Vector<unsigned char>
using Key = Vector<unsigned char>
using PartyID = cdough::PartyID

Private Members

std::vector<Commitment> commitments
Seed localSeeds
Key localKeys
Communicator &communicator
std::shared_ptr<random::CommonPRG> localPRG
PartyID partyID
PartyID numParties
std::vector<PartyID> toPartyIDs
std::vector<PartyID> fromPartyIDs
size_t currentSeedIndex = BATCH_SIZE

Private Static Attributes

static int BATCH_SIZE = 1024
static int SEED_BYTES = crypto_aead_aes256gcm_KEYBYTES
static int COMMITMENT_BYTES = crypto_generichash_BYTES
static int HASH_KEY_BYTES = crypto_generichash_KEYBYTES
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.

template<typename T>
inline void getNext(T &num)

Generate zero value (no-op).

Parameters:

num – The variable to fill (left unchanged).

template<template<typename...> class V, typename T>
inline void getNext(V<T> &nums)

Generate zero values (no-op).

Parameters:

nums – The vector to fill (left unchanged).

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() and assertCorrelated() 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

inline void assertCorrelated(const Corr&) const

Public Members

const int rank

The rank of this party in the MPC. Equivalent to party ID.

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 wide_t = typename DoubleWidth<T>::type
using Base = Impl
using Prime = OLEmodPrimeInterface<T>

Public Functions

inline DerivedOLEmodP(const Base &b)
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 void assertCorrelated(const std::tuple<Vector<T>, Vector<wide_t>> &ole) 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
inline bool isCorrelated(Vector<T> &A, Vector<T> &B, Vector<T> &C, Vector<T> &D) const 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

using value_type = T
using ole_t = std::tuple<Vector<T>, Vector<I>>

OLE correlation type. By convention, the first share is multiplicative; the second is the additive share.

Public Functions

inline OLEGenerator(int rank, std::shared_ptr<CommonPRGManager> manager, std::optional<Communicator*> _comm)

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 randomize function.

Parameters:

n – The number of OLEs to generate.

Returns:

A tuple of two vectors representing the OLE correlation.

virtual Vector<I> getNext(Vector<T> &m, std::optional<Vector<T>> a) = 0
inline virtual bool isCorrelated(Vector<T> &A, Vector<T> &B, Vector<T> &C, Vector<T> &D) const

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

inline void assertCorrelated(const ole_t &ole) const

Verify that the OLE correlation is correct. Aborts if not correlated.

Parameters:

ole – The OLE correlation to verify.

Public Members

std::optional<Communicator*> comm
std::shared_ptr<CommonPRG> localPRG
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 knowing Impl.

Subclassed by cdough::random::DerivedOLEmodP< T, Impl >

Public Types

using wide_t = typename DoubleWidth<T>::type
using ole_t = std::tuple<Vector<T>, Vector<wide_t>>

Public Functions

virtual ~OLEmodPrimeInterface() = default
inline void setPrime(T newPrime)
inline T getPrime() const
inline int primeBits() const
inline virtual Vector<T> reduce(Vector<wide_t> x) const

Reduce x mod p.

Parameters:

x

Returns:

Vector<T>

virtual void randomize(Vector<T> &x) = 0
virtual Vector<wide_t> getNext(Vector<T> &mul_share, std::optional<Vector<T>> add_share) = 0
virtual std::tuple<Vector<T>, Vector<wide_t>> getNext(const size_t n) = 0
virtual void assertCorrelated(const std::tuple<Vector<T>, Vector<wide_t>>&) const = 0
virtual const int getRank() const = 0
virtual Communicator *getComm() const = 0

Private Members

T prime = 2
T maxT = std::numeric_limits<T>::max()
wide_t maxW = std::numeric_limits<wide_t>::max()
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

inline virtual bool isCorrelated(Vector<T> &A, Vector<T> &B, Vector<T> &C, Vector<T> &D) const override

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

inline virtual Vector<T> getNext(Vector<T> &m, std::optional<Vector<T>> a) override
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

inline DummyBase(int rank, std::shared_ptr<CommonPRGManager> common, Communicator *communicator)

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.

inline Vector<I> getNext(Vector<T> &mul_share, std::optional<Vector<T>> add_share)

Generate chosen-message OLE correlations. P0 sends its shares to P1, who computes the correlation.

Parameters:
  • mul_share

  • add_share

Returns:

Vector

Private Functions

virtual Vector<I> getCorrelated(Vector<T> &B, Vector<T> &C, Vector<T> &D) = 0

Virtual method to get the resulting correlated value given three others.

Parameters:
  • B – additive shared

  • C – multiplicative share

  • D – multiplicative share

Returns:

Vector

Private Members

std::shared_ptr<CommonPRG> all_prg
Communicator *_comm
int _rank
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

inline DummyOLE(int rank, std::shared_ptr<CommonPRGManager> common, Communicator *communicator)
inline virtual Vector<I> getNext(Vector<T> &m, std::optional<Vector<T>> a) override
inline virtual Vector<I> getCorrelated(Vector<T> &add, Vector<T> &mul0, Vector<T> &mul1) override

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.

Private Types

using Base = DummyBase<T, I>
template<typename T>
class DummyOT : public cdough::random::OTGenerator<T>, private cdough::random::DummyBase<T>
#include <dummy_ole.h>

Public Functions

inline DummyOT(int rank, std::shared_ptr<CommonPRGManager> common, Communicator *communicator)
inline virtual Vector<T> getNext(Vector<T> &m, std::optional<Vector<T>> a) override
inline virtual Vector<T> getCorrelated(Vector<T> &xor_, Vector<T> &and0, Vector<T> &and1) override

Specialization for Dummy OT: compute over binary field.

Parameters:
  • xor_

  • and0

  • and1

Returns:

Vector<T>

Private Types

using Base = DummyBase<T>

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.

inline virtual Vector<T> getNext(Vector<T> &A, std::optional<Vector<T>> B) override

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

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

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>

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

inline GilboaCRT(internal::base_mod_ptr base, std::shared_ptr<CommonPRGManager> m)
inline virtual Vector<T> getNext(Vector<T> &a, std::optional<Vector<T>> b) override

Generate an OLE correlation using the CRT protocol.

Parameters:
  • a – multiplicative share

  • b – sender’s additive share

Returns:

Vector<T>

Private Types

using OLEBase = OLEGenerator<T>

Private Members

NTL::ZZ Q = NTL::ZZ(1) << L
NTL::ZZ smoothMod
NTL::ZZ samplingBound
int maxPrimeIdx
std::unique_ptr<internal::GilboaCRT_smooth> Gs

Private Static Attributes

static int L = std::numeric_limits<std::make_unsigned_t<T>>::digits
namespace internal

Typedefs

using S = uint8_t
using base_mod_ptr = std::shared_ptr<OLEmodPrimeInterface<S>>
class CRTbasis
#include <gilboa_crt.h>

Helper class to run multiple CRT executions with the same setup.

Public Functions

inline CRTbasis()
inline CRTbasis(int upTo)
inline ZZ apply(const vec_ZZ &residues) const

Private Members

ZZ prodPrimes = ZZ(1)
vec_ZZ coeffs
class GilboaCRT_smooth
#include <gilboa_crt.h>

Perfectly secure OLE over smooth integers.

Protocol 4.5 of Doerner et al.

Public Functions

inline GilboaCRT_smooth(int numPrimes, base_mod_ptr b)
inline vec_ZZ getNext(vec_ZZ a, std::optional<NTL::vec_ZZ> b)

Private Members

int numPrimes
base_mod_ptr base
CRTbasis basis

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>
using S = EVector<T, 1>
template<typename T>
using BeaverMulGenerator = BeaverTripleGenerator<T, cdough::Encoding::AShared>
template<typename T>
using BeaverAndGenerator = BeaverTripleGenerator<T, cdough::Encoding::BShared>
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

inline BeaverTripleGenerator(std::shared_ptr<OLEGenerator<T>> v)

Constructor with OLE generator.

Parameters:

v – The OLE generator to use.

inline BeaverTripleGenerator(std::shared_ptr<PooledGenerator<T, T>> p, std::optional<Communicator*> _comm = std::nullopt)

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.

inline void assertCorrelated(const triple_t &bt)

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 Types

using triple_t = std::tuple<S<T>, S<T>, S<T>>
using vec_t = Vector<T>

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
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.

virtual void assertCorrelated(const triple_t &bt) = 0

Verify the authenticated triples are correct.

Parameters:

bt – The authenticated triples to verify.

Private Types

using S = TensorT
using triple_t = std::tuple<S, S, S>
using vec_t = Vector<T>
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

inline DummyAuthTripleGenerator(int partiesNum, const T &keyShare, PartyID rank, std::shared_ptr<CommonPRG> localPRG, std::shared_ptr<ZeroSharingGenerator> zeroSharingGenerator, Communicator *comm)

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).

inline virtual void assertCorrelated(const triple_t &bt) override

Verify that the authenticated triples are correct.

Parameters:

bt – The authenticated triples to verify.

Private Types

using S = TensorT
using triple_t = std::tuple<S, S, S>
using vec_t = Vector<T>

Private Members

const int partiesNum_
const T keyShare_
T key_
std::shared_ptr<cdough::random::ZeroSharingGenerator> zeroSharingGenerator_
std::shared_ptr<CommonPRG> localPRG_
Communicator *comm_
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.

inline virtual void assertCorrelated(const triple_t &bt) override

Verify that all triple values are zero.

Parameters:

bt – The authenticated triples to verify.

Private Types

using S = TensorT
using triple_t = std::tuple<S, S, S>
using vec_t = Vector<T>
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 k bits.

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.

virtual void assertCorrelated(const tensor_t &bt) = 0

Verify the authenticated values are correct.

Parameters:

bt – The authenticated values to verify.

Private Types

using tensor_t = TensorT
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

inline DummyAuthRandomGenerator(int partiesNum, const T &keyShare, PartyID rank, std::shared_ptr<CommonPRG> localPRG, std::shared_ptr<ZeroSharingGenerator> zeroSharingGenerator, Communicator *comm)

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.

inline virtual void assertCorrelated(const tensor_t &a) override

Verify that the authenticated values are correct.

Parameters:

a – The authenticated values to verify.

Private Types

using tensor_t = TensorT

Private Members

const int partiesNum_
const T keyShare_
T key_
std::shared_ptr<cdough::random::ZeroSharingGenerator> zeroSharingGenerator_
std::shared_ptr<CommonPRG> localPRG_
Communicator *comm_
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

inline virtual void assertCorrelated(const tensor_t &a) override

Verify that all values are zero.

Parameters:

a – The authenticated values to verify.

Private Types

using tensor_t = TensorT
namespace testing

Functions

template<typename T>
cdough::Vector<T> OpenAdditiveShares(const cdough::Vector<T> &shares, const cdough::PartyID pID, int pNum, Communicator *communicator)

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.

template<typename T>
T OpenAdditiveShare(const T &share, const cdough::PartyID pID, int pNum, Communicator *communicator)

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.

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

inline ZeroSharingGenerator(const int _num_parties, std::shared_ptr<cdough::random::CommonPRGManager> _commonPRGManager, int _rank = 0, std::optional<Communicator*> _comm = std::nullopt)

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.

template<typename T>
inline void groupGetNextBinary(std::vector<Vector<T>> &nums, std::set<int> group)

Generate many next pseudorandom binary zero sharings.

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

Variables

const int OPRF_BASE_PORT = GILBOA_OLE_BASE_PORT + (MAX_POSSIBLE_THREADS * 32)
namespace cdough
namespace random
class OPRF
#include <mock.h>
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).

Utilities

namespace cdough
namespace random

Functions

template<typename Tuple, std::size_t... Is>
auto _make_pooled_impl(std::shared_ptr<CorrelationGenerator<Tuple>> generator, std::index_sequence<Is...>)

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.

template<typename Generator>
auto make_pooled(std::shared_ptr<Generator> generator)

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

inline PooledGenerator(std::shared_ptr<CorrelationGenerator<ret_t>> _generator)

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.

inline void assertCorrelated(const ret_t &batch)

Check that the batch is correlated with the generator.

Parameters:

batch – The batch to check.

inline virtual ret_t getNext(const size_t count)

Get elements from the pool.

Parameters:

count – The number of elements to get.

Returns:

A tuple of vectors containing the requested correlations.

Private Types

using ret_t = std::tuple<Vector<Ts>...>

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.

template<std::size_t... I>
inline std::size_t sizeImpl(std::index_sequence<I...>) const

Private implementation function to get the size of the pool.

Template Parameters:

I – Index sequence.

Returns:

The number of elements in the pool.

Private Members

std::shared_ptr<CorrelationGenerator<ret_t>> generator
std::function<ret_t(size_t)> getNextFunc
std::tuple<std::deque<Ts>...> queueTuple

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

inline RandomnessManager(std::shared_ptr<CommonPRGManager> _commonPRGManager, std::shared_ptr<ZeroSharingGenerator> _zeroSharingGenerator, CorrRegistry_t &&_corrGen)

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.

inline RandomnessManager(std::shared_ptr<CommonPRGManager> _commonPRGManager, std::shared_ptr<ZeroSharingGenerator> _zeroSharingGenerator, CorrRegistry_t &&_corrGen, std::shared_ptr<ShardedPermutationGenerator> _sharded)

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<CommonPRG> localPRG
std::shared_ptr<CommonPRGManager> commonPRGManager
std::shared_ptr<ZeroSharingGenerator> zeroSharingGenerator
CorrRegistry_t corr_registry

Private Members

std::shared_ptr<ShardedPermutationGenerator> sharded_perm_generator