Protocols

The protocols/ directory contains the MPC protocol implementations supported by ORQ.

Contents:

  • dummy_0pc.h – Dummy 0-party protocol (mock only, not functional, useful for testing).

  • plaintext_1pc.h – Plaintext 1-party protocol (no privacy, useful for testing).

  • beaver_2pc.h – Dishonest-majority 2-party protocol using Beaver triples.

  • replicated_3pc.h – Replicated secret sharing 3-party protocol.

  • dalskov_4pc.h – Dalskov et al. Fantastic-Four 4-party protocol.

  • custom_4pc.h – Rewrite of Fantastic 4PC to be round efficient.

  • dummy_0pc.h – Dummy 0-party protocol (mock only, not functional).

  • plaintext_1pc.h – Plaintext 1-party protocol (no privacy, useful for testing and debugging, but could be used inside of a TEE).

  • replicated_3pc.h – Replicated secret sharing 3-party protocol.

  • protocol.h – Base protocol interface.

  • protocol_factory.h – Factory that instantiates protocol objects.

template<typename Data, typename Share, typename Vector, typename EVector>
class Dummy_0PC : public orq::Protocol<Data, Share, Vector, EVector>

A DUMMY protocol which DOES NOTHING. Results WILL be nonsense.

Template Parameters:
  • Data – Plaintext data type.

  • Share – Replicated share type.

  • Vector – Data container type.

  • EVector – Share container type.

Public Functions

inline Dummy_0PC(PartyID _partyID, Communicator *_communicator, random::RandomnessManager *_randomnessManager)

Constructor for Dummy_0PC protocol.

Parameters:
  • _partyID – Party identifier.

  • _communicator – Pointer to communicator (should be null).

  • _randomnessManager – Pointer to randomness manager.

inline virtual void print_statistics()

Print protocol statistics including operation and round counts.

inline virtual void mark_statistics()

Mark current statistics for relative measurements.

inline virtual void add_a(const EVector &x, const EVector &y, EVector &z)

Dummy arithmetic addition (counts operations only).

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector (unused).

inline virtual void sub_a(const EVector &x, const EVector &y, EVector &z)

Dummy arithmetic subtraction (counts operations only).

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector (unused).

inline virtual void multiply_a(const EVector &x, const EVector &y, EVector &z)

Dummy arithmetic multiplication (counts operations and rounds).

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector (unused).

inline virtual std::pair<EVector, EVector> div_const_a(const EVector &x, const Data &c)

Dummy division by constant (counts operations and rounds).

Parameters:
  • x – Input vector.

  • c – Constant divisor.

Returns:

Dummy pair of vectors.

inline int div_const_a_count()

Get the number of vectors returned by div_const_a.

Returns:

Number of result vectors (always 2).

inline void dot_product_a(const EVector &x, const EVector &y, EVector &z, const int &aggSize)

Dummy dot product (counts operations and rounds).

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector (unused).

  • aggSize – Aggregation size.

inline virtual void xor_b(const EVector &x, const EVector &y, EVector &z)

Dummy bitwise XOR (counts operations only).

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector (unused).

inline virtual void and_b(const EVector &x, const EVector &y, EVector &z)

Dummy bitwise AND (counts operations and rounds).

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector (unused).

inline virtual void not_b(const EVector &x, EVector &y)

Dummy boolean complement (counts operations only).

Parameters:
  • x – Input vector.

  • y – Output vector (unused).

inline virtual void not_b_1(const EVector &x, EVector &y)

Dummy boolean NOT (counts operations only).

Parameters:
  • x – Input vector.

  • y – Output vector (unused).

inline virtual void ltz(const EVector &x, EVector &y)

Dummy less-than-zero comparison (counts operations only).

Parameters:
  • x – Input vector.

  • y – Output vector (unused).

inline virtual std::pair<EVector, EVector> redistribute_shares_b(const EVector &x)

Dummy share redistribution (counts operations and rounds).

Parameters:

x – Input vector.

Returns:

Dummy pair of vectors.

inline virtual void b2a_bit(const EVector &x, EVector &y)

Dummy boolean-to-arithmetic conversion (counts operations and rounds).

Parameters:
  • x – Input vector.

  • y – Output vector (unused).

inline virtual Data reconstruct_from_a(const std::vector<Share> &shares)

Dummy reconstruction from arithmetic shares.

Parameters:

shares – Input shares.

Returns:

First element of first share.

inline virtual Vector reconstruct_from_a(const std::vector<EVector> &shares)

Dummy vectorized reconstruction from arithmetic shares.

Parameters:

shares – Input shared vectors.

Returns:

First share’s first element.

inline virtual Data reconstruct_from_b(const std::vector<Share> &shares)

Dummy reconstruction from boolean shares.

Parameters:

shares – Input shares.

Returns:

First element of first share.

inline virtual Vector reconstruct_from_b(const std::vector<EVector> &shares)

Dummy vectorized reconstruction from boolean shares.

Parameters:

shares – Input shared vectors.

Returns:

First share’s first element.

inline virtual Vector open_shares_a(const EVector &shares)

Dummy opening of arithmetic shares (counts operations and rounds).

Parameters:

shares – Input shared vector.

Returns:

First share’s vector.

inline virtual Vector open_shares_b(const EVector &shares)

Dummy opening of boolean shares (counts operations and rounds).

Parameters:

shares – Input shared vector.

Returns:

First share’s vector.

inline std::vector<Share> get_share_a(const Data &data)

Generate dummy arithmetic share for single value.

Parameters:

data – Input data value.

Returns:

Vector containing the data.

inline virtual std::vector<EVector> get_shares_a(const Vector &data)

Generate dummy arithmetic shares for vector.

Parameters:

data – Input data vector.

Returns:

Vector of shared vectors.

inline std::vector<Share> get_share_b(const Data &data)

Generate dummy boolean share for single value.

Parameters:

data – Input data value.

Returns:

Vector containing the data.

inline virtual std::vector<EVector> get_shares_b(const Vector &data)

Generate dummy boolean shares for vector.

Parameters:

data – Input data vector.

Returns:

Vector of shared vectors.

inline virtual EVector secret_share_b(const Vector &data, const PartyID &data_party = 0)

Dummy boolean secret sharing (counts operations and rounds).

Parameters:
  • data – Input data vector.

  • data_party – Party owning the data.

Returns:

Dummy shared vector.

inline virtual EVector secret_share_a(const Vector &data, const PartyID &data_party = 0)

Dummy arithmetic secret sharing (counts operations and rounds).

Parameters:
  • data – Input data vector.

  • data_party – Party owning the data.

Returns:

Dummy shared vector.

inline virtual EVector public_share(const Vector &data)

Create dummy public share.

Parameters:

data – Input data vector.

Returns:

Dummy shared vector.

inline virtual void reshare(EVector &v, const std::set<int> group, bool binary)

Dummy resharing (counts operations and rounds).

Parameters:
  • v – Input/output vector.

  • group – Party group.

  • binary – Whether shares are binary.

Public Members

int parties_num = 1
std::map<std::string, uint64_t> op_counter
std::map<std::string, std::optional<uint64_t>> mark_op_counter
std::map<std::string, uint64_t> round_counter
std::map<std::string, std::optional<uint64_t>> mark_round_counter
template<typename Data, typename Share, typename Vector, typename EVector>
class Plaintext_1PC : public orq::Protocol<Data, Share, Vector, EVector>

An INSECURE protocol for testing and benchmarking.

