Intel HEXL
Intel Homomorphic Encryption Acceleration Library, accelerating the modular arithmetic operations used in homomorphic encryption.
|
Performs negacyclic forward and inverse number-theoretic transform (NTT), commonly used in RLWE cryptography. More...
#include <ntt.hpp>
Classes | |
struct | AllocatorAdapter |
Helper class for custom memory allocation. More... | |
Public Member Functions | |
NTT ()=default | |
Initializes an empty NTT object. More... | |
~NTT ()=default | |
Destructs the NTT object. More... | |
NTT (uint64_t degree, uint64_t q, std::shared_ptr< AllocatorBase > alloc_ptr={}) | |
Initializes an NTT object with degree degree and modulus q . More... | |
template<class Allocator , class... AllocatorArgs> | |
NTT (uint64_t degree, uint64_t q, Allocator &&a, AllocatorArgs &&... args) | |
NTT (uint64_t degree, uint64_t q, uint64_t root_of_unity, std::shared_ptr< AllocatorBase > alloc_ptr={}) | |
Initializes an NTT object with degree degree and modulus q . More... | |
template<class Allocator , class... AllocatorArgs> | |
NTT (uint64_t degree, uint64_t q, uint64_t root_of_unity, Allocator &&a, AllocatorArgs &&... args) | |
void | ComputeForward (uint64_t *result, const uint64_t *operand, uint64_t input_mod_factor, uint64_t output_mod_factor) |
Compute forward NTT. Results are bit-reversed. More... | |
void | ComputeInverse (uint64_t *result, const uint64_t *operand, uint64_t input_mod_factor, uint64_t output_mod_factor) |
uint64_t | GetMinimalRootOfUnity () const |
Returns the minimal 2N'th root of unity. More... | |
uint64_t | GetDegree () const |
Returns the degree N. More... | |
uint64_t | GetModulus () const |
Returns the word-sized prime modulus. More... | |
const AlignedVector64< uint64_t > & | GetRootOfUnityPowers () const |
Returns the root of unity powers in bit-reversed order. More... | |
uint64_t | GetRootOfUnityPower (size_t i) |
Returns the root of unity power at bit-reversed index i. More... | |
const AlignedVector64< uint64_t > & | GetPrecon32RootOfUnityPowers () const |
Returns 32-bit pre-conditioned root of unity powers in bit-reversed order. More... | |
const AlignedVector64< uint64_t > & | GetPrecon64RootOfUnityPowers () const |
Returns 64-bit pre-conditioned root of unity powers in bit-reversed order. More... | |
const AlignedVector64< uint64_t > & | GetAVX512RootOfUnityPowers () const |
Returns the root of unity powers in bit-reversed order with modifications for use by AVX512 implementation. More... | |
const AlignedVector64< uint64_t > & | GetAVX512Precon32RootOfUnityPowers () const |
Returns 32-bit pre-conditioned AVX512 root of unity powers in bit-reversed order. More... | |
const AlignedVector64< uint64_t > & | GetAVX512Precon52RootOfUnityPowers () const |
Returns 52-bit pre-conditioned AVX512 root of unity powers in bit-reversed order. More... | |
const AlignedVector64< uint64_t > & | GetAVX512Precon64RootOfUnityPowers () const |
Returns 64-bit pre-conditioned AVX512 root of unity powers in bit-reversed order. More... | |
const AlignedVector64< uint64_t > & | GetInvRootOfUnityPowers () const |
Returns the inverse root of unity powers in bit-reversed order. More... | |
uint64_t | GetInvRootOfUnityPower (size_t i) |
Returns the inverse root of unity power at bit-reversed index i. More... | |
const AlignedVector64< uint64_t > & | GetPrecon32InvRootOfUnityPowers () const |
Returns the vector of 32-bit pre-conditioned pre-computed root of unity. More... | |
const AlignedVector64< uint64_t > & | GetPrecon52InvRootOfUnityPowers () const |
Returns the vector of 52-bit pre-conditioned pre-computed root of unity. More... | |
const AlignedVector64< uint64_t > & | GetPrecon64InvRootOfUnityPowers () const |
Returns the vector of 64-bit pre-conditioned pre-computed root of unity. More... | |
Static Public Member Functions | |
static bool | CheckArguments (uint64_t degree, uint64_t modulus) |
Returns true if arguments satisfy constraints for negacyclic NTT. More... | |
static size_t | MaxDegreeBits () |
Maximum power of 2 in degree. More... | |
static size_t | MaxModulusBits () |
Maximum number of bits in modulus;. More... | |
Static Public Attributes | |
static const size_t | s_default_shift_bits {64} |
Default bit shift used in Barrett precomputation. More... | |
static const size_t | s_ifma_shift_bits {52} |
Bit shift used in Barrett precomputation when AVX512-IFMA acceleration is enabled. More... | |
static const size_t | s_max_fwd_32_modulus {1ULL << (32 - 2)} |
Maximum modulus to use 32-bit AVX512-DQ acceleration for the forward transform. More... | |
static const size_t | s_max_inv_32_modulus {1ULL << (32 - 1)} |
Maximum modulus to use 32-bit AVX512-DQ acceleration for the inverse transform. More... | |
static const size_t | s_max_fwd_ifma_modulus {1ULL << (s_ifma_shift_bits - 2)} |
Maximum modulus to use AVX512-IFMA acceleration for the forward transform. More... | |
static const size_t | s_max_inv_ifma_modulus {1ULL << (s_ifma_shift_bits - 1)} |
Maximum modulus to use AVX512-IFMA acceleration for the inverse transform. More... | |
Performs negacyclic forward and inverse number-theoretic transform (NTT), commonly used in RLWE cryptography.
The number-theoretic transform (NTT) specializes the discrete Fourier transform (DFT) to the finite field \( \mathbb{Z}_q[X] / (X^N + 1) \).
|
default |
Initializes an empty NTT object.
|
default |
Destructs the NTT object.
intel::hexl::NTT::NTT | ( | uint64_t | degree, |
uint64_t | q, | ||
std::shared_ptr< AllocatorBase > | alloc_ptr = {} |
||
) |
Initializes an NTT object with degree degree
and modulus q
.
[in] | degree | also known as N. Size of the NTT transform. Must be a power of 2 |
[in] | q | Prime modulus. Must satisfy \( q == 1 \mod 2N \) |
[in] | alloc_ptr | Custom memory allocator used for intermediate calculations Performs pre-computation necessary for forward and inverse transforms |
|
inline |
intel::hexl::NTT::NTT | ( | uint64_t | degree, |
uint64_t | q, | ||
uint64_t | root_of_unity, | ||
std::shared_ptr< AllocatorBase > | alloc_ptr = {} |
||
) |
Initializes an NTT object with degree degree
and modulus q
.
[in] | degree | also known as N. Size of the NTT transform. Must be a power of 2 |
[in] | q | Prime modulus. Must satisfy \( q == 1 \mod 2N \) |
[in] | root_of_unity | 2N'th root of unity in \( \mathbb{Z_q} \). |
[in] | alloc_ptr | Custom memory allocator used for intermediate calculations |
Performs pre-computation necessary for forward and inverse transforms
|
inline |
|
static |
Returns true if arguments satisfy constraints for negacyclic NTT.
[in] | degree | N. Size of the transform, i.e. the polynomial degree. Must be a power of two. |
[in] | modulus | Prime modulus q. Must satisfy q mod 2N = 1 |
void intel::hexl::NTT::ComputeForward | ( | uint64_t * | result, |
const uint64_t * | operand, | ||
uint64_t | input_mod_factor, | ||
uint64_t | output_mod_factor | ||
) |
Compute forward NTT. Results are bit-reversed.
[out] | result | Stores the result |
[in] | operand | Data on which to compute the NTT |
[in] | input_mod_factor | Assume input operand are in [0, input_mod_factor * q). Must be 1, 2 or 4. |
[in] | output_mod_factor | Returns output result in [0, output_mod_factor * q). Must be 1 or 4. |
void intel::hexl::NTT::ComputeInverse | ( | uint64_t * | result, |
const uint64_t * | operand, | ||
uint64_t | input_mod_factor, | ||
uint64_t | output_mod_factor | ||
) |
Compute inverse NTT. Results are bit-reversed.
[out] | result | Stores the result |
[in] | operand | Data on which to compute the NTT |
[in] | input_mod_factor | Assume input operand are in [0, input_mod_factor * q). Must be 1 or 2. |
[in] | output_mod_factor | Returns output result in [0, output_mod_factor * q). Must be 1 or 2. |
|
inline |
Returns 32-bit pre-conditioned AVX512 root of unity powers in bit-reversed order.
|
inline |
Returns 52-bit pre-conditioned AVX512 root of unity powers in bit-reversed order.
|
inline |
Returns 64-bit pre-conditioned AVX512 root of unity powers in bit-reversed order.
|
inline |
Returns the root of unity powers in bit-reversed order with modifications for use by AVX512 implementation.
|
inline |
Returns the degree N.
|
inline |
Returns the inverse root of unity power at bit-reversed index i.
|
inline |
Returns the inverse root of unity powers in bit-reversed order.
|
inline |
Returns the minimal 2N'th root of unity.
|
inline |
Returns the word-sized prime modulus.
|
inline |
Returns the vector of 32-bit pre-conditioned pre-computed root of unity.
|
inline |
Returns 32-bit pre-conditioned root of unity powers in bit-reversed order.
|
inline |
Returns the vector of 52-bit pre-conditioned pre-computed root of unity.
|
inline |
Returns the vector of 64-bit pre-conditioned pre-computed root of unity.
|
inline |
Returns 64-bit pre-conditioned root of unity powers in bit-reversed order.
|
inline |
Returns the root of unity power at bit-reversed index i.
|
inline |
Returns the root of unity powers in bit-reversed order.
|
inlinestatic |
Maximum power of 2 in degree.
|
inlinestatic |
Maximum number of bits in modulus;.
|
static |
Default bit shift used in Barrett precomputation.
|
static |
Bit shift used in Barrett precomputation when AVX512-IFMA acceleration is enabled.
|
static |
Maximum modulus to use 32-bit AVX512-DQ acceleration for the forward transform.
|
static |
Maximum modulus to use AVX512-IFMA acceleration for the forward transform.
|
static |
Maximum modulus to use 32-bit AVX512-DQ acceleration for the inverse transform.
|
static |
Maximum modulus to use AVX512-IFMA acceleration for the inverse transform.