Intel-HEXL transforms capability - reviewing the logic of checking if the NTT tables exist
It has been pointed out by the crypto-team that the logic used in Intel-HEXL transforms capability should be reviewed. The logic is related to checking whether a specific NTT table exists or not.
bool reCompute = false;
PALISADE_UNUSED(reCompute); // Used only when WITH_INTEL_HEXL=ON {:.ruby}
auto mapSearch = m_rootOfUnityReverseTableByModulus.find(modulus);
if (mapSearch == m_rootOfUnityReverseTableByModulus.end() ||
mapSearch->second.GetLength() != CycloOrderHf) {
PreCompute(rootOfUnity, CycloOrder, modulus);
reCompute = true; {:.ruby}
}
if (typeid(IntType) == typeid(NativeInteger)) {
#ifdef WITH_INTEL_HEXL
if (std::is_same<VecType, NativeVector64>::value) {
std::pair<uint64_t, uint64_t> key{element->GetLength(),
modulus.ConvertToInt()};
intel::hexl::NTT *p_ntt;
std::unique_lock<std::mutex> lock(m_mtxIntelNTT);
auto ntt_it = m_IntelNtt.find(key);
if (reCompute || ntt_it == m_IntelNtt.end()) { {:.ruby}
intel::hexl::NTT ntt(element->GetLength(), modulus.ConvertToInt(),
rootOfUnity.ConvertToInt());
m_IntelNtt[key] = std::move(ntt);
ntt_it = m_IntelNtt.find(key);
}
p_ntt = &ntt_it->second;
lock.unlock();
auto *data = reinterpret_cast<uint64_t *>(&element->at(0));
p_ntt->ComputeForward(data, data, 1, 1);
element->SetModulus(modulus);
} else {
NumberTheoreticTransformNat<VecType>().ForwardTransformToBitReverseInPlace(
m_rootOfUnityReverseTableByModulus[modulus],
m_rootOfUnityPreconReverseTableByModulus[modulus], element);
}
#else
NumberTheoreticTransformNat<VecType>().ForwardTransformToBitReverseInPlace(
m_rootOfUnityReverseTableByModulus[modulus],
m_rootOfUnityPreconReverseTableByModulus[modulus], element);
#endif
The logic can be found at the following four locations:
https://gitlab.com/palisade/palisade-development/-/blob/dev/src/core/lib/math/bigintnat/transformnat.cpp#L602 https://gitlab.com/palisade/palisade-development/-/blob/dev/src/core/lib/math/bigintnat/transformnat.cpp#L670 https://gitlab.com/palisade/palisade-development/-/blob/dev/src/core/lib/math/bigintnat/transformnat.cpp#L742 https://gitlab.com/palisade/palisade-development/-/blob/dev/src/core/lib/math/bigintnat/transformnat.cpp#L819