DO NOT use this protocol for secure computation.

Template Parameters:
  • Data – Plaintext data type.

  • Share – Replicated share type.

  • Vector – Data container type.

  • EVector – Share container type.

Public Functions

inline Plaintext_1PC(PartyID _partyID, Communicator *_communicator, random::RandomnessManager *_randomnessManager)

Constructor for Plaintext_1PC protocol.

Parameters:
  • _partyID – Party identifier.

  • _communicator – Pointer to communicator (should be null).

  • _randomnessManager – Pointer to randomness manager.

inline virtual void print_statistics()

Print protocol statistics including operation and round counts.

inline virtual void mark_statistics()

Mark current statistics for relative measurements.

inline virtual void add_a(const EVector &x, const EVector &y, EVector &z)

Plaintext arithmetic addition.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void sub_a(const EVector &x, const EVector &y, EVector &z)

Plaintext arithmetic subtraction.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void multiply_a(const EVector &x, const EVector &y, EVector &z)

Plaintext arithmetic multiplication.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void truncate(EVector &x)

Defines vectorized arithmetic truncation. This method must take one input vector with arithmetic shares and return a new vector that contains arithmetic shares of the truncated input. The default implementation invokes the protocol’s public division protocol.

Parameters:

x – - The shared vector to truncate.

inline virtual void neg_a(const EVector &x, EVector &y)

Plaintext arithmetic negation.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual std::pair<EVector, EVector> div_const_a(const EVector &x, const Data &c)

Plaintext division by constant with error correction.

Parameters:
  • x – Input vector.

  • c – Constant divisor.

Returns:

Pair of vectors (quotient and error correction).

inline int div_const_a_count()

Get the number of vectors returned by div_const_a.

Returns:

Number of result vectors (always 2).

inline void dot_product_a(const EVector &x, const EVector &y, EVector &z, const int &aggSize)

Plaintext dot product.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

  • aggSize – Aggregation size.

inline virtual void xor_b(const EVector &x, const EVector &y, EVector &z)

Plaintext bitwise XOR.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void and_b(const EVector &x, const EVector &y, EVector &z)

Plaintext bitwise AND.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void not_b(const EVector &x, EVector &y)

Plaintext boolean complement.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void not_b_1(const EVector &x, EVector &y)

Plaintext boolean NOT.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void ltz(const EVector &x, EVector &y)

Plaintext less-than-zero comparison.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void b2a_bit(const EVector &x, EVector &y)

Plaintext boolean-to-arithmetic conversion.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual std::pair<EVector, EVector> redistribute_shares_b(const EVector &x)

Plaintext share redistribution.

Parameters:

x – Input vector.

Returns:

Pair of vectors (original and zero).

inline virtual Data reconstruct_from_a(const std::vector<Share> &shares)

Plaintext reconstruction from arithmetic shares.

Parameters:

shares – Input shares.

Returns:

First element of first share.

inline virtual Vector reconstruct_from_a(const std::vector<EVector> &shares)

Plaintext vectorized reconstruction from arithmetic shares.

Parameters:

shares – Input shared vectors.

Returns:

First share’s first element.

inline virtual Data reconstruct_from_b(const std::vector<Share> &shares)

Plaintext reconstruction from boolean shares.

Parameters:

shares – Input shares.

Returns:

First element of first share.

inline virtual Vector reconstruct_from_b(const std::vector<EVector> &shares)

Plaintext vectorized reconstruction from boolean shares.

Parameters:

shares – Input shared vectors.

Returns:

First share’s first element.

inline virtual Vector open_shares_a(const EVector &shares)

Plaintext opening of arithmetic shares.

Parameters:

shares – Input shared vector.

Returns:

First share’s vector.

inline virtual Vector open_shares_b(const EVector &shares)

Plaintext opening of boolean shares.

Parameters:

shares – Input shared vector.

Returns:

First share’s vector.

inline std::vector<Share> get_share_a(const Data &data)

Generate plaintext arithmetic share for single value.

Parameters:

data – Input data value.

Returns:

Vector containing the data.

inline virtual std::vector<EVector> get_shares_a(const Vector &data)

Generate plaintext arithmetic shares for vector.

Parameters:

data – Input data vector.

Returns:

Vector of shared vectors.

inline std::vector<Share> get_share_b(const Data &data)

Generate plaintext boolean share for single value.

Parameters:

data – Input data value.

Returns:

Vector containing the data.

inline virtual std::vector<EVector> get_shares_b(const Vector &data)

Generate plaintext boolean shares for vector.

Parameters:

data – Input data vector.

Returns:

Vector of shared vectors.

inline virtual EVector secret_share_b(const Vector &data, const PartyID &data_party = 0)

Plaintext boolean secret sharing.

Parameters:
  • data – Input data vector.

  • data_party – Party owning the data.

Returns:

Shared vector.

inline virtual EVector secret_share_a(const Vector &data, const PartyID &data_party = 0)

Plaintext arithmetic secret sharing.

Parameters:
  • data – Input data vector.

  • data_party – Party owning the data.

Returns:

Shared vector.

inline virtual EVector public_share(const Vector &data)

Create plaintext public share.

Parameters:

data – Input data vector.

Returns:

Shared vector.

inline virtual void reshare(EVector &v, const std::set<int> group, bool binary)

Plaintext resharing (counts operations and rounds).

Parameters:
  • v – Input/output vector.

  • group – Party group.

  • binary – Whether shares are binary.

Public Members

int parties_num = 1
std::map<std::string, uint64_t> op_counter
std::map<std::string, std::optional<uint64_t>> mark_op_counter
std::map<std::string, uint64_t> round_counter
std::map<std::string, std::optional<uint64_t>> mark_round_counter
template<typename Data, typename Share, typename Vector, typename EVector>
class Beaver_2PC : public orq::Protocol<Data, Share, Vector, EVector>

Implements the secure primitives for the 2-party semi-honest protocol that uses Beaver triples.

Template Parameters:
  • Data – Plaintext data type.

  • Share – Share type.

  • Vector – Data container type.

  • EVector – Share container type.

Public Functions

inline Beaver_2PC(PartyID _partyID, Communicator *_communicator, random::RandomnessManager *_randomnessManager)

Constructor for Beaver_2PC protocol.

Parameters:
  • _partyID – Party identifier.

  • _communicator – Pointer to communicator.

  • _randomnessManager – Pointer to randomness manager.

inline virtual void multiply_a(const EVector &x, const EVector &y, EVector &z)

Secure arithmetic multiplication using Beaver triples.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual std::pair<EVector, EVector> div_const_a(const EVector &x, const Data &c)

Division by constant with optional error correction.

Parameters:
  • x – Input vector.

  • c – Constant divisor.

Returns:

Pair of vectors (quotient and error correction).

inline virtual void and_b(const EVector &x, const EVector &y, EVector &z)

Secure bitwise AND using Beaver AND triples.

Performs bitwise AND between two binary secret shared values. Consumes one Beaver AND triple. Direct analog to multiplication.

Parameters:
  • x – Binary shared input.

  • y – Binary shared input.

  • z – Binary shared output.

inline virtual void not_b(const EVector &x, EVector &y)

Boolean complement operation.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void not_b_1(const EVector &x, EVector &y)

Boolean NOT operation.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void b2a_bit(const EVector &x, EVector &y)

Convert a boolean-shared bit in the least significant position to an arithmetic sharing:

