We are calculating x^3%8. In the following snippet,
// Initialize Function f(x) = x^3 % p
auto fp = [](NativeInteger m, NativeInteger p1) -> NativeInteger {
if (m < p1)
return (m * m * m) % p1;
else
return ((m - p1 / 2) * (m - p1 / 2) * (m - p1 / 2)) % p1;
};
I do not understand why the else statement is need. I would explain what I understand by the code so that one can figure out where I am wrong.
In the main code (code where this snippet belongs), we have p1=8. For i\ge p1/2 we have (i-p1)^3\equiv p1. Hence I think the code could be,
if (m < p1/2)
return (m * m * m) % p1;
else
return ((m-p1)^3) % p1;
I would really appreciate, if someone could correct me.
It appears to me that the else-statement’s logic is to handle negative values of m. But you are right, it is an unreachable code and you can ignore it.
EvalFunc is described here https://eprint.iacr.org/2021/1337.pdf in Section 4. It’s useful to read the previous sections as well, to understand how the floor evaluation and sign evaluations work.