emp-toolkit / emp-sh2pc

Semi-honest Two Party Computation Based on Garbled Circuits.
Other
76 stars 38 forks source link

Built-in hash or commitment function #25

Closed kzhong130 closed 3 years ago

kzhong130 commented 3 years ago

Hi, I wonder in emp-tool, is there built-in functionality such as hash or commitment that one can use in this 2pc? I see that you mentioned in README of emp-tool you have the hash function, is this one that can be used in 2pc? Unfortunately I did not see the commitment class you mentioned in the reamde. If there is, what is the commitment scheme you are using? Thank you!

weikengchen commented 3 years ago

I think since sh2pc imports emp-tool, you should be able to use those functions as well. https://github.com/emp-toolkit/emp-tool/blob/master/test/hash.cpp

And I think the commitment scheme described in the README is missing @wangxiao1254.

But one thing you can do now for commitment---you can commit data via a hash function. So, the commitment is Hash(randomness || data).

weikengchen commented 3 years ago

The commitment scheme's code can be found here: https://github.com/fionser/emp-tool/blob/stable/emp-tool/utils/com.h

Likely from a previous version.

kzhong130 commented 3 years ago

Thanks for your help! For built-in hash function, I am looking for the function that I can call and use emp-tool to generate a circuit of computing Hash function over the input as how we can do for the Integer class. The hash.h file seems only wrapper of openssl hash function, but not generating the circuit of the hash function. Is this supported in emp-tool or I should try some other circuit compiler for this purpose?

weikengchen commented 3 years ago

As for that, it would be slightly complicated---you would need to invoke the SHA256 function inside the circuit. https://github.com/emp-toolkit/emp-agmpc/blob/master/test/sha256.cpp

Yet, SHA256 might not be the most efficient one. But we are not very sure about what may be a better one at this moment.

kzhong130 commented 3 years ago

Thanks! Yeah, I have tried to use the existing circuit of SHA256. This would work if all I want to compute is hash. But it won't work if I need to call hash function inside the task I run. So sounds to me this is not doable to run tasks consists of hash function inside emp framework now?

wangxiao1254 commented 3 years ago

FWIW: Generic MPC protocols that can compute any function work by expressing the computation as circuits. Everything in EMP is implicitly expressed as circuits at some point of the computation. If you want to compute a hash function here, the hash function has to be expressed as a circuit. You could find algebraic-based hash functions then you won't need a circuit.

weikengchen commented 3 years ago

One thing to add: it is possible for you to run a circuit inside a circuit program. Just to use the CircuitFile class and run the compute function on the labels.

kzhong130 commented 3 years ago

Thanks a lot to both of you! I should mention I am targeting at the ag2pc model where I believe using circuit file is the only option. I will try out using the compute function you mentioned.

wangxiao1254 commented 3 years ago

You can build part of your circuits using emp objects (Integer, etc). The Integer could be used as input to circuit file directly, it will then output a circuit containing both computation.

kzhong130 commented 3 years ago

Thank you very much! The suggestions are really helpful.