First, interpret x = x0 ^ x1 as arithmetic shares. P1 negates its share. Then we have x = x0 - x1, where x’ is some unknown value. Squaring this value under MPC gives the arithmetic conversion:

y = x&rsquo; * x'
  = (x0 - x1) * (x0 - x1)
  = x0 * x0 + x1 * x1 - 2 * x0 * x1
  = x0 + x1 - 2 * x0 * x1

The last line holds since a * a == a for single-bit values. Then we have the arithmetized XOR expression, as required. Since we perform MPC multiplication, the result is already randomized.

Parameters:
  • x – Input boolean shared vector.

  • y – Output arithmetic shared vector.

inline virtual std::pair<EVector, EVector> redistribute_shares_b(const EVector &x)

Redistribute boolean shares.

Parameters:

x – Input vector.

Returns:

Pair of redistributed shared vectors.

inline virtual Data reconstruct_from_a(const std::vector<Share> &shares)

Reconstruct plaintext from arithmetic shares.

Parameters:

shares – Input shares from both parties.

Returns:

Reconstructed plaintext value.

inline virtual Vector reconstruct_from_a(const std::vector<EVector> &shares)

Reconstruct plaintext vector from arithmetic shares.

Parameters:

shares – Input shared vectors from both parties.

Returns:

Reconstructed plaintext vector.

inline virtual Data reconstruct_from_b(const std::vector<Share> &shares)

Reconstruct plaintext from boolean shares.

Parameters:

shares – Input shares from both parties.

Returns:

Reconstructed plaintext value.

inline virtual Vector reconstruct_from_b(const std::vector<EVector> &shares)

Reconstruct plaintext vector from boolean shares.

Parameters:

shares – Input shared vectors from both parties.

Returns:

Reconstructed plaintext vector.

inline virtual Vector open_shares_a(const EVector &shares)

Open arithmetic shares to reveal plaintext.

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline virtual Vector open_shares_b(const EVector &shares)

Open boolean shares to reveal plaintext.

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline std::vector<Share> get_share_a(const Data &data)

Generate arithmetic shares for a single value.

Parameters:

data – Input plaintext value.

Returns:

Vector of arithmetic shares for both parties.

inline virtual std::vector<EVector> get_shares_a(const Vector &data)

Generate arithmetic shares for a vector.

Parameters:

data – Input plaintext vector.

Returns:

Vector of arithmetic shared vectors for both parties.

inline std::vector<Share> get_share_b(const Data &data)

Generate boolean shares for a single value.

Parameters:

data – Input plaintext value.

Returns:

Vector of boolean shares for both parties.

inline virtual std::vector<EVector> get_shares_b(const Vector &data)

Generate boolean shares for a vector.

Parameters:

data – Input plaintext vector.

Returns:

Vector of boolean shared vectors for both parties.

inline virtual EVector secret_share_b(const Vector &data, const PartyID &data_party = 0)

Secret share a boolean vector.

Parameters:
  • data – Input plaintext vector.

  • data_party – Party that owns the data.

Returns:

This party’s boolean shared vector.

inline virtual EVector secret_share_a(const Vector &data, const PartyID &data_party = 0)

Secret share an arithmetic vector.

Parameters:
  • data – Input plaintext vector.

  • data_party – Party that owns the data.

Returns:

This party’s arithmetic shared vector.

inline virtual EVector public_share(const Vector &data)

Create public shares from plaintext data.

Parameters:

data – Input plaintext vector.

Returns:

Public shared vector.

Public Static Attributes

static int parties_num
template<typename Data, typename Share, typename Vector, typename EVector>
class Replicated_3PC : public orq::Protocol<Data, Share, Vector, EVector>

Implements the secure primitives for the 3-party semi-honest protocol by Araki et al. that uses replicated secret sharing.

Template Parameters:
  • Data – Plaintext data type.

  • Share – Replicated share type.

  • Vector – Data container type.

  • EVector – Share container type.

Public Functions

inline Replicated_3PC(PartyID _partyID, Communicator *_communicator, random::RandomnessManager *_randomnessManager)

Constructor for the semi-honest replicated 3-party protocol by Araki et al.

Parameters:
  • _partyID – The (globally) unique id of the party that calls this constructor.

  • _communicator – A pointer to the communicator.

  • _randomnessManager – A pointer to the randomness manager.

inline virtual void multiply_a(const EVector &x, const EVector &y, EVector &z)

Secure arithmetic multiplication using replicated secret sharing.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual std::pair<EVector, EVector> div_const_a(const EVector &x, const Data &c)

Division by constant with share redistribution.

Algorithm:

  1. Start with 3 secret shares (x1, x2, x3), but division requires 2 shares.

  2. Merge first 2 shares to get x1’ = x1 + x2.

  3. Use shares (x1’, x3) for division on secret shares.

  4. End up with (x1/c, x3/c) which are only two shares, but we need 3 shares.

  5. Redistribute shares (y1, y2) to be (y1 - r, r, y2) where r is random.

  6. Logic for calculating result and error is identical to 2PC.

Parameters:
  • x – Input vector.

  • c – Constant divisor.

Returns:

Pair of vectors (quotient and error correction).

inline EVector dot_product_a(const EVector &x, const EVector &y, const int &aggSize)

Secure dot product using replicated secret sharing.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • aggSize – Aggregation size.

Returns:

Output vector containing dot products.

inline virtual void and_b(const EVector &x, const EVector &y, EVector &z)

Secure bitwise AND using replicated secret sharing.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void not_b(const EVector &x, EVector &y)

Boolean complement operation.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void not_b_1(const EVector &x, EVector &y)

Boolean NOT operation (LSB only).

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void b2a_bit(const EVector &x, EVector &y)

Convert boolean-shared bit to arithmetic sharing.

Converts a boolean-shared bit (LSB only) to arithmetic sharing using replicated secret sharing protocol.

Should only be used for the least significant bit.

Parameters:
  • x – Input boolean shared vector.

  • y – Output arithmetic shared vector.

inline virtual std::pair<EVector, EVector> redistribute_shares_b(const EVector &x)

Redistribute boolean shares.

Parameters:

x – Input vector.

Returns:

Pair of redistributed shared vectors.

inline virtual Data reconstruct_from_a(const std::vector<Share> &shares)

Reconstruct plaintext from arithmetic shares.

Parameters:

shares – Input shares from all three parties.

Returns:

Reconstructed plaintext value.

inline virtual Vector reconstruct_from_a(const std::vector<EVector> &shares)

Reconstruct plaintext vector from arithmetic shares.

Parameters:

shares – Input shared vectors from all three parties.

Returns:

Reconstructed plaintext vector.

inline virtual Data reconstruct_from_b(const std::vector<Share> &shares)

Reconstruct plaintext from boolean shares.

Parameters:

shares – Input shares from all three parties.

Returns:

Reconstructed plaintext value.

inline virtual Vector reconstruct_from_b(const std::vector<EVector> &shares)

Reconstruct plaintext vector from boolean shares.

Parameters:

shares – Input shared vectors from all three parties.

Returns:

Reconstructed plaintext vector.

inline virtual Vector open_shares_a(const EVector &shares)

Open arithmetic shares to reveal plaintext.

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline virtual Vector open_shares_b(const EVector &shares)

Open boolean shares to reveal plaintext.

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline std::vector<Share> get_share_a(const Data &data)

Generate replicated arithmetic shares for a single value.

Parameters:

data – Input plaintext value.

Returns:

