myl7/fss 2.0.0
Function secret sharing (FSS) primitives including distributed point/comparison function (DPF/DCF)
Loading...
Searching...
No Matches
fss::Dpf< in_bits, Group, Prg, In > Class Template Reference

2-party DPF scheme. More...

Classes

struct  Cw
 Correction word. More...
struct  Key
 One party's key in the aggregate Cw layout: the correction words plus the party's initial seed. More...

Public Types

using Input = In
 The caller-facing input-domain type.

Public Member Functions

 Dpf (Prg prg)
 Configure the pseudorandom generator.
void Gen (cuda::std::span< int4 > cws, In &tr, cuda::std::span< const int4, 2 > s0s, In a, int4 b_buf, size_t stride=1)
 Generate correction words in a caller-strided layout and packed control bits.
int4 Eval (bool b, int4 s0, cuda::std::span< const int4 > cws, In tr, In x, size_t stride=1)
 Evaluate one point using separate correction components.
void EvalRange (bool b, In first, In last, int4 s0, cuda::std::span< const int4 > cws, In tr, cuda::std::span< int4 > ys, int par_depth=0, size_t stride=1)
 Evaluate the closed input interval [first, last] on the host from split correction words.
void EvalAll (bool b, int4 s0, cuda::std::span< const int4 > cws, In tr, int4 ys[], int par_depth=0, size_t stride=1)
 Evaluate the full domain on the host from split correction words.
template<int frontier_depth = 16, int threads_per_block = 256>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
cudaError_t EvalRangeGpu (bool b, In first, In last, int4 s0, cuda::std::span< const int4 > cws, In tr, cuda::std::span< int4 > ys, cudaStream_t stream=0, size_t stride=1) const
 Evaluate the closed interval [first, last] on the given CUDA stream from split arrays.
template<int frontier_depth = 16, int threads_per_block = 256>
requires (in_bits < sizeof(size_t) * 8)
cudaError_t EvalAllGpu (bool b, int4 s0, cuda::std::span< const int4 > cws, In tr, cuda::std::span< int4 > ys, cudaStream_t stream=0, size_t stride=1) const
 Launch full-domain CUDA evaluation from split device arrays.
template<int frontier_depth = 16, int threads_per_block = 256>
requires (in_bits < sizeof(size_t) * 8)
cudaError_t EvalAllGpuBatch (bool b, cuda::std::span< const int4 > s0s, cuda::std::span< const int4 > cws, cuda::std::span< const In > tr, cuda::std::span< int4 > ys, cudaStream_t stream=0, size_t stride=0) const
 Launch full-domain CUDA evaluation for s0s.size() keys from split device arrays.

Static Public Attributes

static constexpr int kCwCount = in_bits + 1
 Seed-component count Gen() writes at stride 1: in_bits layers plus the terminal.

Detailed Description

template<int in_bits, typename Group, typename Prg, typename In = uint>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
class fss::Dpf< in_bits, Group, Prg, In >

2-party DPF scheme.

Template Parameters
in_bitsInput domain bit size.
GroupType for the output domain. See Groupable.
PrgSee Prgable.
InType for the input domain. From uint8_t to __uint128_t.

Gen() and scalar Eval() are callable from host and device when the backend supports the execution space and all accessed storage is accessible there. EvalRange() and EvalAll() are host operations. EvalAllGpu() and EvalAllGpuBatch() are host launch methods compiled with a CUDA compiler; they do not run on the device.

Constructor & Destructor Documentation

◆ Dpf()

template<int in_bits, typename Group, typename Prg, typename In>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
fss::Dpf< in_bits, Group, Prg, In >::Dpf ( Prg prg)
inlineexplicit

Configure the pseudorandom generator.

Parameters
prgBackend used throughout generation and evaluation.

Member Function Documentation

◆ Eval()

template<int in_bits, typename Group, typename Prg, typename In>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
int4 fss::Dpf< in_bits, Group, Prg, In >::Eval ( bool b,
int4 s0,
cuda::std::span< const int4 > cws,
In tr,
In x,
size_t stride = 1 )
inline

