cryptobiu / libscapi

Comprehensive Open Source Library for Secure Multiparty Computation
MIT License
180 stars 66 forks source link

How to implement basic primitives? #74

Closed Zeinab-Rahmani closed 4 years ago

Zeinab-Rahmani commented 4 years ago

Hello, I have to test and implement the basic primitives such as cryptographic hash. I am following this structure: https://biulibscapi.readthedocs.io/en/latest/primitives/cryptographic_hash.html In order to implement this primitive I did the following in the terminal (which might be totally wrong):

zeinab@zeinab:~$ cd libscapi/ zeinab@zeinab:~/libscapi$ cd include/ zeinab@zeinab:~/libscapi/include$ cd primitives/ zeinab@zeinab:~/libscapi/include/primitives$ cmake . && make CMake Error: The source directory "/home/zeinab/libscapi/include/primitives" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI. zeinab@zeinab:~/libscapi/include/primitives$ ls -al total 204 drwxr-xr-x 2 zeinab zeinab 4096 Oct 2 09:55 . drwxr-xr-x 10 zeinab zeinab 4096 Oct 2 09:55 .. -rw-r--r-- 1 zeinab zeinab 33393 Oct 2 09:55 Dlog.hpp -rw-r--r-- 1 zeinab zeinab 13199 Oct 2 09:55 DlogOpenSSL.hpp -rw-r--r-- 1 zeinab zeinab 3943 Oct 2 09:55 HashBlake2.hpp -rw-r--r-- 1 zeinab zeinab 4618 Oct 2 09:55 Hash.hpp -rw-r--r-- 1 zeinab zeinab 4367 Oct 2 09:55 HashOpenSSL.hpp -rw-r--r-- 1 zeinab zeinab 4982 Oct 2 09:55 Kdf.hpp -rw-r--r-- 1 zeinab zeinab 10929 Oct 2 09:55 Matrix.hpp -rw-r--r-- 1 zeinab zeinab 16464 Oct 2 09:55 Mersenne.hpp -rw-r--r-- 1 zeinab zeinab 23061 Oct 2 09:55 Prf.hpp -rw-r--r-- 1 zeinab zeinab 13605 Oct 2 09:55 PrfOpenSSL.hpp -rw-r--r-- 1 zeinab zeinab 13413 Oct 2 09:55 Prg.hpp -rw-r--r-- 1 zeinab zeinab 4658 Oct 2 09:55 RandomOracle.hpp -rw-r--r-- 1 zeinab zeinab 15771 Oct 2 09:55 TrapdoorPermutation.hpp -rw-r--r-- 1 zeinab zeinab 3689 Oct 2 09:55 TrapdoorPermutationOpenSSL.hpp

Since there is no executable file in this folder, can someone help me what should I do to run these primitives? Thank you for your time.

liorko87 commented 4 years ago

Hello,

libscapi is a library. In order to compile libscapi, please run at the root dir of libscapi the command make. Afterwards a library that called libscapi will be created. Link to this folder and implement the primitive you need.

Lior

Zeinab-Rahmani commented 4 years ago

Thank you so much for the explanation. I linked the libscapi.a to my project. After that, in order to run the cryptographic hash, I wrote the following codes in qt creator:

image


I appreciate it if you could give me some hints on how to fix the errors and run this hash primitive. Thank you for your help :).

Meanwhile, I have to mention that I created the input array 'in' and output array 'out' in the following form which I know might not be correct.

char in [2]={'a','b'}; int out[2];

liorko87 commented 4 years ago

Please follow the functions signatures.

Zeinab-Rahmani commented 4 years ago

I try to follow but I recieve this error: ‘const class std::vector’ has no member named ‘length’

which is related to the following codes: hash->update(in, 0, in.length);

And these are my new codes:

include </home/zeinab/libscapi/include/primitives/HashOpenSSL.hpp>

include

include

using namespace std;

int main(int argc, char* argv[]){ //create an input array in and an output array out const vector in {'h', 'i'} ; vector out;

//create an OpenSSL sha224 function. CryptographicHash* hash = new OpenSSLSHA224();

//call the update function in the Hash interface. hash->update(in, 0, in.length);

//get the result of hashing the updated input. hash->hashFinal(out, 0); return 0; }

Zeinab-Rahmani commented 4 years ago

Hello, I think I found the problem, the code hash->update(in, 0, in.length); should be converted to hash->update(in, 0, in.size()); .

In the following there are my codes with no error:

include "primitives/HashOpenSSL.hpp"

include

using namespace std;

int main(int argc, char *argv[]) { //create an input array in and an output array out const vector in {'h', 'e', 'l', 'l', 'o'}; vector out;

//create  an OpenSSL sha224 function.
CryptographicHash* hash = new OpenSSLSHA224();

//call the update function in the Hash interface.
//void update(const vector<byte> &in, int inOffset, int inLen) override;
hash->update(in, 0, in.size());

//get the result of hashing the updated input.
hash->hashFinal(out, 0);
for(size_t i = 0; i < out.size(); i++){
std::cerr<<out[i]<<""; }
return 0;

}