From 9b8c71562cacb12e69406a9712a1f5c2113852aa Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Sat, 5 Jul 2014 19:42:14 -0400 Subject: [PATCH 1/5] Fix CMake warning --- vendor/easylzma/src/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/easylzma/src/CMakeLists.txt b/vendor/easylzma/src/CMakeLists.txt index decbcc9..8772e6d 100644 --- a/vendor/easylzma/src/CMakeLists.txt +++ b/vendor/easylzma/src/CMakeLists.txt @@ -52,8 +52,8 @@ ENDIF (APPLE) ### copy the two required headers into our output dir as a post build step # copy public headers to output directory -FOREACH (header ${PUB_HDRS}) +#FOREACH (header ${PUB_HDRS}) # preserve relative pathing - ADD_CUSTOM_COMMAND(TARGET easylzma_s POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir}) -ENDFOREACH (header ${PUB_HDRS}) + #ADD_CUSTOM_COMMAND(TARGET easylzma_s POST_BUILD + #COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir}) + #ENDFOREACH (header ${PUB_HDRS}) From caae9e640f2ee488d003afef67f1db10f0049fca Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Sat, 12 Jul 2014 17:29:19 -0400 Subject: [PATCH 2/5] Fix travis compilation error --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78812b9..e3039e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,10 +200,9 @@ ELSE() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall") IF(APPLE) - SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall") ELSE() - target_compile_options(fc PUBLIC -std=c++11 -Wall -fnon-call-exceptions) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fnon-call-exceptions") ENDIF() ENDIF() From 506f896de43e49213ac2d861f9e89a12595325c5 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 14 Jul 2014 10:46:15 -0400 Subject: [PATCH 3/5] Re-enable romix compilation --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3039e1..87be292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,8 +147,7 @@ set( fc_sources src/crypto/rand.cpp src/crypto/salsa20.cpp src/crypto/scrypt.cpp -# commented out until committed -# src/crypto/romix.cpp + src/crypto/romix.cpp src/network/tcp_socket.cpp src/network/udp_socket.cpp src/network/udt_socket.cpp From e442b29f6e59ad96f87e1043b34da08ca4893903 Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 14 Jul 2014 11:40:13 -0400 Subject: [PATCH 4/5] Fix scrypt --- CMakeLists.txt | 3 +- include/fc/crypto/scrypt.hpp | 5 +-- src/crypto/scrypt.cpp | 65 +++++++------------------------ vendor/scrypt-jane/CMakeLists.txt | 8 ++++ vendor/scrypt-jane/scrypt-jane.h | 12 ++++-- 5 files changed, 36 insertions(+), 57 deletions(-) create mode 100644 vendor/scrypt-jane/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 87be292..3b0ed56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,7 @@ list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp") list(APPEND sources ${fc_headers}) add_subdirectory( vendor/easylzma ) +add_subdirectory( vendor/scrypt-jane ) add_subdirectory( vendor/udt4 ) setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC DONT_INSTALL_LIBRARY ) @@ -219,7 +220,7 @@ target_include_directories(fc ${CMAKE_CURRENT_SOURCE_DIR}/vendor/udt4/src ) -target_link_libraries( fc PUBLIC udt easylzma_static ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library}) +target_link_libraries( fc PUBLIC easylzma_static scrypt udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library}) add_executable( ntp_test ntp_test.cpp ) target_link_libraries( ntp_test fc ) diff --git a/include/fc/crypto/scrypt.hpp b/include/fc/crypto/scrypt.hpp index 53d44df..b74708a 100644 --- a/include/fc/crypto/scrypt.hpp +++ b/include/fc/crypto/scrypt.hpp @@ -1,10 +1,9 @@ #pragma once -#include #include namespace fc { - void scrypt_derive_key ( const std::vector &passphrase, const std::vector &salt, - unsigned int n, unsigned int r, unsigned int p, std::vector &key ); + void scrypt_derive_key( const std::vector& passphrase, const std::vector& salt, + unsigned int n, unsigned int r, unsigned int p, std::vector& key ); } // namespace fc diff --git a/src/crypto/scrypt.cpp b/src/crypto/scrypt.cpp index 5eebe39..63b6710 100644 --- a/src/crypto/scrypt.cpp +++ b/src/crypto/scrypt.cpp @@ -1,57 +1,22 @@ -#include - -#include +#include #include - -#include - -#define SCRYPT_SALSA 1 -#define SCRYPT_SHA256 1 - -/* -#include "code/scrypt-jane-portable.h" -#include "code/scrypt-jane-romix.h" -*/ +#include "scrypt-jane.h" namespace fc { - void scrypt_derive_key( const std::vector &passphrase, const std::vector &salt, - unsigned int n, unsigned int r, unsigned int p, std::vector &key ) - { - /* - unsigned int chunk_bytes = SCRYPT_BLOCK_BYTES * r * 2; - std::vector yx((p+1) * chunk_bytes); + unsigned log2( unsigned n ) + { + if( n <= 0 ) FC_THROW_EXCEPTION( exception, "cannot take log2(${n})", ("n",n) ); + unsigned i = 0; + while( n >>= 1 ) ++i; + return i; + } - unsigned char *Y = &yx[0]; - unsigned char *X = &yx[chunk_bytes]; - - if(PKCS5_PBKDF2_HMAC( (const char*)&passphrase[0], passphrase.size(), - &salt[0], salt.size(), 1, - EVP_sha256(), chunk_bytes * p, X) != 1 ) - { - std::fill( yx.begin(), yx.end(), 0 ); - FC_THROW_EXCEPTION( exception, "error generating key material", - ("s", ERR_error_string( ERR_get_error(), nullptr) ) ); - } - - std::vector v(n * chunk_bytes); - - for( unsigned int i = 0; i < p; i++ ) - scrypt_ROMix_basic( (uint32_t*)(X+(chunk_bytes*i)), (uint32_t*)Y, (uint32_t*)&v[0], n, r ); - - if(PKCS5_PBKDF2_HMAC( (const char*)&passphrase[0], passphrase.size(), - X, chunk_bytes * p, 1, - EVP_sha256(), key.size(), &key[0]) != 1 ) - { - std::fill( yx.begin(), yx.end(), 0 ); - std::fill( v.begin(), v.end(), 0 ); - FC_THROW_EXCEPTION( exception, "error generating key material", - ("s", ERR_error_string( ERR_get_error(), nullptr) ) ); - } - - std::fill( yx.begin(), yx.end(), 0 ); - std::fill( v.begin(), v.end(), 0 ); - */ - } + void scrypt_derive_key( const std::vector& passphrase, const std::vector& salt, + unsigned int n, unsigned int r, unsigned int p, std::vector& key ) + { + scrypt( passphrase.data(), passphrase.size(), salt.data(), salt.size(), + log2( n ) - 1, log2( r ), log2( p ), key.data(), key.capacity() ); + } } // namespace fc diff --git a/vendor/scrypt-jane/CMakeLists.txt b/vendor/scrypt-jane/CMakeLists.txt new file mode 100644 index 0000000..305c6e3 --- /dev/null +++ b/vendor/scrypt-jane/CMakeLists.txt @@ -0,0 +1,8 @@ +add_definitions( -DSCRYPT_SALSA ) +add_definitions( -DSCRYPT_SHA256 ) + +set( scrypt_sources + scrypt-jane.c + ) + +add_library( scrypt ${scrypt_sources} ) diff --git a/vendor/scrypt-jane/scrypt-jane.h b/vendor/scrypt-jane/scrypt-jane.h index 1c0df62..bebad72 100644 --- a/vendor/scrypt-jane/scrypt-jane.h +++ b/vendor/scrypt-jane/scrypt-jane.h @@ -19,9 +19,15 @@ #include -typedef void (*scrypt_fatal_errorfn)(const char *msg); -void scrypt_set_fatal_error(scrypt_fatal_errorfn fn); +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*scrypt_fatal_errorfn)(const char *msg); + void scrypt_set_fatal_error(scrypt_fatal_errorfn fn); -void scrypt(const unsigned char *password, size_t password_len, const unsigned char *salt, size_t salt_len, unsigned char Nfactor, unsigned char rfactor, unsigned char pfactor, unsigned char *out, size_t bytes); + void scrypt(const unsigned char *password, size_t password_len, const unsigned char *salt, size_t salt_len, unsigned char Nfactor, unsigned char rfactor, unsigned char pfactor, unsigned char *out, size_t bytes); +#ifdef __cplusplus +} +#endif #endif /* SCRYPT_JANE_H */ From d31f5525a4ee223791395d70dc4f6815a7813b6b Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 14 Jul 2014 14:56:23 -0400 Subject: [PATCH 5/5] Fix linux clang compilation --- vendor/scrypt-jane/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vendor/scrypt-jane/CMakeLists.txt b/vendor/scrypt-jane/CMakeLists.txt index 305c6e3..f43b8a6 100644 --- a/vendor/scrypt-jane/CMakeLists.txt +++ b/vendor/scrypt-jane/CMakeLists.txt @@ -1,3 +1,8 @@ +IF (WIN32) +ELSE (WIN32) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -no-integrated-as") +ENDIF (WIN32) + add_definitions( -DSCRYPT_SALSA ) add_definitions( -DSCRYPT_SHA256 )