diff --git a/.gitignore b/.gitignore index 8a9d35c887947b2618399e6cd64808e7df019e67..594785ade2c539b41af8349c13a431597f84514a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.user +build diff --git a/.travis.yml b/.travis.yml index 0178adbbd0f492320618e12f67ac3b20b1ae6ca4..c9a7d3c0afcb948911c6ab5524d0ae92861cfa20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,16 +4,16 @@ notifications: email: false before_install: + - sudo apt-get install libev-dev - sudo add-apt-repository ppa:beineri/opt-qt-5.10.1-trusty -y - sudo apt-get update -q - sudo apt-get install -qq qt510base - source /opt/qt510/bin/qt510-env.sh script: - - cd test - mkdir build - cd build - cmake ../ - - make - - ./libdap-test + - make libdap-test + - ./test/libdap-test diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c15de0b451836280141a7299138ba955aec5665..8f2d12b65480a97db25db68200bf914825a0691b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,12 @@ -project(dap C) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.0) +project(libdap C) + +# fix implicit declaration warnings +add_definitions ("-D_GNU_SOURCE") + +set(CMAKE_C_FLAGS "-Wall -Wextra") +set(CMAKE_C_FLAGS "-std=c11") add_subdirectory(core) add_subdirectory(crypto) - -add_library(${PROJECT_NAME} STATIC IMPORTED) +add_subdirectory(test EXCLUDE_FROM_ALL) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 28871fc23c1392e4e8910eb144da2f27451ca3b0..0a862d82aeb533eb7f4cc908871ff098e800d0af 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,15 +1,13 @@ cmake_minimum_required(VERSION 2.8) project (dap_core) - -include_directories(common/) -set(CORE_SRCS dap_common.c dap_config.c common/memwipe.c) -set(CORE_HEADERS dap_common.h dap_config.h dap_math_ops.h common/memwipe.h common/int-util.h) +file(GLOB CORE_SRCS *.c) +file(GLOB CORE_HEADERS *.h) add_library(${PROJECT_NAME} STATIC ${CORE_SRCS} ${CORE_HEADERS}) -target_link_libraries(${PROJECT_NAME} ev) +target_link_libraries(${PROJECT_NAME} ev) -set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE) - -set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR} CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE) +#This paths will be used by project-dependent project libraries +target_include_directories(dap_core INTERFACE .) +target_include_directories(dap_core INTERFACE common) diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 543677635f74ab958bd3d98b81a6cd9b3438381b..a5567da6464de334e40057f6a524c76ee7166e2d 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -1,47 +1,35 @@ cmake_minimum_required(VERSION 2.8) project (dap_crypto) - -set(CRYPTO_SRCS - dap_enc.c - dap_enc_base64.c - dap_enc_aes.c - dap_enc_newhope.c - dap_enc_msrln16.c - dap_enc_key.c - dap_enc_sidh16.c - liboqs/kex_sidh_cln16/kex_sidh_cln16.c - liboqs/kex_sidh_cln16/SIDH.c - liboqs/kex_sidh_cln16/SIDH_setup.c - liboqs/kex_sidh_cln16/sidh_kex.c - liboqs/kex_sidh_cln16/ec_isogeny.c - liboqs/kex_sidh_cln16/fpx.c - liboqs/kex_sidh_cln16/generic/fp_generic.c - liboqs/kex_rlwe_msrln16/generic/ntt.c - liboqs/kex_rlwe_msrln16/kex_rlwe_msrln16.c - liboqs/kex_rlwe_msrln16/LatticeCrypto_kex.c - liboqs/kex_rlwe_msrln16/ntt_constants.c - liboqs/crypto/sha3/sha3.c - liboqs/crypto/rand/rand.c - liboqs/crypto/rand_urandom_aesctr/rand_urandom_aesctr.c - liboqs/crypto/rand_urandom_chacha20/rand_urandom_chacha20.c - liboqs/crypto/aes/aes_c.c - liboqs/crypto/aes/aes_ni.c - liboqs/crypto/aes/aes.c +file(GLOB CRYPTO_SRCS *.c) +file(GLOB CRYPTO_HEADERS *.h) + +set(LIBOQS_SRCS + liboqs/kex_sidh_cln16/kex_sidh_cln16.c + liboqs/kex_sidh_cln16/SIDH.c + liboqs/kex_sidh_cln16/SIDH_setup.c + liboqs/kex_sidh_cln16/sidh_kex.c + liboqs/kex_sidh_cln16/ec_isogeny.c + liboqs/kex_sidh_cln16/fpx.c + liboqs/kex_sidh_cln16/generic/fp_generic.c + liboqs/kex_rlwe_msrln16/generic/ntt.c + liboqs/kex_rlwe_msrln16/kex_rlwe_msrln16.c + liboqs/kex_rlwe_msrln16/LatticeCrypto_kex.c + liboqs/kex_rlwe_msrln16/ntt_constants.c + liboqs/crypto/sha3/sha3.c + liboqs/crypto/rand/rand.c + liboqs/crypto/rand_urandom_aesctr/rand_urandom_aesctr.c + liboqs/crypto/rand_urandom_chacha20/rand_urandom_chacha20.c + liboqs/crypto/aes/aes_c.c + liboqs/crypto/aes/aes_ni.c + liboqs/crypto/aes/aes.c ) set(RND_SRCS - libdap/crypto/liboqs/crypto/rand/rand.c + liboqs/crypto/rand/rand.c ) -set(CRYPTO_HEADERS - dap_enc.h - dap_enc_base64.h - dap_enc_aes.h - dap_enc_newhope.h - dap_enc_msrln16.h - dap_enc_key.h - dap_enc_sidh16.h +set(LIBOQS_HEADERS liboqs/kex_sidh_cln16/kex_sidh_cln16.h liboqs/kex_sidh_cln16/SIDH.h liboqs/kex_sidh_cln16/SIDH_internal.h @@ -56,10 +44,7 @@ set(CRYPTO_HEADERS liboqs/crypto/aes/aes.h ) +add_library(${PROJECT_NAME} STATIC ${CRYPTO_SRCS} + ${LIBOQS_SRCS} ${CRYPTO_HEADERS} ${LIBOQS_HEADERS}) -include_directories("${dap_core_INCLUDE_DIRS}") -add_definitions ("${dap_core_DEFINITIONS}") -add_library(${PROJECT_NAME} STATIC ${CRYPTO_SRCS} ${CRYPTO_HEADERS} ) - -set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE) -set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR} CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE) +target_link_libraries(dap_crypto dap_core) diff --git a/crypto/test.c b/crypto/test.c deleted file mode 100644 index 68bef82c9ea0644e3968fb5124531a4f13ecd610..0000000000000000000000000000000000000000 --- a/crypto/test.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. - - This file is part of DAP (Deus Applications Prototypes) the open source project - - DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DAP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. -*/ - - -#include <stdlib.h> -#include <stdio.h> -#include <stdbool.h> -#include "enc_key.h" -#include "enc_base64.h" -#include "enc_rsa.h" -#include "enc_sha.h" -#include "enc.h" -#include "Aes.h" - -#define LOG_TAG "main" - -char * buf_src; -size_t test_size=38915; - -//char buf_src[]="Test string as long as it could be - much more than the one cypher block!!!"; -//const size_t test_size=sizeof(buf_src); - -bool test_enc_func( enc_key_t *key_enc, enc_key_t* key_dec,enc_data_type_t dt) -{ - bool noDiff=true; - char *buf_crypto , * buf_out; - size_t buf_crypto_size; - size_t buf_out_size; - size_t i; - - buf_crypto=(char*) calloc(1,test_size*4); - - buf_out = (char*) calloc(1,test_size*2); - - buf_crypto_size=enc_code(key_enc,buf_src,test_size,buf_crypto,dt); - buf_out_size=enc_decode(key_dec,buf_crypto,buf_crypto_size,buf_out,dt); - for(i=0; i<test_size;i++){ - if(buf_out[i]!=buf_src[i]){ - noDiff=false; - break; - } - } - - free(buf_out); - free(buf_crypto); - - if(noDiff){ - printf (" passed\n"); - return true; - }else{ - printf (" ERROR: Output '%s'\n", buf_out ); - exit(1); - } - return false; -} - -int main (int argc, const char *argv[]) -{ - (void) argc; - (void) argv; - enc_key_t * key, * key_pub; - printf("SafeCrypto test\n"); - - enc_init(); - printf("-- Init buffers (test data size %lu )\n",test_size); - - printf( "-- Aes_Test %s\n", (Aes_Test()==0)?"passed":"was with ERROR" ); - - buf_src=(char*) calloc(1,test_size); - - size_t i; - for(i=0;i<test_size; i++) - buf_src[i]=rand()%255; - - /*printf("-- Test FNAM2... "); - key=enc_key_new(512/8,ENC_KEY_TYPE_FNAM2); - test_enc_func( key,key, ENC_DATA_TYPE_RAW); - enc_key_delete(key); - - exit(0);*/ - - /* printf("-- Test RSA... "); - key=enc_key_new(2048,ENC_KEY_TYPE_RSA_PVT); - key_pub=enc_rsa_pvt_to_pub(key); - test_enc_func(key_pub,key, ENC_DATA_TYPE_B64); - enc_key_delete(key); - enc_key_delete(key_pub);*/ - - printf("-- Test AES... "); - key=enc_key_create("TestPasswW0rdStringAsLongfgsdjgupsidfujp0sijughwrpighjsgjskigjsigh",ENC_KEY_TYPE_AES); - test_enc_func( key,key, ENC_DATA_TYPE_B64); - enc_key_delete(key); - - return 0; -} - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 23e99d069d8609aca0a19ec5b8fb449f86dcb1a5..415379a792768802c4479a7ed0823c2746db4f75 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,11 +4,6 @@ project(libdap-test) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_C_FLAGS "-Wall -Wextra") -set(CMAKE_C_FLAGS "-std=c11") - -# fix implicit declaration warnings -add_definitions ("-D_GNU_SOURCE") # Tell CMake to run moc when necessary: set(CMAKE_AUTOMOC ON) @@ -19,25 +14,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(Qt5Test REQUIRED) -# dependencies for testing - -set(HEADERS - ../core/dap_config.h - ../core/dap_common.h - ) - -set(SRC - ../core/dap_config.c - ../core/dap_common.c - ) - -set(TEST_FILES - main.cpp - TestHeaders.hpp - core/DapConfig_test.hpp -) - -add_executable(${PROJECT_NAME} ${TEST_FILES} ${SRC} ${HEADERS}) # ${SRC} ${HEADERS} +file(GLOB TEST_FILES *.hpp *.cpp core/*.hpp) +add_executable(${PROJECT_NAME} ${TEST_FILES} ${SRC} ${HEADERS}) -target_include_directories(${PROJECT_NAME} PUBLIC ../core) target_link_libraries(${PROJECT_NAME} Qt5::Test) +target_link_libraries(${PROJECT_NAME} dap_core) +target_link_libraries(${PROJECT_NAME} dap_crypto)