Vector of replicated arithmetic shares for all parties.

inline virtual std::vector<EVector> get_shares_a(const Vector &data)

Generate replicated arithmetic shares for a vector.

Parameters:

data – Input plaintext vector.

Returns:

Vector of replicated arithmetic shared vectors for all parties.

inline std::vector<Share> get_share_b(const Data &data)

Generate replicated boolean shares for a single value.

Parameters:

data – Input plaintext value.

Returns:

Vector of replicated boolean shares for all parties.

inline virtual std::vector<EVector> get_shares_b(const Vector &data)

Generate replicated boolean shares for a vector.

Parameters:

data – Input plaintext vector.

Returns:

Vector of replicated boolean shared vectors for all parties.

inline virtual EVector secret_share_b(const Vector &data, const PartyID &data_party = 0)

Secret share a boolean vector using replicated sharing.

Parameters:
  • data – Input plaintext vector.

  • data_party – Party that owns the data.

Returns:

This party’s replicated boolean shared vector.

inline virtual EVector secret_share_a(const Vector &data, const PartyID &data_party = 0)

Secret share an arithmetic vector using replicated sharing.

Parameters:
  • data – Input plaintext vector.

  • data_party – Party that owns the data.

Returns:

This party’s replicated arithmetic shared vector.

inline virtual EVector public_share(const Vector &x)

Create public shares from plaintext data using replicated sharing.

Parameters:

x – Input plaintext vector.

Returns:

Public replicated shared vector.

Public Static Attributes

static int parties_num
template<typename Data, typename Share, typename Vector, typename EVector>
class Fantastic_4PC : public orq::Protocol<Data, Share, Vector, EVector>, public orq::Protocol<Data, Share, Vector, EVector>

Implements the secure primitives for the 4-party malicious protocol by Dalskov et al. that uses replicated secret sharing.

Implementation of the “Fantastic Four” paper by Dalskov et al.

This version implements functionalities exactly as specified in the paper, without any optimizations.

Template Parameters:
  • Data – Plaintext data type.

  • Share – Replicated share type.

  • Vector – Data container type.

  • EVector – Share container type.

  • Data – Plaintext data type.

  • Share – Replicated share type.

  • Vector – Data container type.

  • EVector – Share container type.

Public Functions

inline virtual std::vector<std::set<int>> getGroups() const

Override of default groups to achieve malicious security.

This group selection gives us two copies of each share per group (redundancy).

Returns:

Vector of party groups for malicious security.

inline Fantastic_4PC(PartyID _partyID, Communicator *_communicator, random::RandomnessManager *_randomnessManager)

Constructor for Fantastic_4PC protocol.

Parameters:
  • _partyID – Party identifier.

  • _communicator – Pointer to communicator.

  • _randomnessManager – Pointer to randomness manager.

inline virtual void multiply_a(const EVector &x, const EVector &y, EVector &z)

Secure arithmetic multiplication with malicious security.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline EVector inp_a(const Vector &x, const int &i, const int &j, const int &g, const int &h)

Input sharing protocol for specific party sequence.

Note: this inp is for the div function pattern only. [i precedes j precedes g precedes h].

Parameters:
  • x – Input vector to be shared.

  • i – First party in sequence.

  • j – Second party in sequence.

  • g – Third party in sequence (receiver).

  • h – Fourth party in sequence (randomness generator).

Returns:

Shared vector.

inline virtual std::pair<EVector, EVector> div_const_a(const EVector &x, const Data &c)

Division by constant with malicious security.

Parameters:
  • x – Input vector.

  • c – Constant divisor.

Returns:

Pair of vectors (quotient and error correction).

inline EVector inp_b(const Vector &x, const int &i, const int &j, const int &g, const int &h)

Boolean input sharing protocol for specific party sequence.

Note: this inp is for the div function pattern only. [i precedes j precedes g precedes h].

Parameters:
  • x – Input vector to be shared.

  • i – First party in sequence.

  • j – Second party in sequence.

  • g – Third party in sequence (receiver).

  • h – Fourth party in sequence (randomness generator).

Returns:

Shared vector.

inline virtual void and_b(const EVector &x, const EVector &y, EVector &z)

Secure bitwise AND with malicious security.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void not_b(const EVector &x, EVector &y)

Boolean NOT operation.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void not_b_1(const EVector &x, EVector &y)

Boolean NOT operation for the least significant bit.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void b2a_bit(const EVector &x, EVector &y)

Convert a boolean-shared bit to arithmetic sharing.

4PC share distribution: P0: [B, C, D] -> B C D P1: [C, D, A] -> A C D P2: [D, A, B] -> A B D P3: [A, B, C] -> A B C

Reducing the 4-share to a 2-share: share0 = C ^ D share1 = A ^ B

P0 and P1 can both calculate share0. P2 and P3 can both calculate share1.

Since 2 parties can calculate each of the above, INP can be used to generate a secret-share for share0 and share1.

XOR evaluated as: x ^ y = (x - y)^2 (holds true for binary input)

Parameters:
  • x – Input boolean shared vector.

  • y – Output arithmetic shared vector.

inline virtual std::pair<EVector, EVector> redistribute_shares_b(const EVector &x)

Redistribute boolean shares.

Parameters:

x – Input vector.

Returns:

Pair of redistributed shared vectors.

inline virtual Data reconstruct_from_a(const std::vector<Share> &shares)

Reconstruct plaintext from arithmetic shares.

Parameters:

shares – Input shares from all four parties.

Returns:

Reconstructed plaintext value.

inline virtual Vector reconstruct_from_a(const std::vector<EVector> &shares)

Reconstruct plaintext vector from arithmetic shares.

Parameters:

shares – Input shared vectors from all four parties.

Returns:

Reconstructed plaintext vector.

inline virtual Data reconstruct_from_b(const std::vector<Share> &shares)

Reconstruct plaintext from boolean shares.

Parameters:

shares – Input shares from all four parties.

Returns:

Reconstructed plaintext value.

inline virtual Vector reconstruct_from_b(const std::vector<EVector> &shares)

Reconstruct plaintext vector from boolean shares.

Parameters:

shares – Input shared vectors from all four parties.

Returns:

Reconstructed plaintext vector.

inline virtual Vector open_shares_a(const EVector &shares)

Open arithmetic shares to reveal plaintext.

TODO: malicious check

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline virtual Vector open_shares_b(const EVector &shares)

Open boolean shares to reveal plaintext.

TODO: malicious check

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline std::vector<Share> get_share_a(const Data &data)

Generate arithmetic shares for a single value.

Parameters:

data – Input data value.

Returns:

Vector of shares for all parties.

inline virtual std::vector<EVector> get_shares_a(const Vector &data)

Generate arithmetic shares for a vector.

Parameters:

data – Input data vector.

Returns:

Vector of shares for all parties.

inline std::vector<Share> get_share_b(const Data &data)

Generate boolean shares for a single value.

Parameters:

data – Input data value.

Returns:

Vector of shares for all parties.

inline virtual std::vector<EVector> get_shares_b(const Vector &data)

Generate boolean shares for a vector.

Parameters:

data – Input data vector.

Returns:

Vector of shares for all parties.

inline virtual EVector secret_share_b(const Vector &data, const PartyID &data_party = 0)

Secret share data using the custom 4PC protocol.

Parameters:
  • data – Input data vector.

  • data_party – Party ID of the data party.

Returns:

Secret shared vector.

inline virtual EVector secret_share_a(const Vector &data, const PartyID &data_party = 0)