Evaluate one point using separate correction components.

Root-order packed bit i is the right-control correction at layer i. The correction s LSB is the left-control correction. Layer i is read from cws[i*stride] and the terminal from cws[in_bits*stride], which Gen() writes as a plain int4 with its LSB zero. Packed bits at and above in_bits are ignored.

Parameters
bParty index, false for party 0 and true for party 1.
s0This party's seed from generation.
cwsCorrection words, layer i at index i*stride and the terminal at index in_bits*stride.
trPacked right-control bits, bit i for layer i.
xQuery point.
stridePositive stride between correction entries.
Returns
This party's output share.
Precondition
x is in [0, 2^in_bits).
stride > 0.
With M = numeric_limits<size_t>::max()/sizeof(int4), stride <= (M-1)/in_bits and cws has at least in_bits*stride+1 elements.
cws[in_bits*stride].w & 1 == 0.
All accessed storage is accessible from the calling execution space.
A stride, capacity, or terminal violation aborts with a diagnostic in Debug builds on both the host and the device, and is undefined behavior in Release builds.

◆ EvalAll()

template<int in_bits, typename Group, typename Prg, typename In>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
void fss::Dpf< in_bits, Group, Prg, In >::EvalAll ( bool b,
int4 s0,
cuda::std::span< const int4 > cws,
In tr,
int4 ys[],
int par_depth = 0,
size_t stride = 1 )
inline

Evaluate the full domain on the host from split correction words.

Layer i is read from cws[i*stride] and the terminal from cws[in_bits*stride]. Packed bit i of tr is the right-control correction at layer i, and the left-control correction is the LSB of the layer's cws entry, exactly as the component form of Gen() writes them. Bits of tr at and above in_bits are ignored. par_depth controls OpenMP partitioning for this call.

Parameters
bParty index, false for party 0 and true for party 1.
s0This party's seed from generation.
cwsCorrection words, layer i at index i*stride and the terminal at index in_bits*stride.
trPacked right-control bits, bit i for layer i.
ysOutput array of at least 2^in_bits elements.
par_depthNonnegative OpenMP split depth for this call. Zero runs sequentially. Positive depths require backends that support concurrent calls.
stridePositive element stride between correction-word entries.
Precondition
The output element count and byte size fit size_t.
stride > 0.
With M = numeric_limits<size_t>::max()/sizeof(int4), stride <= (M-1)/in_bits and cws has at least in_bits*stride+1 elements.
cws[in_bits*stride].w & 1 == 0. A violation aborts with a diagnostic in Debug builds and is undefined behavior in Release builds.
Exceptions
std::invalid_argumentif stride is zero or too large or cws is shorter than in_bits*stride+1.
Postcondition
ys[x] contains this party's output share for x.

◆ EvalAllGpu()

template<int in_bits, typename Group, typename Prg, typename In>
requires (in_bits < sizeof(size_t) * 8)
template<int frontier_depth, int threads_per_block>
requires (in_bits < sizeof(size_t) * 8)
cudaError_t fss::Dpf< in_bits, Group, Prg, In >::EvalAllGpu ( bool b,
int4 s0,
cuda::std::span< const int4 > cws,
In tr,
cuda::std::span< int4 > ys,
cudaStream_t stream = 0,
size_t stride = 1 ) const
inline

Launch full-domain CUDA evaluation from split device arrays.

Layer i is read from cws[i*stride] and the terminal from cws[in_bits*stride]. Packed bit i of tr is the right-control correction at layer i, and the left-control correction is the LSB of the layer's cws entry, exactly as the component form of Gen() writes them. Bits of tr at and above in_bits are ignored. Backend values, resource rules and tuning rules match EvalAllGpu().

