amaloz / libgarble

Garbling library based on JustGarble
GNU General Public License v2.0
3 stars 3 forks source link

Issues when garbling and evaluating NOT gate #8

Open cchenOBS opened 7 years ago

cchenOBS commented 7 years ago

Dear author,

First, thank you for your nice work on garbled circuit and I like your code very much. I am actually use you code to build my own protocol but have and issue with garbling and evaluating NOT gate.

As far as I can understand, you are using "garble_gate_garble_standard" to garble any gate in a garble_standard mode. I modified the test code to garble and evaluate only one single NOT gate but it turns out that given input 0 the evaluated output is always 0 and given 1 the result is 1. So I modified the "garble_gate_garble_standard" function such that when garbling NOT gate, I use the following setting:

    if (type == GARBLE_GATE_NOT){
        label0 = out1;
        label1 = out0;
    } 

instead of label0 = out0; label1 = out1; Then, everything worked for NOT gate and larger circuits such as AES and SHA1.

I don't know whether you had such issue. Or it's I did not use the code properly.

Thank you for you time.

weikengchen commented 7 years ago

I am a follower of the project. Just feel interested.

I guess that the library supports only xor gate and and gate. And a direct not gate is expressed as and gate with two identical inputs. It seems to lack further steps to distinguish OR and NOT from AND.

Maybe OR should also be patched.

My personal perference is to combine NOT to an existing AND gate, as if the input labels are swapped.