Types#
nttConst#
-
template<typename Precision>
struct nttConst# Bundles the three Montgomery constants derived from a runtime prime
p: the prime itself,-p^{-1} mod R(n_dash), andR^2 mod p(r2). Callable from both host and device code.Precisionmust be one ofuint16_t,uint32_t, oruint64_t.-
Precision n_dash#
-p^{-1} mod R, whereR = 2^(8 * sizeof(Precision)). Used as the Montgomery reduction constant.
-
__host__ __device__ nttConst(Precision p)#
Computes all three constants from
pusing Newton’s method (6 iterations) forn_dashand a double-width intermediate forr2.
Example
#include <ntt.hpp> // Build constants on the host and pass to a kernel const uint32_t prime = 998244353; cupqc::nttConst<uint32_t> ntt_const(prime); // ntt_const.p == prime // ntt_const.n_dash == -prime^{-1} mod 2^32 // ntt_const.r2 == (2^32)^2 mod prime
Like other host-side constants,
ntt_constmust be passed by value to CUDA kernels. Pass it toNTT::load_to_mont()andNTT::store_from_mont()(and their staged counterparts) to perform Montgomery domain conversions at load/store time when using a runtime prime.-
Precision n_dash#