2021SC@SDUSC
PALISADE中离散高斯取样实现的分析专题
- 高斯分布采样原理——拒绝采样法
- PALISADE中的采样方法
- 具体分析PALISADE中的拒绝采样法
PALISADE中的采样法
PALISADE库提供了各种方法从离散的高斯分布采样。这些方法在DiscreteGaussianGenerator
和DiscreteGaussianGeneratorGeneric
类中都实现了,它们有各自的特定用途。所讨论的所有采样器都已在 GLITCH Discrete Gaussian Testing Suite中进行了测试,没有发现任何问题。
DiscreteGaussianGenerator
类是同态加密的主要类,包括拒绝采样(rejection sampling)
、Karney方法
和Peikert's inversion方法
的实现。
-
拒绝采样法:拒绝采样法的实现定义在Trapdoors for Hard Lattices and New Cryptographic Constructions这篇论文中。主要运用在
GenerateInteger(double mean, double stddev, size_t n, const IntType &modulus)
和GenerateInteger(double mean, double stddev, size_t n)
这两个方法中。拒绝抽样可以用于任意的中心和分布参数,不需要任何预先计算。但是,它的拒收率高,容易受到定时攻击。目前在PALISADE中没有任何加密协议使用它。/* 构造一个生成器对象*/ DiscreteGaussianGenerator dggRejection; /* 第一个参数是平均数,第二个参数是分布参数,第三个是环的维数 */ int64_t number = dggRejection.GenerateInteger(0,4,1024);
-
Karney’s Method
:是一种基于拒绝抽样的改进抽样方法。它被用于Generatelntegerkarney
方法中。与拒绝抽样一样,它可以用于任意中心和分布参数,而不需要任何预先计算。它比传统的抽样方法有较小的拒收率,但仍然容易受到定时攻击。/* 构造一个生成器对象*/ DiscreteGaussianGenerator dggKarney; /* 第一个参数是平均数,第二个参数是分布参数 */ int64_t number = dggKarney.GenerateIntegerKarney(0,4);
-
Peikert's Inversion Method
:它要求以单个中心为中心的CDF概率表保存在内存中,这些表是在构造函数中预先计算的。在Generatelnt, GeneratelntVector, GenerateVector和Generatelntegerlconst IntType& modulus)
方法中使用了Peikert’s Inversion Method。这些方法不容易受到定时攻击,但只适用于单中心,单偏差。还应该注意的是,内存需求随着分布参数的增加而增加,因此建议使用较小偏差的分布参数。/* 构造生成器对象 参数是分布参数 */ DiscreteGaussianGenerator dggPeikert(4); /* 生成一个int的采样 */ int64_t number = dggPeikert.GenerateInt();
类Discretegaussiangeneratorgeneric
是由UCSD开发的恒时间泛型采样器,它包含了这种新采样方法的定义和所需的基采样器。是由UCSD开发的恒时间泛型采样器,它包含了这种新采样方法的定义和所需的基采样器。
-
Peikert’s Inversion Method: 该类中的
Peikert's Inversion Method
方法与定义在DiscreteGaussianGenerator类中的方法一致,只用于基采样,它通过调用GenerateInteger
方法,从一个使用“PEIKERT”参数创建的BaseSampler
对象中调用。/* 生成一个位采样器 */ BitGenerator* bg = new BitGenerator(); /* 平均数与参数 */ double std= 4; double mean = 0; /* 生成BaseSample */ BaseSampler peikert_sampler(mean,std,bg,PEIKERT); /* 随机采样 */ int64_t number = peikert_sampler.GenerateInteger();
-
Knuth-Yao Sampling: 该方法的原理来自于 Sampling from discrete Gaussians for lattice-based cryptography on a constrained device论文中。它需要在构造函数中计算概率矩阵,然后计算离散分布生成树,为了使用这个方法,需要通过调用
GenerateInteger
方法,从一个使用“KNUTH_YAO”参数创建的BaseSampler对象中调用它。 就像Peikert's Inversion Method
一样,它只适用于单中心、单偏差,而内存需求与分布参数成正比。BitGenerator* bg = new BitGenerator(); /* 平均数与分布参数 */ double std= 4; double mean = 0; /* 用“KNUTH_YAO”参数创建的BaseSampler对象 */ BaseSampler ky_sampler(mean,std,bg,KNUTH_YAO); /* 随机采样 */ int64_t number = ky_sampler.GenerateInteger();
-
Generic Constant Time Sampling: 加州大学圣地亚哥分校研究的新的采样法Gaussian Sampling over the Integers: Efficient, Generic, Constant-Time. 它结合了一套以各种平均值为中心的基础采样器和一个单一的分布参数,以从任意中心和分布参数进行采样。 在头文件中详细讨论了参数的选择,但通常采样器需要一组作为参数给出的基本采样器和很少的预计算,这是在构造阶段处理。 这个方法可以通过创建一个离散
gaussiangeneratorgeneric
对象并调用GenerateInteger
方法来调用。 它不容易受到定时攻击。
运行PALISADE库bin/examples/core/sampling的程序的结果如图: