Skip to content

Commit

Permalink
Merge pull request #12 from muflihun/develop
Browse files Browse the repository at this point in the history
1.1.3
  • Loading branch information
abumq authored Mar 8, 2018
2 parents b42558d + 2e5eacb commit 084d03c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [1.1.3] - 08-03-2018
### Fixes
- Issue 11 - (AES) Invalid padding when input is equal to block size

## [1.1.2] - 28-02-2018
### Fixes
- Fix crash with invalid msg from zlib
Expand Down
34 changes: 5 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion build.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// modules for ease of development
///

$lib_version = "1.1.2";
$lib_version = "1.1.3";

$header_template = <<<EOT
//
Expand Down
2 changes: 1 addition & 1 deletion cmake/Findgtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
endif()
18 changes: 16 additions & 2 deletions package/mine.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Bismillah ar-Rahmaan ar-Raheem
//
// Mine (1.1.2)
// Mine (1.1.3)
// Single header minimal cryptography library
//
// Copyright (c) 2017-present Muflihun Labs
Expand Down Expand Up @@ -31,7 +31,7 @@

using namespace mine;
#ifndef MINE_VERSION
#define MINE_VERSION "1.1.2"
#define MINE_VERSION "1.1.3"
#endif


Expand Down Expand Up @@ -998,6 +998,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);
}
Expand All @@ -1006,6 +1013,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);
Expand Down
2 changes: 1 addition & 1 deletion package/mine.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Bismillah ar-Rahmaan ar-Raheem
//
// Mine (1.1.2)
// Mine (1.1.3)
// Single header minimal cryptography library
//
// Copyright (c) 2017-present Muflihun Labs
Expand Down
14 changes: 14 additions & 0 deletions src/aes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions test/aes-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 084d03c

Please sign in to comment.