Parameters
bParty index, false for party 0 and true for party 1.
s0This party's seed, passed by value as a kernel argument.
cwsDevice correction words, layer i at index i*stride and the terminal at index in_bits*stride.
trPacked right-control bits, bit i for layer i.
ysDevice output storage containing at least 2^in_bits blocks.
streamStream on the device owning the referenced resources.
stridePositive element stride between correction-word entries.
Precondition
stride > 0 and cws holds at least in_bits*stride+1 elements.
The buffers and referenced backend resources remain valid until work completes.
Returns
Immediate CUDA status. Invalid dimensions, buffers, strides, null used buffers, or unaddressable sizes return cudaErrorInvalidValue. Execution completion remains asynchronous.

◆ EvalAllGpuBatch()

template<int in_bits, typename Group, typename Prg, typename In>
requires (in_bits < sizeof(size_t) * 8)
template<int frontier_depth, int threads_per_block>
requires (in_bits < sizeof(size_t) * 8)
cudaError_t fss::Dpf< in_bits, Group, Prg, In >::EvalAllGpuBatch ( bool b,
cuda::std::span< const int4 > s0s,
cuda::std::span< const int4 > cws,
cuda::std::span< const In > tr,
cuda::std::span< int4 > ys,
cudaStream_t stream = 0,
size_t stride = 0 ) const
inline

Launch full-domain CUDA evaluation for s0s.size() keys from split device arrays.

The batch uses the level-major layout: key k layer i is read from cws[i*stride + k], key k's packed control is tr[k], and key k's terminal is cws[in_bits*stride + k]. Packed bit i of tr[k] is the right-control correction at layer i, and the left-control correction is the LSB of the layer's cws entry, exactly as the split form of Gen() writes them. Bits of tr[k] at and above in_bits are ignored. stride selects the layout. 0 selects the dense level-major layout, in which the stride is the key count of this call. Any other value is a positive stride of at least s0s.size(). Uses the same resource, execution, and tuning rules as EvalAllGpu(). All keys share this scheme's backend configuration, and every key produces the whole domain.

Parameters
bParty index shared by the batch.
s0sDevice storage containing this party's seed for each key.
cwsDevice level-major correction words.
trDevice packed right-control bits, one value per key.
ysDevice key-major rows of 2^in_bits output blocks per key.
streamStream on the device owning the referenced resources.
stride0 for the dense level-major layout, where the stride is the key count of this call, or a positive element stride >= s0s.size().
Precondition
stride is 0 or at least s0s.size().
cws holds at least in_bits*stride + s0s.size() elements, where a stride of 0 counts as s0s.size(), and tr holds at least s0s.size() values.
The buffers and referenced backend resources remain valid until work completes.
Returns
Immediate CUDA status. An empty batch succeeds without reading buffers. Invalid dimensions, null used buffers, strides, or unaddressable sizes return cudaErrorInvalidValue; an oversized grid returns cudaErrorInvalidConfiguration. Execution completion remains asynchronous.

◆ EvalRange()

template<int in_bits, typename Group, typename Prg, typename In>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
void fss::Dpf< in_bits, Group, Prg, In >::EvalRange ( bool b,
In first,
In last,
int4 s0,
cuda::std::span< const int4 > cws,
In tr,
cuda::std::span< int4 > ys,
int par_depth = 0,
size_t stride = 1 )
inline

Evaluate the closed input interval [first, last] on the host from split correction words.

Layer i is read from cws[i*stride] and the terminal from cws[in_bits*stride]. Packed bit i of tr is the right-control correction at layer i, and the left-control correction is the LSB of the layer's cws entry, exactly as the component form of Gen() writes them. Bits of tr at and above in_bits are ignored.

Parameters
bParty index, false for party 0 and true for party 1.
firstFirst input in the interval.
lastLast input in the interval, included in the output.
s0This party's seed from generation.
cwsCorrection words, layer i at index i*stride and the terminal at index in_bits*stride.
trPacked right-control bits, bit i for layer i.
ysOutput storage with at least last-first+1 elements.
par_depthNonnegative OpenMP split depth for this call. Zero runs sequentially. Positive depths require backends that support concurrent calls.
stridePositive element stride between correction-word entries.
Precondition
first <= last and both endpoints are in [0, 2^in_bits).
stride > 0.
With M = numeric_limits<size_t>::max()/sizeof(int4), stride <= (M-1)/in_bits and cws has at least in_bits*stride+1 elements.
cws[in_bits*stride].w & 1 == 0. A violation aborts with a diagnostic in Debug builds and is undefined behavior in Release builds.
cws and ys.data() are nonnull and refer to accessible host storage.
Exceptions
std::invalid_argumentif first > last, an endpoint is outside the input domain, the interval does not fit size_t, ys is too short, stride is zero or too large, or cws is shorter than in_bits*stride+1.
Postcondition
ys[x-first] contains this party's output share for each x in the interval. Any extra elements of ys remain unchanged.

