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(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.
-
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, orq::random::PseudoRandomGenerator
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::vector<unsigned char> &_seed)
Creates an AESPRGAlgorithm object.
- Parameters:
_seed – The seed shared between the parties.
-
inline virtual void fillBytes(std::span<uint8_t> dest) override
Fill destination with AES-generated random bytes.
- Parameters:
dest – The span to fill with random bytes.
-
inline virtual void setSeed(std::vector<unsigned char> &_seed) override
Set the AES key from seed bytes.
- Parameters:
_seed – The seed bytes to use as AES key.
-
inline virtual void incrementNonce() override
Increment the nonce counter.
Public Static Functions
-
static inline void aesKeyGen(std::span<unsigned char> key)
Generate a random AES key.
- Parameters:
key – The span to fill with the generated key.
Public Static Attributes
-
static const size_t MAX_AES_QUERY_BYTES = (1 << 20)
Protected Functions
-
inline virtual size_t getPreferredBufferSize() override
Returns the size of the buffer allocated to temporarily store random numbers before they are copied to Vectors.
- Returns:
The preferred buffer size in bytes.
Private Functions
-
inline void aesGenerateValues(std::span<uint8_t> dest)
Generate random bytes using AES-256-GCM.
- Parameters:
dest – The span to fill with random bytes.
-
inline AESPRGAlgorithm(std::vector<unsigned char> &_seed)
-
class DeterministicPRGAlgorithm : public 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::vector<unsigned char> &seed) = 0
Sets the seed for generation of random numbers.
- Parameters:
seed – The seed bytes to use.
-
virtual ~DeterministicPRGAlgorithm() = default
Virtual destructor.
-
virtual void incrementNonce() = 0
Increment the algorithm’s nonce, if applicable.
If this algorithm has no nonce, this is a nop. Used to keep PRGs in sync when shared by multiple parties.
-
virtual void setSeed(std::vector<unsigned char> &seed) = 0
-
class DevUrandomPRGAlgorithm : public 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.
Protected Functions
-
inline virtual size_t getPreferredBufferSize()
Returns the size of the buffer allocated to temporarily store random numbers before they are copied to Vectors.
- Returns:
The preferred buffer size in bytes.
Protected Static Attributes
-
static thread_local std::vector<uint8_t> thread_buffer
Private Functions
-
template<typename T>
inline void getNextBuffered(Vector<T> &nums, std::span<uint8_t> buffer) Fills nums with random data.
- Template Parameters:
T – The data type for the vector elements.
- Parameters:
nums – The Vector to fill.
buffer – A buffer to hold the randomly generated values before they are copied into the Vector. It must be large enough to contain at least one element (
sizeof(T)
). This buffer is necessary because the Vector may be a non-contiguous view of a block of memory, and therefore that memory can’t be filled directly with the random data.
-
virtual void fillBytes(std::span<uint8_t> dest) = 0
-
class XChaCha20PRGAlgorithm : public 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::vector<unsigned char> &_seed)
Creates an XChaCha20PRGAlgorithm object.
- Parameters:
_seed – The seed shared between the parties.
-
inline virtual void fillBytes(std::span<uint8_t> dest) override
Fill destination with XChaCha20-generated random bytes.
- Parameters:
dest – The span to fill with random bytes.
-
inline virtual void setSeed(std::vector<unsigned char> &_seed) override
Set the XChaCha20 key from seed bytes.
- Parameters:
_seed – The seed bytes to use as XChaCha20 key.
-
inline virtual void incrementNonce() override
Increment the nonce counter.
Public Static Functions
-
static inline void xchacha20KeyGen(std::span<unsigned char> key)
Generate a random XChaCha20 key.
- Parameters:
key – The span to fill with the generated key.
Public Static Attributes
-
static const size_t MAX_XCHACHA20_QUERY_BYTES = (1 << 20)
Protected Functions
-
inline virtual size_t getPreferredBufferSize() override
Returns the size of the buffer allocated to temporarily store random numbers before they are copied to Vectors.
- Returns:
The preferred buffer size in bytes.
Private Functions
-
inline void xchacha20GenerateValues(std::span<uint8_t> dest)
-
inline XChaCha20PRGAlgorithm(std::vector<unsigned char> &_seed)
-
class AESPRGAlgorithm : public orq::random::DeterministicPRGAlgorithm
-
namespace random
-
namespace orq
-
namespace random
-
class CommonPRG : public orq::random::CorrelationGenerator
- #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.
-
inline void incrementNonce()
Increment nonce if required.
Private Members
-
std::unique_ptr<DeterministicPRGAlgorithm> prg_algorithm
-
inline CommonPRG()
-
class CommonPRGManager
- #include <common_prg.h>
Manages CommonPRG objects for multiple parties and groups.
Maps party ranks and groups to their corresponding CommonPRG instances.
Public Functions
-
inline CommonPRGManager(int _num_parties)
Initializes the CommonPRGManager object with the current party index.
- Parameters:
_num_parties – The number of parties.
Add a CommonPRG object to the manager. The manager handles the index mapping.
- Parameters:
common_prg – A pointer to the CommonPRG to be added to the manager.
relative_rank – The relative rank of the party the prg is shared with.
Add a CommonPRG object to the manager by group. The manager handles the group mapping.
-
inline CommonPRGManager(int _num_parties)
-
class CommonPRG : public orq::random::CorrelationGenerator
-
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
Enums
-
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.
TODO: figure out some way to make the inheritance actually enforced. Currently, can’t make these virtual methods, so need to cast to the specific instance.
Seems like the way to go is std::any and type erasure…
Subclassed by orq::random::BeaverTripleGenerator< T, Encoding::AShared >, orq::random::BeaverTripleGenerator< T, Encoding::BShared >, orq::random::BeaverTripleGenerator< Data, orq::Encoding::AShared >, orq::random::BeaverTripleGenerator< Data, orq::Encoding::BShared >, orq::random::OLEGenerator< T, Encoding::BShared >, orq::random::OLEGenerator< T, Encoding::AShared >, orq::random::OLEGenerator< T, orq::Encoding::BShared >, orq::random::OLEGenerator< Data, E >, orq::random::AuthRandomGeneratorBase< T >, orq::random::AuthTripleGeneratorBase< T >, orq::random::BeaverTripleGenerator< T, E >, orq::random::CommonPRG, orq::random::OLEGenerator< T, E >, orq::random::PooledGenerator< Generator, Ts >, orq::random::ShardedPermutationGenerator, orq::random::ZeroSharingGenerator
Public Functions
-
inline CorrelationGenerator(int _rank)
Constructor for the base correlation generator.
- Parameters:
_rank – The rank of this party.
-
inline int getRank() const
Get the rank of this party.
- Returns:
The rank of this party.
Private Members
-
const int rank
-
inline CorrelationGenerator(int _rank)
-
class CorrelationGenerator : public orq::random::RandomGenerator
-
namespace random
-
namespace orq
-
namespace random
-
template<typename T>
struct CorrelationEnumType<T, Correlation::OLE> - #include <ole_generator.h>
Public Types
-
using type = OLEGenerator<T, Encoding::AShared>
-
using type = OLEGenerator<T, Encoding::AShared>
-
template<typename T>
struct CorrelationEnumType<T, Correlation::rOT> - #include <ole_generator.h>
Public Types
-
using type = OLEGenerator<T, Encoding::BShared>
-
using type = OLEGenerator<T, Encoding::BShared>
-
template<typename T, orq::Encoding E>
class OLEGenerator : public orq::random::CorrelationGenerator - #include <ole_generator.h>
Base class for Oblivious Linear Evaluation generators.
- Template Parameters:
T – The data type for the correlation elements
E – The encoding type (BShared or AShared)
Subclassed by orq::random::DummyOLE< T, E >, orq::random::ZeroOLE< T, E >
Public Functions
-
inline OLEGenerator(int rank, std::optional<Communicator*> _comm)
Constructor for the OLE generator.
- Parameters:
rank – The rank of this party.
_comm – Optional communicator for verification.
-
virtual ole_t getNext(size_t n) = 0
Generate OLE correlations.
- Parameters:
n – The number of OLEs to generate.
- Returns:
A tuple of two vectors representing the OLE correlation.
Verify that the OLE correlation is correct.
- Parameters:
ole – The OLE correlation to verify.
Public Members
-
std::optional<Communicator*> comm
-
template<typename T>
-
namespace random
-
namespace orq
-
namespace random
Variables
-
bool dummy_showed_warning = false
-
template<typename T, orq::Encoding E>
class DummyOLE : public orq::random::OLEGenerator<T, E> - #include <dummy_ole.h>
Insecure dummy OLE generator for testing. Uses a common-seed PRG to choose a random OLE correlation,
A + B = C * D
, where party 0 gets {A, C} and party 1 gets {B, D}.- Template Parameters:
T – underlying datatype
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.
Private Types
-
using OLEBase = OLEGenerator<T, E>
-
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, orq::Encoding E>
class ZeroOLE : public orq::random::OLEGenerator<T, E> - #include <zero_ole.h>
OLE generator that outputs all zeros.
Used for testing and benchmarking where actual security is not required.
- Template Parameters:
T – The data type for the OLE elements
E – The encoding type
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 OLEGenerator<T, E>::ole_t getNext(size_t n)
Generate zero OLE correlations.
- Parameters:
n – The number of OLE pairs to generate.
- Returns:
A tuple of two zero vectors.
-
bool zero_showed_warning = false
-
namespace random
Variables
-
const int MAX_POSSIBLE_THREADS = 256
-
const int SILENT_OT_BASE_PORT = 8877 + (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
Variables
-
const int MAX_TRIPLES_RESERVE_BATCH = 1 << 24
-
namespace orq
-
namespace random
-
-
template<typename T, orq::Encoding E>
class BeaverTripleGenerator : public orq::random::CorrelationGenerator - #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(OLEGenerator<T, E> *v)
Constructor with OLE generator.
- Parameters:
v – The OLE generator to use.
Constructor that takes a PooledGenerator of an OLEGenerator instead of an OLEGenerator itself.
- 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 triple_t getNext(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
CorrelationGenerator
s 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
-
OLEGenerator<T, E> *vg
-
std::variant<std::shared_ptr<PooledGenerator<GilboaOLE<T>, T, T>>, std::shared_ptr<PooledGenerator<SilentOT<T>, T, T>>> pg
-
std::optional<Communicator*> comm
-
template<typename T>
struct CorrelationEnumType<T, Correlation::BeaverAndTriple> - #include <beaver_triple_generator.h>
Public Types
-
using type = BeaverTripleGenerator<T, Encoding::BShared>
-
using type = BeaverTripleGenerator<T, Encoding::BShared>
-
template<typename T>
struct CorrelationEnumType<T, Correlation::BeaverMulTriple> - #include <beaver_triple_generator.h>
Public Types
-
using type = BeaverTripleGenerator<T, Encoding::AShared>
-
using type = BeaverTripleGenerator<T, Encoding::AShared>
-
template<typename T, orq::Encoding E>
-
namespace random
-
namespace orq
-
namespace random
-
template<typename T>
class AuthTripleGeneratorBase : public orq::random::CorrelationGenerator - #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 - #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 : public orq::random::CorrelationGenerator
- #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 : public orq::random::CorrelationGenerator
-
namespace random
Variables
-
const int OPRF_BASE_PORT = 8877 + (MAX_POSSIBLE_THREADS * 32)
-
namespace orq
-
namespace random
-
class OPRF
- #include <oprf.h>
Oblivious Pseudorandom Function implementation.
Provides secure two-party computation of a pseudorandom functions where one party has the key and the other has the input, but neither learns the other’s secret. Outputs are secret shares of the PRF evaluation.
Public Types
-
using key_t = secJoin::AltModPrf::KeyType
Public Functions
-
inline OPRF(int rank, int thread)
Constructor for the OPRF instance.
- Parameters:
rank – The rank of this party (0 or 1).
thread – The thread identifier for port allocation.
-
inline ~OPRF()
Destructor that safely closes all sockets and clears state.
-
template<typename T>
inline Vector<T> evaluate_sender(key_t key, int n) Evaluate OPRF as the sender (key holder).
- Template Parameters:
T – The output data type.
- Parameters:
key – The PRF key to use for evaluation.
n – The number of evaluations to perform.
- Returns:
A vector of PRF output shares.
-
template<typename T>
inline Vector<T> evaluate_receiver(Vector<T> input) Evaluate OPRF as the receiver (input holder).
- Template Parameters:
T – The input and output data type.
- Parameters:
input – The vector of inputs to evaluate.
- Returns:
A vector of PRF output shares corresponding to the inputs.
-
template<typename T>
inline Vector<T> evaluate_plaintext(std::vector<__int128_t> input, key_t key) Evaluate PRF in plaintext (non-oblivious mode).
- Template Parameters:
T – The output data type.
- Parameters:
input – The vector of inputs to evaluate.
key – The PRF key to use for evaluation.
- Returns:
A vector of PRF outputs.
Private Members
-
int rank
-
oc::PRNG prng
-
oc::Socket sock_main_send
-
oc::Socket sock_ole_send
-
oc::Socket sock_main_recv
-
oc::Socket sock_ole_recv
-
bool isServer
-
std::unique_ptr<secJoin::AltModWPrfSender> sender
-
std::unique_ptr<secJoin::AltModWPrfReceiver> receiver
-
secJoin::CorGenerator ole
Private Static Attributes
-
static size_t key_size = 512
-
using key_t = secJoin::AltModPrf::KeyType
-
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.
-
template<typename Generator, typename ...Ts>
class PooledGenerator : public orq::random::CorrelationGenerator - #include <pooled_generator.h>
A wrapper that pools correlations from another generator.
Manages a queue of pre-generated correlations for efficient batch processing.
Includes a compile-time check that the template parameter is a derived class of CorrelationGenerator.
- Template Parameters:
Generator – The underlying correlation generator type
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.
-
inline auto getNext(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 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 Types
-
using typed_correlation = std::tuple<std::type_index, Correlation>
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 – Map of correlation generators.
-
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, Correlation C>
inline CorrelationEnumType<T, C>::type *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 pointer to the correlation generator.
Public Members
-
std::shared_ptr<CommonPRGManager> commonPRGManager
-
std::shared_ptr<ZeroSharingGenerator> zeroSharingGenerator
-
std::map<typed_correlation, CorrelationGenerator*> correlationGenerators
-
using typed_correlation = std::tuple<std::type_index, Correlation>
-
class RandomnessManager
-
namespace random