From 6ef656f9828dff2d26ef908eea206b12c2e4148a Mon Sep 17 00:00:00 2001 From: mkhan Date: Thu, 8 Mar 2018 15:18:24 +1100 Subject: [PATCH 1/5] gtest --- CMakeLists.txt | 30 +++--------------------------- cmake/Findgtest.cmake | 2 +- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14ca0af..ac3e169 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,29 +28,6 @@ install(FILES include(FindPackageHandleStandardArgs) -# We need C++11 -macro(require_cpp11) - if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.0) - # CMake 3.1 has built-in CXX standard checks. - message("-- Setting C++11") - set(CMAKE_CXX_STANDARD 11) - set(CMAKE_CXX_STANDARD_REQUIRED on) - else() - if (CMAKE_CXX_COMPILER_ID MATCHES "GCC") - message ("-- GNU CXX (-std=c++11)") - list(APPEND CMAKE_CXX_FLAGS "-std=c++11") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - message ("-- CLang CXX (-std=c++11)") - list(APPEND CMAKE_CXX_FLAGS "-std=c++11") - elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - message ("-- GNU CXX (-std=c++11)") - list(APPEND CMAKE_CXX_FLAGS "-std=c++11") - else() - message ("-- Requires C++11. Your compiler does not support it.") - endif() - endif() -endmacro() - # http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH if (APPLE) set(CMAKE_MACOSX_RPATH ON) @@ -64,9 +41,7 @@ if (APPLE) endif() endif() -list (APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wunused ") - -require_cpp11() +list (APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wunused -std=c++11 -O3 -L/usr/local/lib/ ") # Check for cryptopp (static) set(CryptoPP_USE_STATIC_LIBS ON) @@ -127,13 +102,14 @@ install (TARGETS mine-cli DESTINATION bin) ########################################## Unit Testing ################################### +set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") # Check for Easylogging++ find_package(EASYLOGGINGPP REQUIRED) include_directories (${EASYLOGGINGPP_INCLUDE_DIR}) find_package (gtest REQUIRED) -include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) +include_directories(${GTEST_INCLUDE_DIRS}) enable_testing() diff --git a/cmake/Findgtest.cmake b/cmake/Findgtest.cmake index cd443f4..f8aa599 100644 --- a/cmake/Findgtest.cmake +++ b/cmake/Findgtest.cmake @@ -156,4 +156,4 @@ if(GTEST_FOUND) _gtest_append_debugs(GTEST_LIBRARIES GTEST_LIBRARY) _gtest_append_debugs(GTEST_MAIN_LIBRARIES GTEST_MAIN_LIBRARY) set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}) -endif() \ No newline at end of file +endif() From 0ebfc0c3192b5f011ff0c0b36ba240e9976e6beb Mon Sep 17 00:00:00 2001 From: mkhan Date: Thu, 8 Mar 2018 15:41:34 +1100 Subject: [PATCH 2/5] test aes issue 11 --- CMakeLists.txt | 2 +- test/aes-test.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac3e169..2d1627e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ if (APPLE) endif() endif() -list (APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wunused -std=c++11 -O3 -L/usr/local/lib/ ") +list (APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wunused -std=c++11 -O0 -L/usr/local/lib/ ") # Check for cryptopp (static) set(CryptoPP_USE_STATIC_LIBS ON) diff --git a/test/aes-test.h b/test/aes-test.h index 94fcb4e..cee1d1c 100644 --- a/test/aes-test.h +++ b/test/aes-test.h @@ -1075,6 +1075,50 @@ TEST(AESTest, Copy) ASSERT_EQ(input, result); } +TEST(AESTest, EncryptResultsForLongTextMatchesRipe) +{ + const std::string key = "163E6AC9A9EB43253AC237D849BDD22C4798393D38FBE322F7E593E318F1AEAF"; + const std::string iv = "a14c54563269e9e368f56b325f04ff00"; + + // echo abcdefgabcdefga | ripe -e --aes --key 163E6AC9A9EB43253AC237D849BDD22C4798393D38FBE322F7E593E318F1AEAF --iv a14c54563269e9e368f56b325f04ff00 + // echo hBbLKWDjHQ0cAEMAsr9eLg== | ripe -d --base64 | ripe -e --hex + const std::string input15 = "abcdefgabcdefga"; + const std::string input15Enc = "8416CB2960E31D0D1C004300B2BF5E2E"; + + // echo abcdefgabcdefgab | ripe -e --aes --key 163E6AC9A9EB43253AC237D849BDD22C4798393D38FBE322F7E593E318F1AEAF --iv a14c54563269e9e368f56b325f04ff00 + // echo z4W6f7nyqQjcLb8QF+qYfpDI3r4mbBGDFSj4Wx2w3OU= | ripe -d --base64 | ripe -e --hex + const std::string input16 = "abcdefgabcdefgab"; + const std::string input16Enc = "CF85BA7FB9F2A908DC2DBF1017EA987E90C8DEBE266C11831528F85B1DB0DCE5"; + + // echo abcdefgabcdefgabc | ripe -e --aes --key 163E6AC9A9EB43253AC237D849BDD22C4798393D38FBE322F7E593E318F1AEAF --iv a14c54563269e9e368f56b325f04ff00 + // echo z4W6f7nyqQjcLb8QF+qYfpUo6XxWg/yWbdYk56VCn7M= | ripe -d --base64 | ripe -e --hex + const std::string input17 = "abcdefgabcdefgabc"; + const std::string input17Enc = "CF85BA7FB9F2A908DC2DBF1017EA987E9528E97C5683FC966DD624E7A5429FB3"; + + // echo abcdefgabcdefgababcdefgabcdefgab | ripe -e --aes --key 163E6AC9A9EB43253AC237D849BDD22C4798393D38FBE322F7E593E318F1AEAF --iv a14c54563269e9e368f56b325f04ff00 + // echo z4W6f7nyqQjcLb8QF+qYfp7M+oB8X/yEn0Vo1aBgAT1I7fn3ojw7Wl5ZnuhQlWJY | ripe -d --base64 | ripe -e --hex + const std::string input32 = "abcdefgabcdefgababcdefgabcdefgab"; + const std::string input32Enc = "CF85BA7FB9F2A908DC2DBF1017EA987E9ECCFA807C5FFC849F4568D5A060013D48EDF9F7A23C3B5A5E599EE850956258"; + + + AES aes; + aes.setKey(key); + + auto run = [&](const std::string& inp, const std::string& exp) { + std::string ivCopy = iv; + std::string output = aes.encr(inp, ivCopy, MineCommon::Encoding::Raw, MineCommon::Encoding::Base16); + LOG(INFO) << "Ripe: echo " << output << " | ripe -d --aes --key " << key << " --iv " << iv << " --hex"; + ASSERT_STRCASEEQ(exp.c_str(), output.c_str()); + }; + + run(input15, input15Enc); + run(input16, input16Enc); + run(input17, input17Enc); + run(input32, input32Enc); + +} + +// } #endif // AES_TEST_H From 3f61cb8f42a47f1000a314142d2cfec0ac28fa03 Mon Sep 17 00:00:00 2001 From: mkhan Date: Thu, 8 Mar 2018 17:04:21 +1100 Subject: [PATCH 3/5] reference: closes issue 11 --- src/aes.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/aes.cc b/src/aes.cc index c5e08c3..8af8e6e 100644 --- a/src/aes.cc +++ b/src/aes.cc @@ -857,6 +857,13 @@ std::string AES::encrypt(const std::string& input, const std::string& key, MineC { Key keyArr = Base16::fromString(key); ByteArray inp = resolveInputMode(input, inputEncoding); + if (pkcs5Padding && inputEncoding == MineCommon::Encoding::Raw && inp.size() % kBlockSize == 0) { + // input size is multiple of block size, increase + // input size for padding + auto sz = inp.size(); + inp.resize(sz + kBlockSize); + std::fill(inp.begin() + sz, inp.end(), 16); + } ByteArray result = encrypt(inp, &keyArr, pkcs5Padding); return resolveOutputMode(result, outputEncoding); } @@ -865,6 +872,13 @@ std::string AES::encrypt(const std::string& input, const std::string& key, std:: { Key keyArr = Base16::fromString(key); ByteArray inp = resolveInputMode(input, inputEncoding); + if (pkcs5Padding && inputEncoding == MineCommon::Encoding::Raw && inp.size() % kBlockSize == 0) { + // input size is multiple of block size, increase + // input size for padding + auto sz = inp.size(); + inp.resize(sz + kBlockSize); + std::fill(inp.begin() + sz, inp.end(), 16); + } ByteArray ivec = Base16::fromString(iv); bool ivecGenerated = iv.empty(); ByteArray result = encrypt(inp, &keyArr, ivec, pkcs5Padding); From 0d89dd1dafbc8395814c38f64f77d84d5abad5f5 Mon Sep 17 00:00:00 2001 From: mkhan Date: Thu, 8 Mar 2018 17:10:23 +1100 Subject: [PATCH 4/5] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f842ce..77de301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [Unreleased] +### Fixes +- Fixes issue 11 + ## [1.1.2] - 28-02-2018 ### Fixes - Fix crash with invalid msg from zlib From 2e5eacb2a459a72aed945d7428c65db5362c49a4 Mon Sep 17 00:00:00 2001 From: Majid Date: Thu, 8 Mar 2018 18:07:31 +1100 Subject: [PATCH 5/5] 1.1.3 --- CHANGELOG.md | 4 ++-- CMakeLists.txt | 6 +++--- build.php | 2 +- package/mine.cc | 18 ++++++++++++++++-- package/mine.h | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77de301..b64d0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Change Log -## [Unreleased] +## [1.1.3] - 08-03-2018 ### Fixes -- Fixes issue 11 +- Issue 11 - (AES) Invalid padding when input is equal to block size ## [1.1.2] - 28-02-2018 ### Fixes diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d1627e..fd8147d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,8 @@ option (test_main_header "Test main header (mine.h)" OFF) option (test_wstring_conversions "Test std::wstring (wchar_t*) conversions for encodings" ON) -set (MINE_VERSION "1.1.2") ## Also update build.php -set (MINE_SOVERSION "1.1.2") +set (MINE_VERSION "1.1.3") ## Also update build.php +set (MINE_SOVERSION "1.1.3") add_definitions (-DMINE_VERSION="${MINE_VERSION}") @@ -41,7 +41,7 @@ if (APPLE) endif() endif() -list (APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wunused -std=c++11 -O0 -L/usr/local/lib/ ") +list (APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wunused -std=c++11 -O3 -L/usr/local/lib/ ") # Check for cryptopp (static) set(CryptoPP_USE_STATIC_LIBS ON) diff --git a/build.php b/build.php index fa82e97..ff8e426 100644 --- a/build.php +++ b/build.php @@ -6,7 +6,7 @@ /// modules for ease of development /// -$lib_version = "1.1.2"; +$lib_version = "1.1.3"; $header_template = <<