I’m attempting to build OpenFHE for WebAssembly using emcmake
and encountered a couple of issues. Since openfhe-wasm
is still a work in progress, I analyzed and tried to fix them. Would appreciate feedback on whether my solutions are appropriate or if there are better alternatives.
Issue 1: MAX_MODULUS_SIZE vs. AUXMODSIZE Mismatch
In src/pke/lib/scheme/ckksrns/ckksrns-parametergeneration.cpp
, AUXMODSIZE
is set to 60
for non-128-bit platforms, but Emscripten fails in FirstPrime
when nBits > MAX_MODULUS_SIZE
(which is 57
).
Proposed Fix:
Modified the condition to handle Emscripten separately:
#if NATIVEINT == 128 && !defined(__EMSCRIPTEN__)
const size_t AUXMODSIZE = 119;
#else
#ifdef __EMSCRIPTEN__
const size_t AUXMODSIZE = 57;
#else
const size_t AUXMODSIZE = 60;
#endif
#endif
Issue 2: blake2xb
Compilation Error
The error occurs due to an incompatible iterator type:
error: no matching function for call to 'blake2xb'
note: candidate function not viable: no known conversion from 'iterator' to 'void *'
Proposed Fix:
Replaced .begin()
with .data()
for raw pointer access:
if (blake2xb(m_buffer.data(), m_buffer.size() * sizeof(PRNG::result_type),
&m_counter, sizeof(m_counter),
m_seed.data(), m_seed.size() * sizeof(PRNG::result_type)) != 0) {
OPENFHE_THROW("PRNG: blake2xb failed");
}
Questions:
- Are these fixes correct, or is there a more robust way to handle them?
- Are there any known workarounds or ongoing efforts to improve Emscripten compatibility?
Thanks in advance for your help!