Secret share data using the custom 4PC protocol.

Parameters:
  • data – Input data vector.

  • data_party – Party ID of the data party.

Returns:

Secret shared vector.

inline virtual EVector public_share(const Vector &x)

Public sharing of a vector x.

P0 gets: (0, 0, 0 ) P1 gets: ( 0, 0, x) P2 gets: (0, 0, x) P3 gets: (0, 0, x)

Parameters:

x – Input data vector.

Returns:

EVector

inline virtual void reshare(EVector &v, const std::set<int> group, bool binary)

An override version of reshare for malicious security in 4PC.

Parameters:
  • v – The vector to be rerandomized and reshared.

  • group – The group performing the resharing.

  • binary – A flag indicating an arithmetic or binary encoding of the vector.

inline virtual std::vector<std::set<int>> getGroups() const

Override of default groups to achieve malicious security.

This group selection gives us two copies of each share per group (redundancy).

Returns:

Vector of party groups for malicious security.

inline Fantastic_4PC(PartyID _partyID, Communicator *_communicator, random::RandomnessManager *_randomnessManager)

Constructor for Fantastic_4PC protocol (Dalskov implementation).

Parameters:
  • _partyID – Party identifier.

  • _communicator – Pointer to communicator.

  • _randomnessManager – Pointer to randomness manager.

inline void jmp(Vector &x, int from, int also_from, int to)

Joint message passing protocol.

Parameters:
  • xVector of (non-secret shared) data.

  • from – Owner of this data.

  • also_from – Co-owner of data.

  • to – Party who will receive data from both.

template<orq::Encoding E>
inline EVector inp(const Vector &x, int Pi, int Pj, std::optional<int> Pg = {}, std::optional<int> Ph = {})

Shared-input function.

Two parties, who both know a plaintext value x, secret-share it with the other two parties.

Template Parameters:

EEncoding type (A- or B-shared).

Parameters:
  • x – Plaintext data.

  • Pi – First owner.

  • Pj – Second owner.

  • Pg – Optional third party (computed if not provided).

  • Ph – Optional fourth party (computed if not provided).

Returns:

Shared vector.

inline virtual void multiply_a(const EVector &x, const EVector &y, EVector &z)

Multiply two arithmetic-shared vectors.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual std::pair<EVector, EVector> div_const_a(const EVector &x, const Data &c)

Divide an arithmetic-shared vector by a constant.

Parameters:
  • x – Input vector.

  • c – Constant divisor.

Returns:

Pair of vectors (quotient and error correction).

inline virtual void and_b(const EVector &x, const EVector &y, EVector &z)

Boolean AND operation.

Parameters:
  • x – First input vector.

  • y – Second input vector.

  • z – Output vector.

inline virtual void not_b(const EVector &x, EVector &y)

Boolean NOT operation.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void not_b_1(const EVector &x, EVector &y)

Boolean NOT operation for the least significant bit.

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual void b2a_bit(const EVector &x, EVector &y)

Convert a boolean-shared bit in the least significant position to an arithmetic sharing:

4PC share distribution: P0: [B, C, D] -> B C D P1: [C, D, A] -> A C D P2: [D, A, B] -> A B D P3: [A, B, C] -> A B C

Reducing the 4-share to a 2-share: share0 = C ^ D share1 = A ^ B

P0 and P1 can both calculate share0. P2 and P3 can both calculate share1.

Since 2 parties can calculate each of the above, INP can be used to generate a secret-share for share0 and share1.

XOR evaluated as: x ^ y = (x - y)^2 (holds true for binary input)

Parameters:
  • x – Input vector.

  • y – Output vector.

inline virtual std::pair<EVector, EVector> redistribute_shares_b(const EVector &x)

Redistribute boolean shares.

Parameters:

x – Input vector.

Returns:

Pair of vectors (redistributed shares).

inline virtual Data reconstruct_from_a(const std::vector<Share> &shares)

Reconstruct arithmetic shares from a vector of shares.

Parameters:

shares – Input shares.

Returns:

Reconstructed arithmetic shares.

inline virtual Vector reconstruct_from_a(const std::vector<EVector> &shares)

Reconstruct arithmetic shares from a vector of shares.

Parameters:

shares – Input shares.

Returns:

Reconstructed arithmetic shares.

inline virtual Data reconstruct_from_b(const std::vector<Share> &shares)

Reconstruct boolean shares from a vector of shares.

Parameters:

shares – Input shares.

Returns:

Reconstructed boolean shares.

inline virtual Vector reconstruct_from_b(const std::vector<EVector> &shares)

Reconstruct boolean shares from a vector of shares.

Parameters:

shares – Input shares.

Returns:

Reconstructed boolean shares.

inline virtual Vector open_shares_a(const EVector &shares)

Open arithmetic shares to reveal plaintext.

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline virtual Vector open_shares_b(const EVector &shares)

Open boolean shares to reveal plaintext.

Parameters:

shares – Input shared vector.

Returns:

Opened plaintext vector.

inline virtual bool malicious_check(bool should_abort = true)

Malicious check for hash consistency.

Parameters:

should_abort – Whether to abort on failure.

Returns:

True if checks passed, false otherwise.

inline virtual std::vector<EVector> get_shares_a(const Vector &data)

Generate arithmetic shares for a vector.

Parameters:

data – Input data vector.

Returns:

Vector of shares for all parties.

inline virtual std::vector<EVector> get_shares_b(const Vector &data)

Generate boolean shares for a vector.

Parameters:

data – Input data vector.

Returns:

Vector of shares for all parties.

inline virtual EVector secret_share_b(const Vector &data, const PartyID &data_party = 0)

Secret share data using the custom 4PC protocol.

Parameters:
  • data – Input data vector.

  • data_party – Party ID of the data party.

Returns:

Secret shared vector.

inline virtual EVector secret_share_a(const Vector &data, const PartyID &data_party = 0)

Secret share data using the custom 4PC protocol.

Parameters:
  • data – Input data vector.

  • data_party – Party ID of the data party.

Returns:

Secret shared vector.

inline virtual EVector public_share(const Vector &x)

Public sharing of a vector x.

P0 gets: ( 0, 0, 0) P1 gets: (x, 0, 0) P2 gets: (x, 0, 0) P3 gets: (x, 0, 0 )

Parameters:

x – Input data vector.

Returns:

EVector

inline virtual void reshare(EVector &v, const std::set<int> group, bool binary)

An override version of reshare for malicious security in 4PC.

Parameters:
  • v – The vector to be rerandomized and reshared.

  • group – The group performing the resharing.

  • binary – A flag indicating an arithmetic or binary encoding of the vector.

Public Static Attributes

static int parties_num

Private Functions

inline void malicious_check(const Vector &x, const Vector &y, const int p1, const int p2)

Malicious check to assert that two vectors are the same.

Given two vectors x and y, assert that they are the same. If they are not, accuse the specified parties and abort.

Parameters:
  • x – The first vector.

  • y – The second vector.

  • p1 – The first party relative ID to accuse if they are not the same.

  • p2 – The second party relative ID to accuse if they are not the same.

inline int next_party(int i, int j)

Computes the JMP receiver.

Designed to give each party a chance to be the receiver. This is required for open to be correct.

Parameters:
  • i – First party.

  • j – Second party.

Returns:

Party ID of the receiver.

inline int excluded_party(int i, int j, int k)

Return the index of the missing party.