◆ EvalRangeGpu()

template<int in_bits, typename Group, typename Prg, typename In>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
template<int frontier_depth, int threads_per_block>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
cudaError_t fss::Dpf< in_bits, Group, Prg, In >::EvalRangeGpu ( bool b,
In first,
In last,
int4 s0,
cuda::std::span< const int4 > cws,
In tr,
cuda::std::span< int4 > ys,
cudaStream_t stream = 0,
size_t stride = 1 ) const
inline

Evaluate the closed interval [first, last] on the given CUDA stream from split arrays.

Output ys[j] corresponds to first+j. Extra output capacity is unchanged.

Layer i is read from cws[i*stride] and the terminal from cws[in_bits*stride]. Packed bit i of tr is the right-control correction at layer i, and the left-control correction is the LSB of the layer's cws entry, exactly as the component form of Gen() writes them. Bits of tr at and above in_bits are ignored. Resources, subdivision and asynchronous error handling follow EvalRangeGpu().

Parameters
bParty index, false for party 0 and true for party 1.
firstFirst input in the interval.
lastLast input in the interval, included in the output.
s0This party's seed, passed by value as a kernel argument.
cwsDevice correction words, layer i at index i*stride and the terminal at index in_bits*stride.
trPacked right-control bits, bit i for layer i.
ysDevice output storage. Entry x-first receives this party's share at x.
streamStream on the device owning the referenced resources.
stridePositive element stride between correction-word entries.
Precondition
stride > 0 and cws holds at least in_bits*stride+1 elements.
The buffers and referenced backend resources remain valid until work completes.
Returns
Immediate CUDA status. Invalid endpoints, buffers, strides, counts or byte sizes return cudaErrorInvalidValue. Execution completion remains asynchronous. The grid limit cannot be exceeded, because the subdivision caps the block-root depth at 30.

◆ Gen()

template<int in_bits, typename Group, typename Prg, typename In>
requires (ValidForInputBits<In, in_bits> && Groupable<Group> && Prgable<Prg, 2>)
void fss::Dpf< in_bits, Group, Prg, In >::Gen ( cuda::std::span< int4 > cws,
In & tr,
cuda::std::span< const int4, 2 > s0s,
In a,
int4 b_buf,
size_t stride = 1 )
inline

Generate correction words in a caller-strided layout and packed control bits.

Layer i is stored at cws[i*stride] and the terminal at cws[in_bits*stride]. tr receives root-order packed right-control bits: bit 0 is the root layer, bit i belongs to layer i, and bits at or above in_bits are zero. The terminal is stored unchanged as a plain int4. The default stride of 1 stores the correction words contiguously.

Parameters
cwsOutput storage; its capacity includes in_bits*stride+1 elements.
trOutput packed right-control bits, with unused bits zero.
s0sTwo initial seeds, retained by the caller.
aThe secret point.
b_bufOutput value, clamped before conversion to Group.
stridePositive element stride between correction-word entries.
Precondition
a is in [0, 2^in_bits).
stride > 0.
With M = numeric_limits<size_t>::max()/sizeof(int4), stride <= (M-1)/in_bits and cws has at least in_bits*stride+1 elements.
Inputs and outputs do not overlap.
All accessed storage is accessible from the calling execution space.
A stride or capacity violation aborts with a diagnostic in Debug builds on both the host and the device, and is undefined behavior in Release builds.
Postcondition
Only the described prefix is written, and storage beyond it is untouched.

The documentation for this class was generated from the following file: