From 0a66568db7713fc874dcf14879561c61a5ad9374 Mon Sep 17 00:00:00 2001 From: anta999 <arcticshine999@gmail.com> Date: Tue, 30 Jul 2019 20:03:11 +0400 Subject: [PATCH] fixed cert tests --- .gitmodules | 76 +++++++++++ .travis.yml | 10 +- CMakeLists.txt | 164 +++++++++++++++++------- dap_hash.c | 102 +++++++-------- dap_hash.h | 151 ++++++++++++++-------- libdap | 1 + libdap-chain | 1 + libdap-chain-gdb | 1 + libdap-chain-global-db | 1 + libdap-chain-mempool | 1 + libdap-chain-net | 1 + libdap-chain-net-srv | 1 + libdap-chain-wallet | 1 + libdap-client | 1 + libdap-crypto | 1 + libdap-server | 1 + libdap-server-core | 1 + libdap-server-http-db-auth | 1 + libdap-server-udp | 1 + libdap-stream | 1 + libdap-stream-ch | 1 + libdap-stream-ch-chain | 1 + libdap-stream-ch-chain-net | 1 + test/CMakeLists.txt | 36 +++--- test/dap_chain_cert_save_tests.c | 129 +++++++++---------- test/dap_sha3_tests.c | 211 +++++++++++++++++++++++++++++++ test/libdap-test | 1 + test/main.c | 21 +-- 28 files changed, 667 insertions(+), 252 deletions(-) create mode 160000 libdap create mode 160000 libdap-chain create mode 160000 libdap-chain-gdb create mode 160000 libdap-chain-global-db create mode 160000 libdap-chain-mempool create mode 160000 libdap-chain-net create mode 160000 libdap-chain-net-srv create mode 160000 libdap-chain-wallet create mode 160000 libdap-client create mode 160000 libdap-crypto create mode 160000 libdap-server create mode 160000 libdap-server-core create mode 160000 libdap-server-http-db-auth create mode 160000 libdap-server-udp create mode 160000 libdap-stream create mode 160000 libdap-stream-ch create mode 160000 libdap-stream-ch-chain create mode 160000 libdap-stream-ch-chain-net create mode 100644 test/dap_sha3_tests.c create mode 160000 test/libdap-test diff --git a/.gitmodules b/.gitmodules index 8b13789179..dce1d1ba52 100755 --- a/.gitmodules +++ b/.gitmodules @@ -1 +1,77 @@ +[submodule "libdap"] + path = libdap + url = https://gitlab.demlabs.net/cellframe/libdap + branch = master +[submodule "test/libdap-test"] + path = test/libdap-test + url = https://gitlab.demlabs.net/cellframe/libdap-test/ + branch = master +[submodule "libdap-chain"] + path = libdap-chain + url = https://gitlab.demlabs.net/cellframe/libdap-chain + branch = master +[submodule "libdap-crypto"] + path = libdap-crypto + url = https://gitlab.demlabs.net/cellframe/libdap-crypto + branch = master +[submodule "libdap-chain-gdb"] + path = libdap-chain-gdb + url = https://gitlab.demlabs.net/cellframe/libdap-chain-gdb.git + branch = master +[submodule "libdap-chain-global-db"] + path = libdap-chain-global-db + url = https://gitlab.demlabs.net/cellframe/libdap-chain-global-db.git + branch = master +[submodule "libdap-chain-mempool"] + path = libdap-chain-mempool + url = https://gitlab.demlabs.net/cellframe/libdap-chain-mempool.git + branch = master +[submodule "libdap-chain-net-srv"] + path = libdap-chain-net-srv + url = https://gitlab.demlabs.net/cellframe/libdap-chain-net-srv.git + branch = master +[submodule "libdap-chain-wallet"] + path = libdap-chain-wallet + url = https://gitlab.demlabs.net/cellframe/libdap-chain-wallet.git + branch = master +[submodule "libdap-client"] + path = libdap-client + url = https://gitlab.demlabs.net/cellframe/libdap-client.git + branch = master +[submodule "libdap-server"] + path = libdap-server + url = https://gitlab.demlabs.net/cellframe/libdap-server.git + branch = master +[submodule "libdap-server-core"] + path = libdap-server-core + url = https://gitlab.demlabs.net/cellframe/libdap-server-core.git + branch = master +[submodule "libdap-server-udp"] + path = libdap-server-udp + url = https://gitlab.demlabs.net/cellframe/libdap-server-udp.git + branch = master +[submodule "libdap-stream"] + path = libdap-stream + url = https://gitlab.demlabs.net/cellframe/libdap-stream.git + branch = master +[submodule "libdap-stream-ch"] + path = libdap-stream-ch + url = https://gitlab.demlabs.net/cellframe/libdap-stream-ch.git + branch = master +[submodule "libdap-stream-ch-chain"] + path = libdap-stream-ch-chain + url = https://gitlab.demlabs.net/cellframe/libdap-stream-ch-chain.git + branch = master +[submodule "libdap-stream-ch-chain-net"] + path = libdap-stream-ch-chain-net + url = https://gitlab.demlabs.net/cellframe/libdap-stream-ch-chain-net.git + branch = master +[submodule "libdap-chain-net"] + path = libdap-chain-net + url = https://gitlab.demlabs.net/cellframe/libdap-chain-net + branch = master +[submodule "libdap-server-http-db-auth"] + path = libdap-server-http-db-auth + url = https://gitlab.demlabs.net/cellframe/libdap-server-http-db-auth.git + branch = master diff --git a/.travis.yml b/.travis.yml index c3f4e90422..177fa1db10 100755 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_install: script: - mkdir build - cd build - - cmake ../ + - cmake -DBUILD_DAP_CHAIN_CRYPTO_TESTS=ON ../ - make - ctest --verbose @@ -19,3 +19,11 @@ addons: apt: sources: - ubuntu-toolchain-r-test + packages: + - libev-dev + - libjson-c-dev + - libmagic-dev + - libmemcached-dev + - libldb-dev + - libtalloc-dev + - libtevent-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index 8af021546d..6cc4baae72 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,46 +1,118 @@ -cmake_minimum_required(VERSION 2.8) -project (dap_chain_crypto) - -set(DAP_CHAIN_CRYPTO_SRCS - dap_hash.c - dap_hash_fusion.c - dap_hash_keccak.c - dap_hash_slow.c - dap_chain_pkey.c - dap_chain_sign.c - dap_chain_cert.c - dap_chain_cert_file.c - ) - -set(DAP_CHAIN_CRYPTO_HEADERS - dap_hash.h - dap_hash_fusion.h - dap_hash_keccak.h - dap_hash_slow.h - dap_chain_pkey.h - dap_chain_sign.h - dap_chain_cert.h - dap_chain_cert_file.h - ) - -if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) - add_subdirectory(libdap) - add_subdirectory(libdap-crypto) - add_subdirectory(libdap-chain) - enable_testing() - add_subdirectory(test) -endif() - -add_subdirectory(monero_crypto) - -include_directories("${monero_crypto_INCLUDE_DIRS}") -add_definitions ("${monero_crypto_DEFINITIONS}") - -add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_CRYPTO_SRCS} ${DAP_CHAIN_CRYPTO_HEADERS}) - -target_include_directories(dap_chain_crypto INTERFACE .) -target_link_libraries(dap_chain_crypto dap_core dap_crypto dap_chain monero_crypto) - -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) +cmake_minimum_required(VERSION 2.8) +project (dap_chain_crypto) + +set(DAP_CHAIN_CRYPTO_SRCS + dap_hash.c + dap_hash_fusion.c + dap_hash_keccak.c + dap_hash_slow.c + dap_chain_pkey.c + dap_chain_sign.c + dap_chain_cert.c + dap_chain_cert_file.c + ) + +set(DAP_CHAIN_CRYPTO_HEADERS + dap_hash.h + dap_hash_fusion.h + dap_hash_keccak.h + dap_hash_slow.h + dap_chain_pkey.h + dap_chain_sign.h + dap_chain_cert.h + dap_chain_cert_file.h + ) + +if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) + set(SUBMODULES_NO_BUILD ON) + + # Check whether we're on a 32-bit or 64-bit system + if(CMAKE_SIZEOF_VOID_P EQUAL "8") + set(DEFAULT_BUILD_64 ON) + else() + set(DEFAULT_BUILD_64 OFF) + endif() + option(BUILD_64 "Build for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_BUILD_64}) + + add_definitions ("-DDAP_SERVER") + add_definitions ("-DNODE_NETNAME=\"kelvin\"") + + set(_CCOPT "-Wall -O2 -pg -fPIC -fno-pie -no-pie") + set(_LOPT "-pg") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}") + set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${_LOPT}") + + if (NOT (TARGET dap_core)) + add_subdirectory(libdap) + endif() + if (NOT (TARGET dap_crypto)) + add_subdirectory(libdap-crypto) + endif() + if (NOT (TARGET dap_chain)) + add_subdirectory(libdap-chain) + endif() + if (NOT (TARGET dap_chain_mempool)) + add_subdirectory(libdap-chain-mempool) + endif() + if (NOT (TARGET dap_server_core)) + add_subdirectory(libdap-server-core) + endif() + if (NOT (TARGET dap_chain_net)) + add_subdirectory(libdap-chain-net) + endif() + if (NOT (TARGET dap_chain_global_db)) + add_subdirectory(libdap-chain-global-db) + endif() + if (NOT (TARGET dap_client)) + add_subdirectory(libdap-client) + endif() + if (NOT (TARGET dap_server)) + add_subdirectory(libdap-server) + endif() + if (NOT (TARGET dap_udp_server)) + add_subdirectory(libdap-server-udp) + endif() + if (NOT (TARGET libdap-stream)) + add_subdirectory(libdap-stream) + endif() + if (NOT (TARGET dap_stream_ch)) + add_subdirectory(libdap-stream-ch) + endif() + if (NOT (TARGET dap_stream_ch_chain)) + add_subdirectory(libdap-stream-ch-chain) + endif() + if (NOT (TARGET dap_stream_ch_chain_net)) + add_subdirectory(libdap-stream-ch-chain-net) + endif() + if (NOT (TARGET dap_chain_wallet)) + add_subdirectory(libdap-chain-wallet) + endif() + if (NOT (TARGET dap_chain_net_srv)) + add_subdirectory(libdap-chain-net-srv) + endif() + if (NOT (TARGET dap_server_http_db_auth)) + add_subdirectory(libdap-server-http-db-auth) + endif() + if (NOT (TARGET dap_chain_gdb)) + add_subdirectory(libdap-chain-gdb) + endif() +endif() + +add_subdirectory(monero_crypto) + +include_directories("${monero_crypto_INCLUDE_DIRS}") +add_definitions ("${monero_crypto_DEFINITIONS}") + +add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_CRYPTO_SRCS} ${DAP_CHAIN_CRYPTO_HEADERS}) + +target_include_directories(dap_chain_crypto INTERFACE .) +target_link_libraries(dap_chain_crypto dap_core dap_crypto dap_chain monero_crypto) + +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) + +if (${BUILD_DAP_CHAIN_CRYPTO_TESTS} MATCHES ON) + enable_testing() + add_subdirectory(test) +endif() diff --git a/dap_hash.c b/dap_hash.c index 50f23f2995..49b0d91388 100755 --- a/dap_hash.c +++ b/dap_hash.c @@ -1,58 +1,44 @@ -/* - * Authors: - * Dmitriy A. Gearasimov <kahovski@gmail.com> - * DeM Labs Inc. https://demlabs.net - * DeM Labs Open source community https://github.com/demlabsinc - * Copyright (c) 2017-2018 - * 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 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "dap_common.h" -#include "dap_hash.h" - -#define LOG_TAG "dap_hash" - -int dap_hash_fast(const void *a_data_in, size_t a_data_in_size, dap_chain_hash_fast_t *a_hash_out) -{ - if(!a_data_in || !a_data_in_size || !a_hash_out) - return -1; - dap_hash(a_data_in, a_data_in_size, a_hash_out->raw, sizeof(a_hash_out->raw), - DAP_HASH_TYPE_KECCAK); - return 1; -} - -bool dap_hash_fast_is_blank(dap_chain_hash_fast_t *a_hash) -{ - if(!a_hash) - return true; - uint8_t *l_hast_bytes = (uint8_t*) a_hash; - for(size_t i = 0; i < sizeof(dap_chain_hash_fast_t); i++) { - if(l_hast_bytes[i]) - return false; - } - return true; -} - -bool dap_hash_fast_compare(dap_chain_hash_fast_t *a_hash1, dap_chain_hash_fast_t *a_hash2) -{ - if(!a_hash1 || !a_hash2) - return false; - if(!memcmp(a_hash1, a_hash2, sizeof(dap_chain_hash_fast_t))) - return true; - return false; -} +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * 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 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "dap_common.h" +#include "dap_hash.h" + +#include "KeccakHash.h" +#include "SimpleFIPS202.h" + +#define LOG_TAG "dap_hash" + +/** +int dap_hash_fast(const void *a_data_in, size_t a_data_in_size, dap_chain_hash_fast_t *a_hash_out) +{ + if(!a_data_in || !a_data_in_size || !a_hash_out) + return -1; +// dap_hash(a_data_in, a_data_in_size, a_hash_out->raw, sizeof(a_hash_out->raw), +// DAP_HASH_TYPE_KECCAK); + SHA3_256( (unsigned char *)a_hash_out, (const unsigned char *)a_data_in, a_data_in_size ); + + return 1; +} +**/ diff --git a/dap_hash.h b/dap_hash.h index fd72c9494f..9dcc854143 100755 --- a/dap_hash.h +++ b/dap_hash.h @@ -1,56 +1,95 @@ -/* - * Authors: - * Dmitriy A. Gearasimov <kahovski@gmail.com> - * DeM Labs Inc. https://demlabs.net - * DeM Labs Open source community https://github.com/demlabsinc - * Copyright (c) 2017-2018 - * 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 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. -*/ -#pragma once -#include <stddef.h> -#include <stdbool.h> - -#include "dap_hash_slow.h" -#include "dap_hash_keccak.h" -#include "dap_chain_common.h" - - -typedef enum dap_hash_type { - DAP_HASH_TYPE_KECCAK = 0, - DAP_HASH_TYPE_SLOW_0 = 1, -} dap_hash_type_t; - -static inline void dap_hash(const void * a_data_in, size_t a_data_in_size, - void * a_data_out, size_t a_data_out_size, - dap_hash_type_t a_type ){ - switch (a_type){ - case DAP_HASH_TYPE_KECCAK: - dap_hash_keccak(a_data_in,a_data_in_size, a_data_out,a_data_out_size); - break; - case DAP_HASH_TYPE_SLOW_0: - if( a_data_out_size>= dap_hash_slow_size() ){ - dap_hash_slow(a_data_in,a_data_in_size,(char*) a_data_out); - } - break; - } - -} - -int dap_hash_fast(const void *a_data_in, size_t a_data_in_size, dap_chain_hash_fast_t *a_hash_out); -bool dap_hash_fast_is_blank(dap_chain_hash_fast_t *a_hash); -bool dap_hash_fast_compare(dap_chain_hash_fast_t *a_hash1, dap_chain_hash_fast_t *a_hash2); +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * 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 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once +#include <stddef.h> +#include <stdbool.h> +#include <stdint.h> + +#include "dap_hash_slow.h" +#include "dap_hash_keccak.h" +#include "dap_chain_common.h" + +#include "KeccakHash.h" +#include "SimpleFIPS202.h" + +#define DAP_HASH_FAST_SIZE 32 + +typedef enum dap_hash_type { + DAP_HASH_TYPE_KECCAK = 0, + DAP_HASH_TYPE_SLOW_0 = 1, +} dap_hash_type_t; + +static inline int dap_hash_fast( const void *a_data_in, size_t a_data_in_size, uint8_t *a_hash_out ) +{ + if (!a_data_in || !a_data_in_size || !a_hash_out) + return -1; + +// dap_hash(a_data_in, a_data_in_size, a_hash_out->raw, sizeof(a_hash_out->raw), +// DAP_HASH_TYPE_KECCAK); + + SHA3_256( (unsigned char *)a_hash_out, (const unsigned char *)a_data_in, a_data_in_size ); + + return 1; +} + +static inline void dap_hash(const void * a_data_in, size_t a_data_in_size, + void * a_data_out, size_t a_data_out_size, + dap_hash_type_t a_type ){ + switch (a_type){ + case DAP_HASH_TYPE_KECCAK: +// dap_hash_keccak( a_data_in, a_data_in_size, a_data_out, a_data_out_size ); + SHA3_256( (unsigned char *)a_data_out, (const unsigned char *)a_data_in, a_data_in_size ); + break; + case DAP_HASH_TYPE_SLOW_0: + if( a_data_out_size>= dap_hash_slow_size() ){ + dap_hash_slow(a_data_in,a_data_in_size,(char*) a_data_out); + } + break; + } +} + +static uint64_t blank_hash[4] = { 0, 0, 0, 0 }; + +static inline bool dap_hash_fast_compare( void *a_hash1, void *a_hash2 ) +{ + if( !memcmp(a_hash1, a_hash2, DAP_HASH_FAST_SIZE) ) + return true; + + return false; +} + +static inline bool dap_hash_fast_is_blank( void *a_hash ) +{ +// uint8_t *l_hast_bytes = (uint8_t*) a_hash; +// for(size_t i = 0; i < sizeof(dap_chain_hash_fast_t); i++) { +// if(l_hast_bytes[i]) +// return false; +// } + return dap_hash_fast_compare( a_hash, &blank_hash[0] ); +} + + +//int dap_hash_fast(const void *a_data_in, size_t a_data_in_size, dap_chain_hash_fast_t *a_hash_out); +//bool dap_hash_fast_is_blank(dap_chain_hash_fast_t *a_hash); +//bool dap_hash_fast_compare(dap_chain_hash_fast_t *a_hash1, dap_chain_hash_fast_t *a_hash2); diff --git a/libdap b/libdap new file mode 160000 index 0000000000..67993d1f4c --- /dev/null +++ b/libdap @@ -0,0 +1 @@ +Subproject commit 67993d1f4cec44de464acee32a4d4f71d51c7e7d diff --git a/libdap-chain b/libdap-chain new file mode 160000 index 0000000000..b94cdd0d9e --- /dev/null +++ b/libdap-chain @@ -0,0 +1 @@ +Subproject commit b94cdd0d9ea3e10b5ade8a5f8073d34521a2783a diff --git a/libdap-chain-gdb b/libdap-chain-gdb new file mode 160000 index 0000000000..6ef661685f --- /dev/null +++ b/libdap-chain-gdb @@ -0,0 +1 @@ +Subproject commit 6ef661685f2792242433bf340f253d255f39e881 diff --git a/libdap-chain-global-db b/libdap-chain-global-db new file mode 160000 index 0000000000..94d4a28dd9 --- /dev/null +++ b/libdap-chain-global-db @@ -0,0 +1 @@ +Subproject commit 94d4a28dd97cc1395295e1582839b58ba36e2463 diff --git a/libdap-chain-mempool b/libdap-chain-mempool new file mode 160000 index 0000000000..15d5b39812 --- /dev/null +++ b/libdap-chain-mempool @@ -0,0 +1 @@ +Subproject commit 15d5b398125de01ba2525c76cd76c4ba590c4e2b diff --git a/libdap-chain-net b/libdap-chain-net new file mode 160000 index 0000000000..5af381b67e --- /dev/null +++ b/libdap-chain-net @@ -0,0 +1 @@ +Subproject commit 5af381b67ea3e6fcaa76a3620cdc11541a2212bf diff --git a/libdap-chain-net-srv b/libdap-chain-net-srv new file mode 160000 index 0000000000..be35813a34 --- /dev/null +++ b/libdap-chain-net-srv @@ -0,0 +1 @@ +Subproject commit be35813a341b88738d909329974407cab87c0143 diff --git a/libdap-chain-wallet b/libdap-chain-wallet new file mode 160000 index 0000000000..892160fc24 --- /dev/null +++ b/libdap-chain-wallet @@ -0,0 +1 @@ +Subproject commit 892160fc248cccd1d3749fc70766a07128f450ac diff --git a/libdap-client b/libdap-client new file mode 160000 index 0000000000..27bef519e7 --- /dev/null +++ b/libdap-client @@ -0,0 +1 @@ +Subproject commit 27bef519e72519abbd1c1e8b65274526cd006c3a diff --git a/libdap-crypto b/libdap-crypto new file mode 160000 index 0000000000..6249887fdd --- /dev/null +++ b/libdap-crypto @@ -0,0 +1 @@ +Subproject commit 6249887fdd5c9ed88eb26c1e10f853ea9f7001b6 diff --git a/libdap-server b/libdap-server new file mode 160000 index 0000000000..b92bfa29b7 --- /dev/null +++ b/libdap-server @@ -0,0 +1 @@ +Subproject commit b92bfa29b7994665ea80a98718a121f6e9576c8f diff --git a/libdap-server-core b/libdap-server-core new file mode 160000 index 0000000000..6778521f9f --- /dev/null +++ b/libdap-server-core @@ -0,0 +1 @@ +Subproject commit 6778521f9f646e2985994e63f470067b3e2c1e48 diff --git a/libdap-server-http-db-auth b/libdap-server-http-db-auth new file mode 160000 index 0000000000..bdab475c9d --- /dev/null +++ b/libdap-server-http-db-auth @@ -0,0 +1 @@ +Subproject commit bdab475c9dfe0ad876cd642a798e1b0b54ca314e diff --git a/libdap-server-udp b/libdap-server-udp new file mode 160000 index 0000000000..08bda84390 --- /dev/null +++ b/libdap-server-udp @@ -0,0 +1 @@ +Subproject commit 08bda8439038c79927427e0e531863a05193d478 diff --git a/libdap-stream b/libdap-stream new file mode 160000 index 0000000000..0dcee9fe68 --- /dev/null +++ b/libdap-stream @@ -0,0 +1 @@ +Subproject commit 0dcee9fe68ab7daaf42ed76d7bce0a1a5dc51631 diff --git a/libdap-stream-ch b/libdap-stream-ch new file mode 160000 index 0000000000..9bead7765f --- /dev/null +++ b/libdap-stream-ch @@ -0,0 +1 @@ +Subproject commit 9bead7765fba0a633098bf2279547c4dbf62cc4f diff --git a/libdap-stream-ch-chain b/libdap-stream-ch-chain new file mode 160000 index 0000000000..5f869621ca --- /dev/null +++ b/libdap-stream-ch-chain @@ -0,0 +1 @@ +Subproject commit 5f869621cac54e87615ed031aed81b48d38df9b0 diff --git a/libdap-stream-ch-chain-net b/libdap-stream-ch-chain-net new file mode 160000 index 0000000000..b43008b98e --- /dev/null +++ b/libdap-stream-ch-chain-net @@ -0,0 +1 @@ +Subproject commit b43008b98e4a7220059457732e81aa6a80021739 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 19060335f8..e4e350d47c 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,18 +1,18 @@ -if(TARGET chain_crypto_test) - return() # The project has already been built. -endif() -project(chain_crypto_test) - -add_subdirectory(libdap-test) - -file(GLOB SOURCES *.c) -file(GLOB HEADERS *.h) - -add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS}) - -target_link_libraries(${PROJECT_NAME} dap_test dap_core dap_crypto dap_chain) - -add_test( - NAME chain_crypto_test - COMMAND chain_crypto_test -) +if(TARGET chain_crypto_test) + return() # The project has already been built. +endif() +project(chain_crypto_test) + +add_subdirectory(libdap-test) + +file(GLOB SOURCES *.c) +file(GLOB HEADERS *.h) + +add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS}) + +target_link_libraries(${PROJECT_NAME} dap_chain_crypto dap_core dap_crypto dap_chain monero_crypto dap_test) + +add_test( + NAME chain_crypto_test + COMMAND chain_crypto_test +) diff --git a/test/dap_chain_cert_save_tests.c b/test/dap_chain_cert_save_tests.c index 9e1930faed..e20ea46d32 100755 --- a/test/dap_chain_cert_save_tests.c +++ b/test/dap_chain_cert_save_tests.c @@ -1,64 +1,65 @@ -#include <stdint.h> -#include <stdlib.h> -#include <unistd.h> - -#include "dap_test.h" -#include "dap_enc_key.h" -#include "dap_chain_cert.h" -#include "dap_chain_cert_file.h" - -#define CERT_FILE_PATH "cert_file_path.tmp" - -static void test_cert_memory_file(dap_enc_key_type_t a_key_type) -{ - uint32_t l_cert_buf_size = 0; - dap_chain_cert_t *l_cert = dap_chain_cert_generate_mem("name 1", a_key_type); - dap_assert_PIF(l_cert, "Fail create cert"); - uint8_t * l_cert_buf = dap_chain_cert_save_mem(l_cert, &l_cert_buf_size); - dap_assert_PIF(l_cert_buf, "Fail save cert to memory"); - dap_chain_cert_delete(l_cert); - - dap_chain_cert_t *l_cert2 = dap_chain_cert_mem_load(l_cert_buf, l_cert_buf_size); - dap_assert_PIF(l_cert2, "Fail read cert from memory"); - - dap_chain_cert_delete(l_cert2); - DAP_DELETE(l_cert_buf); - - dap_pass_msg("Save and load cert in memory successfully"); - - dap_chain_cert_t *l_certf = dap_chain_cert_generate_mem("name 2", a_key_type); - int l_res = dap_chain_cert_save_file(l_certf, CERT_FILE_PATH); - dap_assert_PIF(!l_res, "Fail save cert to file"); - dap_chain_cert_delete(l_certf); - - dap_chain_cert_t *l_certf2 = dap_chain_cert_file_load(CERT_FILE_PATH); - dap_assert_PIF(l_certf2, "Fail load cert from file"); - dap_chain_cert_delete(l_certf2); - // delete temp file - unlink(CERT_FILE_PATH); - - dap_pass_msg("Save and load cert in file successfully"); - -} - -void init_test_case() -{ - dap_enc_key_init(); -} - -void cleanup_test_case() -{ - dap_enc_key_deinit(); -} - -void dap_chain_cert_save_tests_run(void) -{ - dap_print_module_name("dap_chain_cert_save"); - init_test_case(); - - test_cert_memory_file(DAP_ENC_KEY_TYPE_SIG_BLISS); - test_cert_memory_file(DAP_ENC_KEY_TYPE_SIG_TESLA); - test_cert_memory_file(DAP_ENC_KEY_TYPE_SIG_PICNIC); - - cleanup_test_case(); -} +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> + +#include "dap_test.h" +#include "dap_enc_key.h" +#include "dap_chain_cert.h" +#include "dap_chain_cert_file.h" + +#define CERT_FILE_PATH "cert_file_path.tmp" + +static void test_cert_memory_file(dap_enc_key_type_t a_key_type) +{ + uint32_t l_cert_buf_size = 0; + + dap_chain_cert_t *l_cert = dap_chain_cert_generate_mem("name 1", a_key_type); + dap_assert_PIF(l_cert, "Fail create cert"); + + uint8_t * l_cert_buf = dap_chain_cert_mem_save(l_cert, &l_cert_buf_size); + dap_assert_PIF(l_cert_buf, "Fail save cert to memory"); + dap_chain_cert_delete(l_cert); + + dap_chain_cert_t *l_cert2 = dap_chain_cert_mem_load(l_cert_buf, l_cert_buf_size); + dap_assert_PIF(l_cert2, "Fail read cert from memory"); + dap_chain_cert_delete(l_cert2); + DAP_DELETE(l_cert_buf); + + dap_pass_msg("Save and load cert in memory successfully"); + + dap_chain_cert_t *l_certf = dap_chain_cert_generate_mem("name 2", a_key_type); + int l_res = dap_chain_cert_file_save(l_certf, CERT_FILE_PATH); + dap_assert_PIF(!l_res, "Fail save cert to file"); + dap_chain_cert_delete(l_certf); + + dap_chain_cert_t *l_certf2 = dap_chain_cert_file_load(CERT_FILE_PATH); + dap_assert_PIF(l_certf2, "Fail load cert from file"); + dap_chain_cert_delete(l_certf2); + + // delete temp file + unlink(CERT_FILE_PATH); + + dap_pass_msg("Save and load cert in file successfully"); +} + +void init_test_case() +{ + dap_enc_key_init(); +} + +void cleanup_test_case() +{ + dap_enc_key_deinit(); +} + +void dap_chain_cert_save_tests_run(void) +{ + dap_print_module_name("dap_chain_cert_save"); + init_test_case(); + + test_cert_memory_file(DAP_ENC_KEY_TYPE_SIG_BLISS); + test_cert_memory_file(DAP_ENC_KEY_TYPE_SIG_TESLA); + test_cert_memory_file(DAP_ENC_KEY_TYPE_SIG_PICNIC); + + cleanup_test_case(); +} diff --git a/test/dap_sha3_tests.c b/test/dap_sha3_tests.c new file mode 100644 index 0000000000..7a58271861 --- /dev/null +++ b/test/dap_sha3_tests.c @@ -0,0 +1,211 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <memory.h> +#include <time.h> +#include <stdbool.h> + +#ifdef _WIN32 +#include <windows.h> +#endif + +#include <pthread.h> + +#include "dap_test.h" + +#define BUFSIZE 512 + +#ifdef _MSC_VER + #define DAP_STATIC_INLINE static __forceinline + #define DAP_INLINE __forceinline + #define DAP_ALIGNED(x) __declspec( align(x) ) +#else + #define DAP_STATIC_INLINE static __attribute__((always_inline)) inline + #define DAP_INLINE __attribute__((always_inline)) inline + #define DAP_ALIGNED(x) __attribute__ ((aligned (x))) +#endif + +uint32_t xs30_seed[4] = { 0x3D696D09, 0xCD6BEB33, 0x9D1A0022, 0x9D1B0022 }; + +static inline void zRAND_reset( void ) { + + xs30_seed[0] = 0x3D696D09; + xs30_seed[1] = 0xCD6BEB33; + xs30_seed[2] = 0x9D1A0022; + xs30_seed[3] = 0x9D1B0022; +} + +static inline uint32_t zRAND( void ) { //period 2^96-1 + + uint32_t *zseed = &xs30_seed[0]; + + uint32_t t; + + zseed[0] ^= zseed[0] << 16; + zseed[0] ^= zseed[0] >> 5; + zseed[0] ^= zseed[0] << 1; + + t = zseed[0]; + zseed[0] = zseed[1]; + zseed[1] = zseed[2]; + + zseed[2] = t ^ zseed[0] ^ zseed[1]; + + return zseed[0]; +} + +static inline uint64_t gettime64( void ) +{ + uint64_t t64; + struct timespec now; + + clock_gettime( CLOCK_MONOTONIC, &now ); + t64 = now.tv_sec; + t64 *= 1000000000; + t64 += now.tv_nsec; + + return t64; +} + +static inline double gettimefloat( void ) +{ + return (double)gettime64() / 1000000000.0; +} + +#include "keccak.h" +#include "XKCP/lib/high/Keccak/FIPS202/KeccakHash.h" +#include "fips202.h" +#include "SimpleFIPS202.h" + +#define DAP_CHAIN_HASH_FAST_SIZE 32 + +typedef union dap_chain_hash_fast{ + uint8_t raw[DAP_CHAIN_HASH_FAST_SIZE]; +} dap_chain_hash_fast_t; + +typedef enum dap_hash_type { + DAP_HASH_TYPE_KECCAK = 0, + DAP_HASH_TYPE_SLOW_0 = 1, +} dap_hash_type_t; + +static inline void dap_hash_keccak( const void * a_in, size_t a_in_size, void *a_out, size_t a_out_size ) +{ + keccak((const uint8_t*) a_in, a_in_size, (uint8_t *) a_out,(int) a_out_size ); +} + +static inline void dap_hash(const void * a_data_in, size_t a_data_in_size, + void * a_data_out, size_t a_data_out_size, + dap_hash_type_t a_type ){ + switch (a_type){ + case DAP_HASH_TYPE_KECCAK: + dap_hash_keccak(a_data_in,a_data_in_size, a_data_out,a_data_out_size); + break; +// case DAP_HASH_TYPE_SLOW_0: +// if( a_data_out_size>= dap_hash_slow_size() ){ +// dap_hash_slow(a_data_in,a_data_in_size,(char*) a_data_out); +// } +// break; + } +} + +int dap_hash_fast( const void *a_data_in, size_t a_data_in_size, dap_chain_hash_fast_t *a_hash_out ) +{ + if(!a_data_in || !a_data_in_size || !a_hash_out) + return -1; + + dap_hash( a_data_in, a_data_in_size, a_hash_out->raw, sizeof(a_hash_out->raw), + DAP_HASH_TYPE_KECCAK); + + return 1; +} + +#define DATA_SIZE 2048 + +uint8_t data[8192]; +uint8_t data2[8192]; + +Keccak_HashInstance ki0; + +#define print_hash( x ) \ + printf( " hash = " ); \ + for( int g = 0; g < 32; ++g ) \ + printf( "%02X", x[g] ); \ + printf( "\n" ); \ + +void dap_sha3_tests_run(void) +{ + dap_chain_hash_fast_t hash0; + uint64_t start; + double t; + + uint8_t hash2[32]; + + dap_print_module_name("dap_sha3_tests_run( )"); + +// printf("dap_hash_fast( ) of %u data x %u ...\n", DATA_SIZE, 65536 ); + + for (int i = 0; i < DATA_SIZE; ++ i ) { + data[i] = zRAND( ) & 255; + } + + zRAND_reset( ); + start = gettime64( ); + + for (int h = 0; h < 65536; h ++ ) { + dap_hash_fast( &data[0], DATA_SIZE, &hash0 ); + } + + t = (double)(gettime64( ) - start) / 1000000000.0; + benchmark_mgs_rate( "dap_hash_fast_sha3(monero_crypto)(2048)", 65536.0 / t ); + print_hash( hash0.raw ); + +// printf("Keccak_sha_256( ) of %u data x %u ...\n", DATA_SIZE, 65536 ); + start = gettime64( ); + + for (int h = 0; h < 65536; h ++ ) { + SHA3_256( &hash2[0], &data[0], DATA_SIZE ); + } + t = (double)(gettime64( ) - start) / 1000000000.0; + benchmark_mgs_rate( "SHA_256(XKCP)(2048)", 65536.0 / t ); + print_hash( hash2 ); + +// printf("sha3_512(dap_crypto) of %u data x %u ...\n", DATA_SIZE, 65536 ); + start = gettime64( ); + + for (int h = 0; h < 65536; h ++ ) { + sha3_256( &hash2[0], &data[0], DATA_SIZE ); + } + + t = (double)(gettime64( ) - start) / 1000000000.0; + benchmark_mgs_rate( "sha3_256(dap_crypto)(2048)", 65536.0 / t ); + + print_hash( hash2 ); + +// printf("shake256(dap_crypto) of %u data x %u ...\n", DATA_SIZE, 65536 ); + start = gettime64( ); + + for (int h = 0; h < 65536; h ++ ) { + shake256( &hash2[0], 32, &data[0], DATA_SIZE ); + } + + t = (double)(gettime64( ) - start) / 1000000000.0; + benchmark_mgs_rate( "shake256(dap_crypto)(2048)", 65536.0 / t ); + print_hash( hash2 ); + +// printf("SHAKE256 of %u data x %u ...\n", DATA_SIZE, 65536 ); + start = gettime64( ); + + for (int h = 0; h < 65536; h ++ ) { + SHAKE256( &hash2[0], 32, &data[0], DATA_SIZE ); + } + + t = (double)(gettime64( ) - start) / 1000000000.0; + benchmark_mgs_rate( "SHAKE256(XKCP)(2048)", 65536.0 / t ); + + print_hash( hash2 ); + + dap_pass_msg("dap_sha3_tests_run( )"); + + return; +} \ No newline at end of file diff --git a/test/libdap-test b/test/libdap-test new file mode 160000 index 0000000000..b76175acc5 --- /dev/null +++ b/test/libdap-test @@ -0,0 +1 @@ +Subproject commit b76175acc517f085c319c8e66c62bd143f96bf94 diff --git a/test/main.c b/test/main.c index fd16469cbd..865be7a077 100755 --- a/test/main.c +++ b/test/main.c @@ -1,9 +1,12 @@ -#include "dap_common.h" -#include "dap_chain_cert_save_tests.h" - -int main(void) { - // switch off debug info from library - set_log_level(L_CRITICAL); - dap_chain_cert_save_tests_run(); - return 0; -} +#include "dap_common.h" +#include "dap_chain_cert_save_tests.h" + +void dap_sha3_tests_run(void); + +int main(void) { + // switch off debug info from library + dap_log_level_set(L_CRITICAL); + dap_chain_cert_save_tests_run(); + dap_sha3_tests_run(); + return 0; +} -- GitLab