This is wrong - for y = c1*u + c0, -y is -c1*u - c0. The only situation where c1 == -c1 is when c1=0, not when c1=half, and so the logic should be changed to:
It's equivalent since for any element in the field f > -f <=> f > half. This is because the numbers in the field are arranged as such:
half = (p-1)/2
c1 > -c1 <=> c1 > half, so all the numbers of [half+1, 2*half] satisfy that
c1 = 0 <=> c1 == -c1, because it has to satisfy 2*c1 == 0 (mod p), which can only happen for c1 == 0`, and then c0 > -c0 is equivalent to c0 > half for the same reasons.
Currently, we do:
This is wrong - for
y = c1*u + c0
,-y
is-c1*u - c0
. The only situation wherec1 == -c1
is whenc1=0
, not whenc1=half
, and so the logic should be changed to:This is equivalent to the upstream logic of checking y > -y:
It's equivalent since for any element in the field
f > -f <=> f > half
. This is because the numbers in the field are arranged as such: