MP-SPDZ icon indicating copy to clipboard operation
MP-SPDZ copied to clipboard

embed/extract negative integers to specific slot of a ring_element

Open jscode017 opened this issue 9 months ago • 3 comments

Hi @mkskeller I tried to embed then extract negative integer to specific slot of a ring_element as follows:

Ring_Element org_m;
modp modp_spec;
to_modp(modp_spec, spec_int, org_m.value.get_prD());
org_m.value.set_element(slot, modp_spec);
bigint bigint_orgm;
to_bigint(bigint_orgm, org_m.value.get_element(1), org_m.value.get_prD());
cout<<"org m: "<<bigint_orgm<<endl;

However due to the org_m.value.get_prD(), when I embed -2, I would get org_m.value.get_prD()-2, Is there a way to directly get -2, or I have to do things such as (if <p/2 then is positive, else is negative):

if(ele<org_m.value.get_prD()/2)
    set ele=ele
else
    set ele=-ele

Thanks a lot!

jscode017 avatar May 08 '24 17:05 jscode017

This is done in a number of places, but it isn't exposed as an independent function for modp, so you have to do it manually.

mkskeller avatar May 09 '24 02:05 mkskeller

Thanks for the reply, is it possible that you can point out a place that done this as an example? thanks again for your help

jscode017 avatar May 09 '24 03:05 jscode017

For example here: https://github.com/data61/MP-SPDZ/blob/59a4e830cf09328cd2a5f699617b3f90526799fc/FHE/Rq_Element.cpp#L146

mkskeller avatar May 09 '24 05:05 mkskeller