All party indices will sum to 6 (0 + 1 + 2 + 3), so just subtract the given parties to find the missing one.

Parameters:
  • i – First party.

  • j – Second party.

  • k – Third party.

Returns:

Index of the missing party.

inline int abs2rel(int p)

Convert absolute party ID to relative party ID.

Parameters:

p – Absolute party ID.

Returns:

Relative party ID.

inline int rel2abs(int p)

Convert relative party ID to absolute party ID.

Parameters:

p – Relative party ID.

Returns:

Absolute party ID.

inline int abs2sh(int p)

Compute which relative share is \(x_p\) (my share excluding party p).

If self, return 0, even though that’s not a valid share (this is to prevent out-of-bounds array accesses on party-agnostic code).

Parameters:

p – Party ID.

Returns:

Relative share index.

inline int who_hashes(int a, int b)

Given two JMP senders, decide who will hash and who will send.

Different strategies here could change performance by redistributing work. This function must be commutative (who_hashes(a, b) == who_hashes(b, a)).

Parameters:
  • a – First party.

  • b – Second party.

Returns:

Party who should hash.

inline void init_hash(int i, int j)

Initialize hash state for malicious security.

Parameters:
  • i – First party (must be less than j).

  • j – Second party.

inline Vector _open_shares(const EVector &sh)

Internal method to open shares using JMP protocol.

Parameters:

sh – Input shared vector.

Returns:

Opened plaintext vector.

template<typename orq::Encoding E>
inline std::vector<EVector> get_shares(const Vector &data)

Generate shares for given data with specified encoding.

Template Parameters:

EEncoding type (AShared or BShared).

Parameters:

data – Input plaintext vector.

Returns:

Vector of shared vectors for all parties.

template<orq::Encoding E>
inline EVector _secret_share(const Vector &data, const PartyID &data_party)

Internal secret sharing method with specified encoding.

Template Parameters:

EEncoding type (AShared or BShared).

Parameters:
  • data – Input plaintext vector.

  • data_party – Party that owns the data.

Returns:

This party’s shared vector.

inline std::tuple<int, int, std::pair<int, int>> _jmp_assignments(int Pi, int Pj)

Compute JMP assignments for parties Pi and Pj.

Parameters:
  • Pi – First party.

  • Pj – Second party.

Returns:

Tuple containing hash party, send party, and hash ID.

inline void _jmp_recv(Vector &x, int Pi, int Pj, int Pr)

JMP receive operation for malicious security.

Parameters:
  • xVector to receive data into.

  • Pi – First sender party.

  • Pj – Second sender party.

  • Pr – Receiver party (must be this party).

inline void _jmp_send(const Vector &x, int Pi, int Pj, int Pr)

JMP send operation for malicious security.

Parameters:
  • xVector to send.

  • Pi – First sender party.

  • Pj – Second sender party.

  • Pr – Receiver party.

Private Members

std::map<std::pair<int, int>, std::unique_ptr<crypto_generichash_state>> hash_states

Utilities and Base Classes

Defines

TYPE_BITS_int8_t
TYPE_BITS_int16_t
TYPE_BITS_int32_t
TYPE_BITS_int64_t
TYPE_BITS___int128_t
TYPE_BITS(T)
GLUE_(a, b)
GLUE(a, b)
PROTO_OBJ_NAME(T)
namespace orq

Enums

enum class ReshareAction

Actions for resharing operations.

Values:

enumerator Send
enumerator Receive
template<typename Data, typename Share, typename Vector, typename EVector>
class Protocol : public orq::ProtocolBase
#include <protocol.h>

Abstract class defining primitive methods for secure protocols.

This is the abstract class that defines the primitive methods each secure protocol must implement.

Primitive operations are grouped as follows:

  1. Arithmetic operations on arithmetic shares.

  2. Boolean operations on boolean shares.

  3. Primitives for sending and receiving shares.

  4. Primitives for constructing and opening shares to learners.

Template Parameters:
  • Data – Plaintext data type.

  • Share – Share type (e.g., a 32-bit integer, a pair of 64-bit integers, etc.).

  • Vector – Data container type.

  • EVector – Share container type.

Subclassed by orq::Dummy_0PC< int8_t, ReplicatedShare< int8_t >, Vector< int8_t >, EVector< int8_t > >, orq::Dummy_0PC< int16_t, ReplicatedShare< int16_t >, Vector< int16_t >, EVector< int16_t > >, orq::Dummy_0PC< int32_t, ReplicatedShare< int32_t >, Vector< int32_t >, EVector< int32_t > >, orq::Dummy_0PC< int64_t, ReplicatedShare< int64_t >, Vector< int64_t >, EVector< int64_t > >, orq::Dummy_0PC< __int128_t, ReplicatedShare< __int128_t >, Vector< __int128_t >, EVector< __int128_t > >, orq::Plaintext_1PC< int8_t, ReplicatedShare< int8_t >, Vector< int8_t >, EVector< int8_t > >, orq::Plaintext_1PC< int16_t, ReplicatedShare< int16_t >, Vector< int16_t >, EVector< int16_t > >, orq::Plaintext_1PC< int32_t, ReplicatedShare< int32_t >, Vector< int32_t >, EVector< int32_t > >, orq::Plaintext_1PC< int64_t, ReplicatedShare< int64_t >, Vector< int64_t >, EVector< int64_t > >, orq::Plaintext_1PC< __int128_t, ReplicatedShare< __int128_t >, Vector< __int128_t >, EVector< __int128_t > >, orq::Beaver_2PC< Data, Share, Vector, EVector >, orq::Dummy_0PC< Data, Share, Vector, EVector >, orq::Fantastic_4PC< Data, Share, Vector, EVector >, orq::Fantastic_4PC< Data, Share, Vector, EVector >, orq::Plaintext_1PC< Data, Share, Vector, EVector >, orq::Replicated_3PC< Data, Share, Vector, EVector >

Public Functions

inline Protocol(Communicator *_communicator, random::RandomnessManager *_randomnessManager, PartyID _partyID, const int &_numParties, const int &_replicationNumber)

Protocol constructor.

Parameters:
  • _communicator – A pointer to the communicator.

  • _randomnessManager – A pointer to the randomness manager.

  • _partyID – The (globally) unique identifier of the party that calls this constructor.

  • _numParties – The total number of computing parties participating in the protocol.

  • _replicationNumber – The protocol’s replication factor.

inline virtual ~Protocol()

Destructor.

inline virtual void reshare(EVector &v, const std::set<int> group, bool binary)

Reshare shares with other parties.

The group rerandomizes the vector v and sends shares to all parties that are not in the group.

Operates in place.

TODO: fix runtime to support this better.

Parameters:
  • v – The EVector representing each party’s view of the vector to be

  • group – The group of parties that perform the resharing.

  • binary – whether this is a binary (true) or arithmetic (false) resharing reshared.

inline virtual void handle_precision(const EVector &x, const EVector &y, EVector &z)
inline virtual void add_a(const EVector &x, const EVector &y, EVector &z)

Defines vectorized arithmetic addition.

Parameters:
  • x – The first shared vector of size S.

  • y – The second shared vector of size S.

  • z – The output shared vector of size S.

inline virtual void sub_a(const EVector &x, const EVector &y, EVector &z)

Defines vectorized arithmetic subtraction.

Parameters:
  • x – The first shared vector of size S.

  • y – The second shared vector of size S.

  • z – The output shared vector of size S.

virtual void multiply_a(const EVector &first, const EVector &second, EVector &result) = 0

Defines vectorized arithmetic multiplication.

Parameters:
  • first – The first shared vector of size S.

  • second – The second shared vector of size S.

  • result – The output shared vector of size S.

inline virtual void neg_a(const EVector &in, EVector &out)

Defines vectorized arithmetic negation.

Parameters:
  • in – The input shared vector of size S.

  • out – The output shared vector of size S.

virtual std::pair<EVector, EVector> div_const_a(const EVector &input, const Data &c) = 0

Defines vectorized arithmetic division by constant.

Parameters:
  • input – The input shared vector.

  • c – The constant divisor.

Returns:

Pair of shared vectors representing the division result.

inline virtual void dot_product_a(const EVector &x, const EVector &y, EVector &z, const size_t &aggSize)

Defines the vectorized dot product operation for consecutive elements.

Parameters:
  • x – The first shared vector of size S.

  • y – The second shared vector of size S.

  • z – The output shared vector.

  • aggSize – The number of consecutive pairs of elements to aggregate.

inline virtual void truncate(EVector &x)

Defines vectorized arithmetic truncation. This method must take one input vector with arithmetic shares and return a new vector that contains arithmetic shares of the truncated input. The default implementation invokes the protocol’s public division protocol.

Parameters:

x – - The shared vector to truncate.

inline virtual void xor_b(const EVector &x, const EVector &y, EVector &z)

Defines vectorized bitwise XOR (^).

Parameters:
  • x – The first shared vector of size S.

  • y – The second shared vector of size S.

  • z – The output shared vector of size S.

virtual void and_b(const EVector &first, const EVector &second, EVector &result) = 0

Defines vectorized bitwise AND (&).

Parameters:
  • first – The first shared vector of size S.

  • second – The second shared vector of size S.

  • result – The output shared vector of size S.

virtual void not_b(const EVector &in, EVector &out) = 0

Defines vectorized boolean complement (~).

Parameters:
  • in – The input shared vector of size S.

  • out – The output shared vector of size S.

virtual void not_b_1(const EVector &in, EVector &out) = 0

Defines vectorized boolean NOT (!).

Parameters:
  • in – The input shared vector of size S.

  • out – The output shared vector of size S.

inline virtual void ltz(const EVector &in, EVector &out)

Defines vectorized less-than-zero comparison.

Parameters:
  • in – The input shared vector of size S.

  • out – The output shared vector of size S.

virtual void b2a_bit(const EVector &in, EVector &out) = 0

Defines vectorized boolean-to-arithmetic single bit conversion.

Parameters:
  • in – A B-shared vector of S single-bit elements.

  • out – The output A-shared vector of size S.

virtual std::pair<EVector, EVector> redistribute_shares_b(const EVector &x) = 0

Defines a redistribution of arithmetic secret shares into boolean secret shares.

Parameters:

x – The input arithmetic shared vector.

Returns:

Pair of boolean shared vectors representing the redistribution.

virtual Data reconstruct_from_a(const std::vector<Share> &shares) = 0

Defines how to reconstruct a single data value by adding its arithmetic shares.

NOTE: This method is useful when a computing party also acts as learner that receives arithmetic shares from other parties and needs to reconstruct a true value.

Parameters:

shares – The input vector containing arithmetic shares of the secret value.

Returns:

The plaintext value of type Data.

virtual Vector reconstruct_from_a(const std::vector<EVector> &shares) = 0

Vectorized version of the reconstruct_from_a() method.

NOTE: This method is useful when a computing party also acts as learner that receives arithmetic shared vectors from other parties and needs to reconstruct the original vector.

Parameters:

shares – A vector of shared vectors (each one of size n) that contain arithmetic shares.

Returns:

A new vector that contains n plaintext values of type Data.

virtual Data reconstruct_from_b(const std::vector<Share> &shares) = 0

Defines how to reconstruct a single data value by XORing its boolean shares.

NOTE: This method is useful when a computing party also acts as learner that receives boolean shares from other parties and needs to reconstruct a true value.

Parameters:

shares – The input vector containing boolean shares of the secret value.

Returns:

The plaintext value of type Data.

virtual Vector reconstruct_from_b(const std::vector<EVector> &shares) = 0

Vectorized version of the reconstruct_from_b() method.

NOTE: This method is useful when a computing party also acts as learner that receives boolean shared vectors from other parties and needs to reconstruct the original vector.

Parameters:

shares – A vector of shared vectors (each one of size n) that contain boolean shares.

Returns:

A new vector that contains n plaintext values of type Data.

virtual Vector open_shares_a(const EVector &shares) = 0

Opens arithmetic shares to reveal plaintext values.

NOTE: This method is useful when computing parties need to reveal a secret-shared vector to each other.

Parameters:

shares – A shared vector that contains arithmetic shares of the secret values.

Returns:

A new vector that contains the plaintext values of type Data.

virtual Vector open_shares_b(const EVector &shares) = 0

Opens boolean shares to reveal plaintext values.

NOTE: This method is useful when computing parties need to reveal a secret-shared vector to each other.

Parameters:

shares – A shared vector that contains boolean shares of the secret values.

Returns:

A new vector that contains the plaintext values of type Data.

virtual std::vector<EVector> get_shares_a(const Vector &data) = 0

Compute secret shares for a vector of plaintext values.

Parameters:

data – A vector of input values of type Data.

Returns:

A vector of shared vectors containing arithmetic shares.

virtual std::vector<EVector> get_shares_b(const Vector &data) = 0

Compute secret shares for a vector of plaintext values.

Parameters:

data – A vector of input values of type Data.

Returns:

A vector of shared vectors containing boolean shares.

virtual EVector secret_share_b(const Vector &data, const PartyID &data_party) = 0

Compute secret shares for a vector of plaintext values.

NOTE: This method is useful for secret-sharing plaintext data in ORQ programs.

Parameters:
  • data – The plaintext vector that must be secret-shared among computing parties.

  • data_party – The party that owns the data.

Returns:

The boolean shared vector

inline virtual EVector secret_share_b(const Vector &data, const PartyID &data_party, const int &fixed_point_precision)

Compute secret shares for a vector of plaintext values. Overloaded secret_share_b function that establishes a non-zero fixed-point precision.

Parameters:
  • data – The plaintext vector that must be secret-shared among computing parties.

  • data_party – The party that owns the data.

  • fixed_point_precision – precision of the input values

Returns:

The boolean shared fixed-point vector

virtual EVector secret_share_a(const Vector &data, const PartyID &data_party) = 0

Defines how to A-share a plaintext vector according to a protocol.

NOTE: This method is useful for secret-sharing plaintext data in ORQ programs.

Parameters:
  • data – - The plaintext vector that must be secret-shared among computing parties.

  • data_party – data ownner

Returns:

The arithmetic shared vector of the party that calls this method.

inline virtual EVector secret_share_a(const Vector &data, const PartyID &data_party, const int &fixed_point_precision)

Compute secret shares for a vector of plaintext values. Overloaded secret_share_a function that establishes a non-zero fixed-point precision.

Parameters:
  • data – The plaintext vector that must be secret-shared among computing parties.

  • data_party – The party that owns the data.

  • fixed_point_precision – precision of the input values

Returns:

The arithmetic shared fixed-point vector

virtual EVector public_share(const Vector &x) = 0

Create a “secret” share of a public value, x. This implemented by setting one share to x and all others to zero; this gives a valid sharing under both arithmetic and boolean.

