Switched to dynamic sampling of baseconverter primes

This commit is contained in:
Kim Laine 2020-01-27 22:21:56 -08:00
Родитель 9b94db7ea7
Коммит f8b9977bdb
3 изменённых файлов: 15 добавлений и 66 удалений

Просмотреть файл

@ -15,6 +15,7 @@
#include "seal/util/polyarithsmallmod.h"
#include "seal/util/smallntt.h"
#include "seal/util/globals.h"
#include "seal/util/numth.h"
#include "seal/smallmodulus.h"
using namespace std;
@ -57,9 +58,6 @@ namespace seal
*/
reset();
m_sk_ = global_variables::internal_mods::m_sk;
m_tilde_ = global_variables::internal_mods::m_tilde;
gamma_ = global_variables::internal_mods::gamma;
small_plain_mod_ = small_plain_mod;
coeff_count_ = coeff_count;
coeff_base_mod_count_ = coeff_base.size();
@ -97,6 +95,18 @@ namespace seal
throw logic_error("invalid parameters");
}
// Sample auxiliary primes; the aux base has size aux_base_mod_count_ and
// we need two more primes: one for m_sk and one for gamma.
auto baseconv_primes = get_primes(
coeff_count_,
SEAL_USER_MOD_BIT_COUNT_MAX + 1,
aux_base_mod_count_ + 2);
auto baseconv_primes_iter = baseconv_primes.cbegin();
m_sk_ = *baseconv_primes_iter++;
gamma_ = *baseconv_primes_iter++;
m_tilde_ = uint64_t(1) << 32;
// We use a reversed order here for performance reasons
coeff_base_products_mod_aux_bsk_array_ =
allocate<Pointer<std::uint64_t>>(bsk_base_mod_count_, pool_);
@ -126,8 +136,7 @@ namespace seal
bsk_base_array_ = allocate<SmallModulus>(bsk_base_mod_count_, pool_);
copy(coeff_base.cbegin(), coeff_base.cend(), coeff_base_array_.get());
copy_n(global_variables::internal_mods::aux_small_mods.cbegin(),
aux_base_mod_count_, aux_base_array_.get());
copy_n(baseconv_primes_iter, aux_base_mod_count_, aux_base_array_.get());
copy_n(aux_base_array_.get(), aux_base_mod_count_, bsk_base_array_.get());
bsk_base_array_[bsk_base_mod_count_ - 1] = m_sk_;

Просмотреть файл

