cryptobiu / libscapi

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

Error While Linking with Cmake #93

Closed kingradio closed 5 months ago

kingradio commented 5 months ago

Describe the bug While trying to link the lib with my project,it happens that

[100%] Linking CXX executable pir
/home/ydcy/libscapi/libscapi.a(Prg.o): In function `OpenSSLRC4::setKey(SecretKey&)':
/home/ydcy/libscapi/src/primitives/Prg.cpp:382: undefined reference to `RC4_set_key'
/home/ydcy/libscapi/libscapi.a(Prg.o): In function `PrgFromOpenSSLAES::generateKey(int)':
/home/ydcy/libscapi/src/primitives/Prg.cpp:255: undefined reference to `RAND_bytes'
/home/ydcy/libscapi/libscapi.a(Prg.o): In function `OpenSSLRC4::getPRGBytes(std::vector<unsigned char, std::allocator<unsigned char> >&, int, int)':
/home/ydcy/libscapi/src/primitives/Prg.cpp:421: undefined reference to `RC4'
/home/ydcy/libscapi/libscapi.a(Prg.o): In function `OpenSSLRC4::generateKey(int)':
/home/ydcy/libscapi/src/primitives/Prg.cpp:402: undefined reference to `RAND_bytes'
/home/ydcy/libscapi/libscapi.a(Prg.o): In function `PrgFromOpenSSLAES::prepare()':
/home/ydcy/libscapi/src/primitives/Prg.cpp:372: undefined reference to `EVP_EncryptUpdate'
/home/ydcy/libscapi/libscapi.a(Prg.o): In function `PrgFromOpenSSLAES::setKey(SecretKey&)':
/home/ydcy/libscapi/src/primitives/Prg.cpp:272: undefined reference to `EVP_CIPHER_CTX_new'
/home/ydcy/libscapi/src/primitives/Prg.cpp:276: undefined reference to `EVP_CIPHER_CTX_reset'
/home/ydcy/libscapi/src/primitives/Prg.cpp:277: undefined reference to `EVP_aes_128_ecb'
/home/ydcy/libscapi/src/primitives/Prg.cpp:277: undefined reference to `EVP_EncryptInit'
/home/ydcy/libscapi/src/primitives/Prg.cpp:282: undefined reference to `EVP_EncryptUpdate'
/home/ydcy/libscapi/src/primitives/Prg.cpp:289: undefined reference to `EVP_CIPHER_CTX_reset'
/home/ydcy/libscapi/src/primitives/Prg.cpp:290: undefined reference to `EVP_CIPHER_CTX_reset'
/home/ydcy/libscapi/src/primitives/Prg.cpp:291: undefined reference to `EVP_aes_128_ecb'
/home/ydcy/libscapi/src/primitives/Prg.cpp:291: undefined reference to `EVP_EncryptInit'
/home/ydcy/libscapi/libscapi.a(Prg.o): In function `PrgFromOpenSSLAES::~PrgFromOpenSSLAES()':
/home/ydcy/libscapi/src/primitives/Prg.cpp:244: undefined reference to `EVP_CIPHER_CTX_reset'
collect2: error: ld returned 1 exit status
CMakeFiles/pir.dir/build.make:96: recipe for target 'pir' failed
make[2]: *** [pir] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/pir.dir/all' failed
make[1]: *** [CMakeFiles/pir.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Steps to reproduce the bug The CmakeLists.txt is as below

cmake_minimum_required(VERSION 3.10)
project(pir)
set(GMP_LIBRARY_DIR /usr/local/lib)
set(GMP_INCLUDE_DIRS /usr/local/include)
set(SSL_LIBRARY_DIR /usr/local/lib)
set(SSL_INCLUDE_DIRS /usr/local/include/openssl)
include_directories(${GMP_INCLUDE_DIRS})
include_directories(${SSL_INCLUDE_DIR})
link_directories(${GMP_LIBRARY_DIR})
link_directories(${SSL_LIBRARY_DIR})
add_executable(${PROJECT_NAME} test.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC /home/ydcy/libscapi/include)
target_link_libraries(${PROJECT_NAME} /home/ydcy/libscapi/libscapi.a ${SSL_LIBRARY_DIR}/libssl.a ${GMP_LIBRARY_DIR}/libgmp.a)

and the c++ code is

int PRP(int in){
    PseudorandomPermutation* prp = new LubyRackoffPrpFromPrfVarying();
    vector<byte> *input = new vector<byte>(reinterpret_cast<byte*>(&in), 
                    reinterpret_cast<byte*>(&in) + sizeof(int));
    vector<byte> *output = new vector<byte>(4);
    byte *buffer = new byte[4];
    buffer[0] = 0x01;
    buffer[1] = 0x02;
    buffer[2] = 0x03; 
    buffer[3] = 0x04;
    SecretKey *key = new SecretKey(buffer,4,prp->getAlgorithmName());
    prp->setKey(*key);
    prp->computeBlock(*input,0,*output,0);
    int out;
    memcpy(&out, output->data(), sizeof(int));
    delete(input);
    delete(output);
    delete(prp);
    prp = nullptr;
    input = nullptr;
    output = nullptr;
    return out;
}

Machine details (please complete the following information):