myl7/fss 2.0.0
Function secret sharing (FSS) primitives including distributed point/comparison function (DPF/DCF)
Loading...
Searching...
No Matches
prg.cuh
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
7
8#pragma once
9#include <cuda_runtime.h>
10#include <cuda/std/array>
11#include <concepts>
12#include <cuda/std/span>
13
23template <typename Prg, int mul>
24concept Prgable = requires(Prg prg, int4 seed) {
25 { prg.Gen(seed) } -> std::same_as<cuda::std::array<int4, mul>>;
26};
27
41template <typename Prg, int mul>
42concept HasGenHalf = mul > 0 && mul % 2 == 0 && Prgable<Prg, mul> && requires(Prg prg, int4 seed, bool right) {
43 { prg.GenHalf(seed, right) } -> std::same_as<cuda::std::array<int4, mul / 2>>;
44};
45
81template <typename Prg, int mul>
82concept HasGen8 = Prgable<Prg, mul> && requires(Prg prg, cuda::std::span<const int4, 8> seeds) {
83 { prg.Gen8(seeds) } -> std::same_as<cuda::std::array<cuda::std::array<int4, mul>, 8>>;
84};
85
86// -----------------------------------------------------------------------------
87
88namespace fss::detail {
89
90template <int mul, typename Prg>
91 requires(mul > 0 && mul % 2 == 0 && Prgable<Prg, mul>)
92__host__ __device__ inline cuda::std::array<int4, mul / 2> GenHalf(Prg &prg, int4 seed, bool right) {
93 if constexpr (HasGenHalf<Prg, mul>) {
94 return prg.GenHalf(seed, right);
95 } else {
96 auto full = prg.Gen(seed);
97 cuda::std::array<int4, mul / 2> out{};
98 int offset = right ? mul / 2 : 0;
99 for (int i = 0; i < mul / 2; ++i) out[i] = full[i + offset];
100 return out;
101 }
102}
103
104// Keep the optional batched entry point outside the public PRG requirement.
105template <int mul, typename Prg>
106cuda::std::array<cuda::std::array<int4, mul>, 8> GenBatch(Prg &prg, cuda::std::span<const int4, 8> seeds) {
107 if constexpr (HasGen8<Prg, mul>) {
108 return prg.Gen8(seeds);
109 } else {
110 cuda::std::array<cuda::std::array<int4, mul>, 8> out{};
111 for (int j = 0; j < 8; ++j) out[j] = prg.Gen(seeds[j]);
112 return out;
113 }
114}
115
116} // namespace fss::detail
Optional eight-seed batch extension of Prgable.
Definition prg.cuh:82
Optional selected-half extension of Prgable for positive even mul.
Definition prg.cuh:42
Pseudorandom generator (PRG) interface.
Definition prg.cuh:24