// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
#include "seal/util/common.h"
#include "seal/util/defines.h"
#include "seal/util/pointer.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
namespace seal
{
class Ciphertext;
namespace util
{
class NTTTables;
/**
@par PolyIter, RNSIter, and CoeffIter
In this file we define a set of custom iterator classes ("SEAL iterators") that are used throughout Microsoft
SEAL for easier iteration over ciphertext polynomials, their RNS components, and the coefficients in the RNS
components. All SEAL iterators satisfy the C++ LegacyRandomAccessIterator requirements. SEAL iterators are ideal
to use with the SEAL_ITERATE macro, which expands to std::for_each_n in C++17 and to seal::util::seal_for_each_n
in C++14. All SEAL iterators derive from SEALIterBase.
The most important SEAL iterator classes behave as illustrated by the following diagram:
+-------------------+
| Pointer & Size | Construct +-----------------+
| or Ciphertext |------------>| (Const)PolyIter | Iterates over RNS polynomials in a ciphertext
+-------------------+ +--------+--------+ (coeff_modulus_size-many RNS components)
|
|
| Dereference
|
|
v
+----------------+ Construct +----------------+
| Pointer & Size |------------->| (Const)RNSIter | Iterates over RNS components in an RNS polynomial
+----------------+ +-------+--------+ (poly_modulus_degree-many coefficients)
|
|
| Dereference
|
|
v
+----------------+ Construct +------------------+
| Pointer & Size |------------>| (Const)CoeffIter | Iterates over coefficients (std::uint64_t) in a single
+----------------+ +---------+--------+ RNS polynomial component
|
|
| Dereference
|
|
v
+-------------------------+
| (const) std::uint64_t & |
+-------------------------+
@par PtrIter and StrideIter
PtrIter<T *> and StrideIter<T *> are both templated SEAL iterators that wrap raw pointers. The difference
between these two types is that advancing PtrIter<T *> always advances the wrapped pointer by one, whereas the
step size (stride) can be set to be anything for a StrideIter<T *>. CoeffIter is a typedef of
PtrIter<std::uint64_t *> and and RNSIter is almost the same as StrideIter<std::uint64_t *>, but still a
different type.
+----------+ Construct +-------------------+
| MyType * |------------->| PtrIter<MyType *> | Simple wrapper for raw pointers
+----------+ +----+----------+---+
| |
| |
Dereference | | PtrIter<MyType *>::ptr()
| | or implicit conversion
| |
v v
+----------+ +----------+
| MyType & | | MyType * |
+----------+ +----------+
+----------+ Construct +----------------------+
| MyType * |------------->| StrideIter<MyType *> | Simple wrapper for raw pointers with custom stride size
+----------+ +-----+----------+-----+
| |
| |
Dereference | | StrideIter<MyType *>::ptr()
| | or implicit conversion
| |
v v
+----------+ +----------+
| MyType & | | MyType * |
+----------+ +----------+
@par IterTuple
An extremely useful template class is the (variadic) IterTuple<...> that allows multiple SEAL iterators to be
zipped together. An IterTuple is itself a SEAL iterator and nested IterTuple types are used commonly in the
library. Dereferencing an IterTuple always yields an std::tuple, with each IterTuple element dereferenced.
Since an IterTuple can be constructed from an std::tuple holding the respective single-parameter constructor
arguments for each iterator, the dereferenced std::tuple can often be directly passed on to functions expecting
an IterTuple.
The individual components of an IterTuple can be accessed with the seal::util::get<i>(...) functions. The
behavior of IterTuple is summarized in the following diagram:
+-----------------------------------------+
| IterTuple<PolyIter, RNSIter, CoeffIter> |
+--------------------+--------------------+
|
|
| Dereference
|
|
v
+--------------------------------------------------+
| std::tuple<RNSIter, CoeffIter, std::uint64_t &>> |
+------+-------------------+-------------------+---+
| | |
| | |
| std::get<0> | std::get<1> | std::get<2>
| | |
| | |
v v v
+-------------+ +---------------+ +-----------------+
| RNSIter | | CoeffIter | | std::uint64_t & |
+-------------+ +---------------+ +-----------------+
Sometimes we have to use multiple nested iterator tuples. In this case accessing the nested iterators can be
tedious with nested get<...> calls. Consider the following, where encrypted1 and encrypted2 are Ciphertexts
and destination is either a Ciphertext or a PolyIter:
IterTuple<PolyIter, PolyIter> I(encrypted1, encrypted2);
IterTuple<decltype(I), PolyIter> J(I, destination);
auto encrypted1_iter = get<0>(get<0>(J));
auto encrypted2_iter = get<1>(get<0>(J));
An easier way is to use another form of get<...> that accepts multiple indices and accesses the structure in a
nested manner. For example, in the above we could also write:
auto encrypted1_iter = get<0, 0>(J));
auto encr
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SEAL-4.1-x64-windows.zip (78个子文件)
SEAL-4.1
include
SEAL-4.1
seal
relinkeys.h 4KB
valcheck.h 16KB
memorymanager.h 27KB
kswitchkeys.h 13KB
serializable.h 5KB
secretkey.h 11KB
evaluator.h 78KB
context.h 26KB
randomtostd.h 2KB
decryptor.h 6KB
ciphertext.h 28KB
modulus.h 20KB
plaintext.h 32KB
ckks.h 34KB
version.h 1KB
serialization.h 15KB
keygenerator.h 16KB
randomgen.h 21KB
dynarray.h 26KB
encryptor.h 19KB
publickey.h 10KB
util
uintarithsmallmod.h 16KB
numth.h 5KB
hestdparms.h 4KB
globals.h 3KB
fips202.h 314B
iterator.h 81KB
polyarithsmallmod.h 29KB
locks.h 8KB
dwthandler.h 16KB
clipnormal.h 2KB
mempool.h 9KB
defines.h 13KB
uintarithmod.h 8KB
rlwe.h 5KB
blake2.h 7KB
rns.h 12KB
pointer.h 40KB
config.h 1KB
uintarith.h 35KB
common.h 22KB
streambuf.h 5KB
ztools.h 3KB
gcc.h 4KB
msvc.h 2KB
hash.h 1KB
blake2-impl.h 4KB
ntt.h 11KB
scalingvariant.h 958B
clang.h 4KB
croots.h 926B
galois.h 6KB
polycore.h 6KB
uintcore.h 18KB
galoiskeys.h 3KB
encryptionparams.h 20KB
batchencoder.h 13KB
seal.h 770B
gsl
gsl_byte 130B
pointers 10KB
string_span 31KB
assert 4KB
gsl_narrow 136B
span_ext 6KB
gsl 1KB
span 30KB
gsl_algorithm 235B
algorithm 2KB
gsl_assert 136B
gsl_util 130B
util 5KB
byte 7KB
narrow 3KB
lib
cmake
SEAL-4.1
SEALTargets-debug.cmake 836B
SEALTargets.cmake 4KB
SEALConfigVersion.cmake 4KB
SEALConfig.cmake 6KB
seal-4.1.lib 31MB
共 78 条
- 1
资源评论
azh-1415926
- 粉丝: 17
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功