@ -205,50 +205,6 @@ namespace seal
0x1fffffffb90001, 0x1fffffffb60001, 0x1fffffffa50001
} }
};
namespace internal_mods
{
const SmallModulus m_sk(0x1fffffffffe00001);
const SmallModulus m_tilde(uint64_t(1) << 32);
const SmallModulus gamma(0x1fffffffffc80001);
const vector<SmallModulus> aux_small_mods{
0x1fffffffffb40001, 0x1fffffffff500001, 0x1fffffffff380001, 0x1fffffffff000001,
0x1ffffffffef00001, 0x1ffffffffee80001, 0x1ffffffffeb40001, 0x1ffffffffe780001,
0x1ffffffffe600001, 0x1ffffffffe4c0001, 0x1ffffffffdf40001, 0x1ffffffffdac0001,
0x1ffffffffda40001, 0x1ffffffffc680001, 0x1ffffffffc000001, 0x1ffffffffb880001,
0x1ffffffffb7c0001, 0x1ffffffffb300001, 0x1ffffffffb1c0001, 0x1ffffffffadc0001,
0x1ffffffffa400001, 0x1ffffffffa140001, 0x1ffffffff9d80001, 0x1ffffffff9140001,
0x1ffffffff8ac0001, 0x1ffffffff8a80001, 0x1ffffffff81c0001, 0x1ffffffff7800001,
0x1ffffffff7680001, 0x1ffffffff7080001, 0x1ffffffff6c80001, 0x1ffffffff6140001,
0x1ffffffff5f40001, 0x1ffffffff5700001, 0x1ffffffff4bc0001, 0x1ffffffff4380001,
0x1ffffffff3240001, 0x1ffffffff2dc0001, 0x1ffffffff1a40001, 0x1ffffffff11c0001,
0x1ffffffff0fc0001, 0x1ffffffff0d80001, 0x1ffffffff0c80001, 0x1ffffffff08c0001,
0x1fffffffefd00001, 0x1fffffffef9c0001, 0x1fffffffef600001, 0x1fffffffeef40001,
0x1fffffffeed40001, 0x1fffffffeed00001, 0x1fffffffeebc0001, 0x1fffffffed540001,
0x1fffffffed440001, 0x1fffffffed2c0001, 0x1fffffffed200001, 0x1fffffffec940001,
0x1fffffffec6c0001, 0x1fffffffebe80001, 0x1fffffffebac0001, 0x1fffffffeba40001,
0x1fffffffeb4c0001, 0x1fffffffeb280001, 0x1fffffffea780001, 0x1fffffffea440001,
0x1fffffffe9f40001, 0x1fffffffe97c0001, 0x1fffffffe9300001, 0x1fffffffe8d00001,
0x1fffffffe8400001, 0x1fffffffe7cc0001, 0x1fffffffe7bc0001, 0x1fffffffe7a80001,
0x1fffffffe7600001, 0x1fffffffe7500001, 0x1fffffffe6fc0001, 0x1fffffffe6d80001,
0x1fffffffe6ac0001, 0x1fffffffe6000001, 0x1fffffffe5d40001, 0x1fffffffe5a00001,
0x1fffffffe5940001, 0x1fffffffe54c0001, 0x1fffffffe5340001, 0x1fffffffe4bc0001,
0x1fffffffe4a40001, 0x1fffffffe3fc0001, 0x1fffffffe3540001, 0x1fffffffe2b00001,
0x1fffffffe2680001, 0x1fffffffe0480001, 0x1fffffffe00c0001, 0x1fffffffdfd00001,
0x1fffffffdfc40001, 0x1fffffffdf700001, 0x1fffffffdf340001, 0x1fffffffdef80001,
0x1fffffffdea80001, 0x1fffffffde680001, 0x1fffffffde000001, 0x1fffffffdde40001,
0x1fffffffddd80001, 0x1fffffffddd00001, 0x1fffffffddb40001, 0x1fffffffdd780001,
0x1fffffffdd4c0001, 0x1fffffffdcb80001, 0x1fffffffdca40001, 0x1fffffffdc380001,
0x1fffffffdc040001, 0x1fffffffdbb40001, 0x1fffffffdba80001, 0x1fffffffdb9c0001,
0x1fffffffdb740001, 0x1fffffffdb380001, 0x1fffffffda600001, 0x1fffffffda340001,
0x1fffffffda180001, 0x1fffffffd9700001, 0x1fffffffd9680001, 0x1fffffffd9440001,
0x1fffffffd9080001, 0x1fffffffd8c80001, 0x1fffffffd8800001, 0x1fffffffd82c0001,
0x1fffffffd7cc0001, 0x1fffffffd7b80001, 0x1fffffffd7840001, 0x1fffffffd73c0001
};
}
}
}
}
}

Просмотреть файл

@ -68,22 +68,6 @@ For .NET Framework wrapper support (C++/CLI) we need to
it easy for non-expert users to select secure parameters.
*/
extern const std::map<std::size_t, std::vector<SmallModulus>> default_coeff_modulus_256;
// For internal use only, do not modify
namespace internal_mods
{
// Prime, 61 bits, and congruent to 1 mod 2^18
extern const SmallModulus m_sk;
// Non-prime; 2^32
extern const SmallModulus m_tilde;
// Prime, 61 bits, and congruent to 1 mod 2^18
extern const SmallModulus gamma;
// For internal use only, all primes 61 bits and congruent to 1 mod 2^18
extern const std::vector<SmallModulus> aux_small_mods;
}
}
}
}