SEAL开源库源码01
文章目录
- SEAL开源库源码01
- seal/util/defines.h
-
- 通用的判断函数
- 将x输出为字符串
- 字符串的拼接
- 检查double类型是否是64比特
- 检查int是否为32比特
- 检查unsigned long long 是否为64比特
- 多项式系数模数的上下界
- 内部使用的系数模长
- 用户定义的系数模长的上下界
- 明文模长的上下界
- 系数模数数量的上下界(没有硬性的要求)
- 多项式模的次数 (模一个多项式,指的是这个多项式的次数)
- 密文大小的上界
- How many pairs of modular integers can we multiply and accumulate in a 128-bit data type (?)
- 操作系统标识,检测操作系统
- 检测编译器
- 根据是否为debug 模式,产生true/false 值
- byte类型
- 将SEAL_FORCE_INLINE 作为inline的别名
- C++17 'if constexpr'
- C++17 [[maybe_unused]]
- C++17 [[nodiscard]]
- std::for_each_n
- 分配内存
- 释放指针
- 使用哪个随机数生成器
- 使用哪个误差分布
- 使用通用的加减乘除
- 类型检查
- 返回一些迭代器的宏
- 根据cond选择
- define.h到此结束,其中有两个未在这个文件中定义的量,分别是 **SEAL_INTERNAL_MOD_BIT_COUNT_MAX** 和 **SIZE_MAX**。
seal/util/defines.h
这个头文件没有相应的cpp文件,定义了一些其他文件中需要用到的基本的东西
通用的判断函数
// Debugging help
#define SEAL_ASSERT(condition) \
{
\
if (!(condition)) \
{
\
std::cerr << "ASSERT FAILED: " << #condition << " @ " << __FILE__ << " (" << __LINE__ << ")" << std::endl; \
} \
}
将x输出为字符串
一个井号和两个井号的意思:一个井号将x转换为字符串,两个井号为字符串的拼接
井号和两个井号
// String expansion
#define _SEAL_STRINGIZE(x) #x
#define SEAL_STRINGIZE(x) _SEAL_STRINGIZE(x)
字符串的拼接
// Join
#define _SEAL_JOIN(M, N) M##N
#define SEAL_JOIN(M, N) _SEAL_JOIN(M, N)
检查double类型是否是64比特
// Check that double is 64 bits
static_assert(sizeof(double) == 8, "Require sizeof(double) == 8");
检查int是否为32比特
// Check that int is 32 bits
static_assert(sizeof(int) == 4, "Require sizeof(int) == 4");
检查unsigned long long 是否为64比特
// Check that unsigned long long is 64 bits
static_assert(sizeof(unsigned long long) == 8, "Require sizeof(unsigned long long) == 8");
多项式系数模数的上下界
上界为61比特,下界为2比特
// Bounds for bit-length of all coefficient moduli
#define SEAL_MOD_BIT_COUNT_MAX 61
#define SEAL_MOD_BIT_COUNT_MIN 2
内部使用的系数模长
似乎是定长的61比特
// Bit-length of internally used coefficient moduli, e.g., auxiliary base in BFV
#define SEAL_INTERNAL_MOD_BIT_COUNT 61
用户定义的系数模长的上下界
上界60比特,下界2比特
// Bounds for bit-length of user-defined coefficient moduli
#define SEAL_USER_MOD_BIT_COUNT_MAX 60
#define SEAL_USER_MOD_BIT_COUNT_MIN 2
明文模长的上下界
跟用户定义的模长的上下界相同,上界60比特,下界2比特
// Bounds for bit-length of the plaintext modulus
#define SEAL_PLAIN_MOD_BIT_COUNT_MAX SEAL_USER_MOD_BIT_COUNT_MAX
#define SEAL_PLAIN_MOD_BIT_COUNT_MIN SEAL_USER_MOD_BIT_COUNT_MIN
系数模数数量的上下界(没有硬性的要求)
上界为64个,下界为1个
// Bounds for number of coefficient moduli (no hard requirement)
#define SEAL_COEFF_MOD_COUNT_MAX 64
#define SEAL_COEFF_MOD_COUNT_MIN 1
多项式模的次数 (模一个多项式,指的是这个多项式的次数)
上界为131072 = 2 17 2^{17} 217,下界为2
// Bounds for polynomial modulus degree (no hard requirement)
#define SEAL_POLY_MOD_DEGREE_MAX 131072
#define SEAL_POLY_MOD_DEGREE_MIN 2
密文大小的上界
不能超过 2 32 2^{32} 232除以多项式模的degree上界,即 2 32 / 2 17 = 2 15 = 32768 2^{32}/2^{17} = 2^{15} = 32768 232/217=215