Random
The random/ directory provides all randomness and correlation generators required by ORQ’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 orq
-
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.
-
inline void reserve(size_t size_permutation, size_t num_permutations, 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.
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.
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.
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 orq::random::DMShardedPermutation< T >, orq::random::HMShardedPermutation, orq::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 orq::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 orq::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, orq::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, orq::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 orq::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 orq::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 “orq::random::DMDummyGenerator” in doxygen xml output for project “ORQ” from directory: xml
Warning
doxygenclass: Cannot find class “orq::random::DMPermutationCorrelationGenerator” in doxygen xml output for project “ORQ” from directory: xml
Randomness Generators
-
namespace orq
-
namespace random
-
class RandomGenerator
- #include <random_generator.h>
Base class for random number generators.
Provides a common interface for generating pseudorandom numbers.
Subclassed by orq::random::CorrelationGenerator< std::tuple< S< T >, S< T >, S< T > > >, orq::random::CorrelationGenerator< std::tuple< Vector< T >, Vector< T > > >, orq::random::CorrelationGenerator< std::tuple< Vector< uint8_t >, Vector< uint16_t > > >, orq::random::CorrelationGenerator< std::tuple< Vector< Ts >… > >, orq::random::CorrelationGenerator< Corr >, orq::random::PseudoRandomGenerator, orq::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 orq
-
namespace random
-
class AESPRGAlgorithm : public orq::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::span<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::span<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::span<unsigned char> _seed)
-
class DeterministicPRGAlgorithm : public orq::random::PRGAlgorithm
- #include <prg_algorithm.h>
Base class for deterministic PRG algorithms.
Extends PRGAlgorithm with seed management and nonce functionality.
Subclassed by orq::random::AESPRGAlgorithm, orq::random::XChaCha20PRGAlgorithm
Public Functions
-
virtual void setSeed(std::span<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::span<unsigned char> seed) = 0
-
class DevUrandomPRGAlgorithm : public orq::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 orq::random::DeterministicPRGAlgorithm, orq::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(std::span<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(std::span<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 orq::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::span<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::span<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::span<unsigned char> _seed)
-
class AESPRGAlgorithm : public orq::random::DeterministicPRGAlgorithm
-
namespace random
-
namespace orq
-
namespace random
-
class CommonPRG
- #include <common_prg.h>
Subclassed by orq::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.
-
template<typename T>
inline void getNext(std::span<T> nums) Generate many next elements from the PRF.
- Parameters:
nums – The span 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 getNext(NTL::GF2E &num)
-
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-relative requests and explicit groups to their corresponding CommonPRG instances.
Public Functions
-
inline CommonPRGManager(int _num_parties, int _party_id = 0, RelativeRankMode _relative_rank_mode = RelativeRankMode::INCLUDED)
Initializes the CommonPRGManager object with the current party index.
- Parameters:
_num_parties – The number of parties.
_party_id – The absolute ID of the current party.
_relative_rank_mode – How relative ranks map to groups.
Add a CommonPRG object by relative rank behavior.
INCLUDED: group is {party_id, target_party}. EXCLUDED: group is all parties except target_party.
Add a CommonPRG object by explicit group.
-
inline std::shared_ptr<CommonPRG> get(int relative_rank)
Get a CommonPRG object by relative rank behavior.
INCLUDED: group is {party_id, target_party}. EXCLUDED: group is all parties except target_party.
-
inline std::shared_ptr<CommonPRG> get(std::set<int> group)
Get the CommonPRG object shared with an explicit group.
-
inline std::shared_ptr<CommonPRG> get()
Get the everyone group.
- Returns:
std::shared_ptr<CommonPRG>
-
inline void printGroupKeys() const
Print all group keys currently present in the manager map (for debugging)
Public Static Attributes
-
static struct orq::random::CommonPRGManager::AllSemaphore ALL
Private Functions
-
inline int getAbsoluteRank(int relative_rank) const
-
inline std::set<int> buildGroupFromRelativeRank(int relative_rank) const
Private Members
-
const int num_parties
-
const int party_id
-
RelativeRankMode relative_rank_mode
-
std::set<int> everyone
-
struct AllSemaphore
- #include <common_prg.h>
-
inline CommonPRGManager(int _num_parties, int _party_id = 0, RelativeRankMode _relative_rank_mode = RelativeRankMode::INCLUDED)
-
class CommonPRG
-
namespace random
Implements PRG via CommonPRG with random seed.
- Date
2024-10-29
Defines
-
SEED_NUM_BYTES
-
namespace orq
-
namespace random
-
class PseudoRandomGenerator : public orq::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 orq::random::RandomGenerator
-
namespace random
-
namespace orq
-
namespace random
-
class ZeroRandomGenerator : public orq::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 orq::random::CommonPRG
-
namespace random
Correlation Generators
-
namespace orq
-
namespace random
-
template<typename Corr>
class CorrelationGenerator : public orq::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.
Subclassed by orq::random::AuthRandomGeneratorBase< T >, orq::random::AuthTripleGeneratorBase< T >
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 orq
-
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 orq::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 orq::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 orq::random::GilboaCRT< T >, orq::random::GilboaOLE< T >, orq::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 orq::random::DerivedOLEmodP< T, Impl >
Public Types
-
template<typename Impl>
-
namespace random
-
namespace orq
-
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 orq::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:
-
template<typename T, typename I = T>
class DummyOLE : public orq::random::OLEGenerator<T, T>, private orq::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:
-
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 orq
-
namespace random
Variables
-
bool zero_showed_warning = false
-
template<typename T>
class ZeroOLE : public orq::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 –
-
bool zero_showed_warning = false
-
namespace random
Variables
-
const int SILENT_OT_BASE_PORT = GILBOA_OLE_BASE_PORT + (MAX_POSSIBLE_THREADS * 16)
-
namespace orq
-
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
-
const size_t OT_BLOCK_SIZE_BITS = 128
-
namespace random
-
namespace orq
-
namespace random
-
template<typename T>
class GilboaOLE : public orq::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
Variables
-
const int MAX_TRIPLES_RESERVE_BATCH = 1 << 24
-
namespace orq
-
namespace random
Typedefs
-
template<typename T, orq::Encoding E>
class BeaverTripleGenerator : public orq::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, orq::Encoding E>
-
namespace random
-
namespace orq
-
namespace random
-
template<typename T>
class AuthTripleGeneratorBase : public orq::random::CorrelationGenerator<Corr> - #include <dummy_auth_triple_generator.h>
Base class for authenticated triple generators.
- Template Parameters:
T – The data type for the authenticated triple elements
Subclassed by orq::random::DummyAuthTripleGenerator< T >, orq::random::ZeroAuthTripleGenerator< T >
Public Functions
-
inline AuthTripleGeneratorBase(const 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>
struct CorrelationEnumType<T, Correlation::AuthMulTriple> - #include <dummy_auth_triple_generator.h>
Public Types
-
using type = AuthTripleGeneratorBase<T>
-
using type = AuthTripleGeneratorBase<T>
-
template<typename T>
class DummyAuthTripleGenerator : public orq::random::AuthTripleGeneratorBase<T> - #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
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.
Private Types
-
template<typename T>
class ZeroAuthTripleGenerator : public orq::random::AuthTripleGeneratorBase<T> - #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
Public Functions
-
inline ZeroAuthTripleGenerator(const 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>
-
namespace random
-
namespace orq
-
namespace random
-
template<typename T>
class AuthRandomGeneratorBase : public orq::random::CorrelationGenerator<Corr> - #include <dummy_auth_random_generator.h>
Base class for authenticated random generators.
- Template Parameters:
T – The data type for the authenticated values
Subclassed by orq::random::DummyAuthRandomGenerator< T >, orq::random::ZeroAuthRandomGenerator< T >
Public Functions
-
inline AuthRandomGeneratorBase(const 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.
Verify the authenticated values are correct.
- Parameters:
bt – The authenticated values to verify.
-
template<typename T>
struct CorrelationEnumType<T, Correlation::AuthRandom> - #include <dummy_auth_random_generator.h>
Public Types
-
using type = DummyAuthRandomGenerator<T>
-
using type = DummyAuthRandomGenerator<T>
-
template<typename T>
class DummyAuthRandomGenerator : public orq::random::AuthRandomGeneratorBase<T> - #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
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.
Verify that the authenticated values are correct.
- Parameters:
a – The authenticated values to verify.
-
template<typename T>
class ZeroAuthRandomGenerator : public orq::random::AuthRandomGeneratorBase<T> - #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
Public Functions
-
inline ZeroAuthRandomGenerator(const 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.
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>
-
namespace random
-
namespace orq
-
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<orq::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 orq
-
namespace random
-
class OPRF
- #include <mock.h>
-
class OPRF
-
namespace random
Utilities
-
namespace orq
-
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 orq::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 orq
-
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
-
std::unique_ptr<CommittedSeedsQueue<>> csq
-
CorrRegistry_t corr_registry
Private Members
-
std::shared_ptr<ShardedPermutationGenerator> sharded_perm_generator
-
class RandomnessManager
-
namespace random