Parameters:

x – The public vector to share.

Returns:

The shared vector.

inline virtual EVector public_share(const Vector &x, const int fixed_point_precision)

An overloaded public_share function that establishes a non-zero fixed-point precision.

Parameters:
  • x

  • fixed_point_precision

Returns:

EVector

Public Members

Communicator *communicator
random::RandomnessManager *randomnessManager
class ProtocolBase
#include <protocol.h>

Base class for all secure multi-party computation protocols.

Subclassed by orq::Protocol< T, std::vector< T >, Vector< T >, EVector< T, R > >, orq::Protocol< T, S< T >, V< T >, E< T > >, orq::Protocol< Data, Share, Vector, EVector >

Public Functions

inline ProtocolBase(PartyID pID, int partiesNum, int replicationNum)

Constructor for ProtocolBase.

Parameters:
  • pID – Party identifier for this protocol instance.

  • partiesNum – Total number of parties in the protocol.

  • replicationNum – Replication factor for the protocol.

inline virtual ~ProtocolBase()
inline virtual std::vector<std::set<int>> getGroups() const

Get the groups for shuffling operations.

Returns:

Vector of party groups for shuffling.

inline std::vector<std::vector<int>> getPartyShareMappings() const

Get a mapping from parties to share numbers.

Returns:

std::vector<std::vector<int>>

inline std::vector<std::vector<int>> getSharePartyMappings() const

Get a mapping from shares to parties holding that share.

Returns:

Vector mapping share IDs to party lists.

inline int getPartyID() const

Get the party ID for this protocol instance.

Returns:

Party identifier.

inline const int getRepNumber() const

Get the replication number for this protocol.

Returns:

Replication factor.

inline const int getNumParties() const

Get the total number of parties in this protocol.

Returns:

Number of parties.

inline virtual void print_statistics()

Print statistics for this protocol. The default is to do nothing, but protocols may choose to override this function to print operator counts, network statistics, or other information.

inline virtual void mark_statistics()

Mark statistics. This can be used to take relative measurements of a section of code.

inline virtual bool malicious_check(const bool should_abort = true)

Check for malicious behavior (4PC only).

Parameters:

should_abort – Whether to abort the protocol if malicious behavior is detected.

Returns:

True if no malicious behavior is detected, false otherwise.

Public Members

size_t send_calls = 0
size_t recv_calls = 0

Public Static Functions

static inline void generateAllCombinations(std::set<int> set, std::set<int> partial_set, int size, std::vector<std::set<int>> &combinations)

Generates all combinations of a given size of an input size (recursively).

Parameters:
  • set – the set of ints to find combinations of.

  • partial_set – the partially complete combination at any given point in the recursion.

  • size – the size of the combinations to search for, decremented with each recursive call.

  • combinations – a vector of combinations to be filled throughout the algorithm.

static inline std::vector<std::set<int>> generateGroups(int num_parties, int parties_to_reconstruct, int num_adversaries)

Defines the groups for the protocol.

This is a STATIC function to be callable during setup before protocol objects exist.

Parameters:
  • num_parties – The number of parties in the protocol.

  • parties_to_reconstruct – Number of parties needed to reconstruct.

  • num_adversaries – Number of adversarial parties.

Returns:

The vector of groups.

static inline std::vector<std::set<int>> generateRandomnessGroups(int n, int n_reconstruct, int n_adversary)

Generate randomness groups (includes the group of everyone).

Parameters:
  • n – Number of parties.

  • n_reconstruct – Number of parties needed for reconstruction.

  • n_adversary – Number of adversarial parties.

Returns:

Vector of randomness groups.

Protected Attributes

PartyID partyID
const int numParties
const int replicationNumber
std::map<std::set<int>, ReshareAssignment> reshareMap = {}

Map from party-groups to resharing assignment.

reshare will retrieve a list of assignments from this map given the current group, and then each party will execute its respective instructions.

Private Functions

inline void generatePartyShareMappings()

Defines the mapping from rank to the secret shares held by that rank.

Index i in the vector is the set of shares held by rank i. For a replication k, party i holds shares [i, i+1, …, i+k-1]. This function should be called during construction.

inline void generateSharePartyMappings()

Generate a mapping from shares to parties holding that share.

Called during construction to populate the mapping.

inline auto generate_send_assignment(int p, std::set<int> group)

Generate send assignment for resharing shares to other parties.

Parameters:
  • p – Party identifier.

  • group – Set of parties in the resharing group.

Returns:

ReshareAssignment for sending shares.

inline auto generate_recv_assignment(int p, std::set<int> group)

Generate receive assignment for resharing shares from other parties.

Parameters:
  • p – Party identifier.

  • group – Set of parties in the resharing group.

Returns:

ReshareAssignment for receiving shares.

Private Members

std::vector<std::vector<int>> partyShareMap = {}
std::vector<std::vector<int>> sharePartyMap = {}
struct ReshareAssignment
#include <protocol.h>

Assignment for resharing operations.

Defines whether a party sends or receives shares during resharing, along with the target parties and share indices.

Public Members

ReshareAction action
std::vector<int> ranks
std::vector<int> shareIdx
namespace orq
template<template<typename, typename, typename, typename> class Protocol, template<typename> class S, template<typename> class V, template<typename> class E>
class DefaultProtocolFactory : public orq::ProtocolFactory<DefaultProtocolFactory<Protocol, S, V, E>>
#include <protocol_factory.h>

Default protocol factory implementation.

Template Parameters:
  • Protocol – The protocol class template.

  • S – Share type template.

  • VVector type template.

  • EEncoding vector type template.

Public Functions

inline DefaultProtocolFactory(const int &partyID, const int &partiesNumber)

Constructor for DefaultProtocolFactory.

Parameters:
  • partyID – The party identifier.

  • partiesNumber – The total number of parties.

template<typename T>
inline std::unique_ptr<ProtocolBase> create(Communicator *communicator, random::RandomnessManager *randomnessManager)

Create a protocol instance for the given data type.

Template Parameters:

T – The data type for the protocol.

Parameters:
  • communicator – Pointer to the communicator.

  • randomnessManager – Pointer to the randomness manager.

Returns:

Unique pointer to the created protocol instance.

Private Types

template<typename T>
using ProtocolInstance = Protocol<T, S<T>, V<T>, E<T>>

Private Members

const int partyID_
const int partiesNumber_
template<typename InnerFactory>
class ProtocolFactory
#include <protocol_factory.h>

Base factory class for creating protocol instances using CRTP.

Template Parameters:

InnerFactory – The derived factory class.

Subclassed by orq::DefaultProtocolFactory< Beaver_2PC, Share, Vector, EVector >, orq::DefaultProtocolFactory< Fantastic_4PC, Share, Vector, EVector >, orq::DefaultProtocolFactory< Dummy_0PC, Share, Vector, EVector >, orq::DefaultProtocolFactory< Plaintext_1PC, Share, Vector, EVector >, orq::DefaultProtocolFactory< Replicated_3PC, Share, Vector, EVector >

Public Functions

virtual ~ProtocolFactory() = default
template<typename T>
inline std::unique_ptr<ProtocolBase> create(Communicator *_communicator, random::RandomnessManager *_randomnessManager)

Create a protocol instance for the given data type.

Template Parameters:

T – The data type for the protocol.

Parameters:
  • _communicator – Pointer to the communicator.

  • _randomnessManager – Pointer to the randomness manager.

Returns:

Unique pointer to the created protocol instance.