diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-25 01:18:24 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-25 01:18:24 +0300 |
commit | f752dfe56b67f2729df0c54c83612ba36f8133bc (patch) | |
tree | 9d392157a1d9ae0d112260c5dedc7ec535d38291 /utils/file | |
parent | cxx: implement more stuff (diff) | |
download | aes-tools-f752dfe56b67f2729df0c54c83612ba36f8133bc.tar.gz aes-tools-f752dfe56b67f2729df0c54c83612ba36f8133bc.zip |
remove specialized buffer encryption functions
Diffstat (limited to 'utils/file')
-rw-r--r-- | utils/file/CMakeLists.txt | 27 | ||||
-rw-r--r-- | utils/file/README.md (renamed from utils/file/cxx/README.md) | 0 | ||||
-rw-r--r-- | utils/file/aes128ecb_decrypt_file.cpp | 104 | ||||
-rw-r--r-- | utils/file/aes128ecb_encrypt_file.cpp | 103 | ||||
-rw-r--r-- | utils/file/aes_common.hpp (renamed from utils/file/cxx/aes_common.hpp) | 0 | ||||
-rw-r--r-- | utils/file/aes_decrypt_bmp.cpp (renamed from utils/file/cxx/aes_decrypt_bmp.cpp) | 0 | ||||
-rw-r--r-- | utils/file/aes_decrypt_file.cpp (renamed from utils/file/cxx/aes_decrypt_file.cpp) | 0 | ||||
-rw-r--r-- | utils/file/aes_encrypt_bmp.cpp (renamed from utils/file/cxx/aes_encrypt_bmp.cpp) | 0 | ||||
-rw-r--r-- | utils/file/aes_encrypt_file.cpp (renamed from utils/file/cxx/aes_encrypt_file.cpp) | 0 | ||||
-rw-r--r-- | utils/file/bmp/butterfly.bmp (renamed from utils/file/cxx/bmp/butterfly.bmp) | bin | 503370 -> 503370 bytes | |||
-rw-r--r-- | utils/file/bmp/cipherfly_cbc.bmp (renamed from utils/file/cxx/bmp/cipherfly_cbc.bmp) | bin | 503382 -> 503382 bytes | |||
-rw-r--r-- | utils/file/bmp/cipherfly_ecb.bmp (renamed from utils/file/cxx/bmp/cipherfly_ecb.bmp) | bin | 503382 -> 503382 bytes | |||
-rw-r--r-- | utils/file/cxx/CMakeLists.txt | 21 |
13 files changed, 19 insertions, 236 deletions
diff --git a/utils/file/CMakeLists.txt b/utils/file/CMakeLists.txt index ad949f7..75895a0 100644 --- a/utils/file/CMakeLists.txt +++ b/utils/file/CMakeLists.txt @@ -1,10 +1,21 @@ -macro(util prefix) - add_executable(util_${prefix} ${prefix}.cpp) - target_link_libraries(util_${prefix} libaesnixx libaesni) - set_target_properties(util_${prefix} PROPERTIES OUTPUT_NAME ${prefix}) -endmacro() +find_package(Boost REQUIRED COMPONENTS program_options) -util(aes128ecb_encrypt_file) -util(aes128ecb_decrypt_file) +add_executable(util_aes_encrypt_file aes_encrypt_file.cpp aes_common.hpp) +target_include_directories(util_aes_encrypt_file PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(util_aes_encrypt_file libaesni libaesnixx ${Boost_LIBRARIES}) +set_target_properties(util_aes_encrypt_file PROPERTIES OUTPUT_NAME aes_encrypt_file) -add_subdirectory(cxx) +add_executable(util_aes_decrypt_file aes_decrypt_file.cpp aes_common.hpp) +target_include_directories(util_aes_decrypt_file PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(util_aes_decrypt_file libaesni libaesnixx ${Boost_LIBRARIES}) +set_target_properties(util_aes_decrypt_file PROPERTIES OUTPUT_NAME aes_decrypt_file) + +add_executable(util_aes_encrypt_bmp aes_encrypt_bmp.cpp aes_common.hpp) +target_include_directories(util_aes_encrypt_bmp PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(util_aes_encrypt_bmp libaesni libaesnixx ${Boost_LIBRARIES}) +set_target_properties(util_aes_encrypt_bmp PROPERTIES OUTPUT_NAME aes_encrypt_bmp) + +add_executable(util_aes_decrypt_bmp aes_decrypt_bmp.cpp aes_common.hpp) +target_include_directories(util_aes_decrypt_bmp PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(util_aes_decrypt_bmp libaesni libaesnixx ${Boost_LIBRARIES}) +set_target_properties(util_aes_decrypt_bmp PROPERTIES OUTPUT_NAME aes_decrypt_bmp) diff --git a/utils/file/cxx/README.md b/utils/file/README.md index bf79cb2..bf79cb2 100644 --- a/utils/file/cxx/README.md +++ b/utils/file/README.md diff --git a/utils/file/aes128ecb_decrypt_file.cpp b/utils/file/aes128ecb_decrypt_file.cpp deleted file mode 100644 index 9b8b15c..0000000 --- a/utils/file/aes128ecb_decrypt_file.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/** - * \file - * \author Egor Tensin <Egor.Tensin@gmail.com> - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include <aesni/all.h> -#include <aesnixx/all.hpp> - -#include <cstdlib> - -#include <exception> -#include <iostream> -#include <fstream> -#include <string> -#include <vector> - -namespace -{ - void exit_with_usage() - { - std::cout << "Usage: aes128ecb_decrypt_file.exe KEY SRC DEST\n"; - std::exit(EXIT_FAILURE); - } - - std::ifstream::pos_type get_file_size(const std::string& path) - { - std::ifstream ifs; - ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); - ifs.open(path, std::ifstream::binary | std::ifstream::ate); - return ifs.tellg(); - } -} - -int main(int argc, char** argv) -{ - if (argc != 4) - exit_with_usage(); - - try - { - aesni::aes::Key128 key; - aesni::aes::from_string(key, argv[1]); - - aesni::aes::RoundKeys128 encryption_keys, decryption_keys; - - const std::string src_path(argv[2]); - const std::string dest_path(argv[3]); - - const auto src_size = static_cast<std::size_t>(get_file_size(src_path)); - - std::ifstream src_ifs; - src_ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); - src_ifs.open(src_path, std::ifstream::binary); - - std::vector<char> src_buf; - src_buf.reserve(src_size); - src_buf.assign(std::istreambuf_iterator<char>(src_ifs), - std::istreambuf_iterator<char>()); - - aesni_aes128_expand_key(&key, &encryption_keys); - aesni_aes128_derive_decryption_keys(&encryption_keys, &decryption_keys); - - std::size_t dest_size; - - aesni_decrypt_buffer_ecb128( - src_buf.data(), - src_size, - NULL, - &dest_size, - &decryption_keys, - aesni::ErrorDetailsThrowsInDestructor()); - - std::vector<char> dest_buf; - dest_buf.reserve(dest_size); - - aesni_decrypt_buffer_ecb128( - src_buf.data(), - src_size, - dest_buf.data(), - &dest_size, - &decryption_keys, - aesni::ErrorDetailsThrowsInDestructor()); - - std::ofstream dest_ofs; - dest_ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit); - dest_ofs.open(dest_path, std::ofstream::binary); - dest_ofs.write(dest_buf.data(), dest_size); - } - catch (const aesni::Error& e) - { - std::cerr << e; - return 1; - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - - return 0; -} diff --git a/utils/file/aes128ecb_encrypt_file.cpp b/utils/file/aes128ecb_encrypt_file.cpp deleted file mode 100644 index a43c4d9..0000000 --- a/utils/file/aes128ecb_encrypt_file.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/** - * \file - * \author Egor Tensin <Egor.Tensin@gmail.com> - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include <aesni/all.h> -#include <aesnixx/all.hpp> - -#include <cstdlib> - -#include <exception> -#include <iostream> -#include <fstream> -#include <string> -#include <vector> - -namespace -{ - void exit_with_usage() - { - std::cout << "Usage: aes128ecb_encrypt_file.exe KEY SRC DEST\n"; - std::exit(EXIT_FAILURE); - } - - std::ifstream::pos_type get_file_size(const std::string& path) - { - std::ifstream ifs; - ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); - ifs.open(path, std::ifstream::binary | std::ifstream::ate); - return ifs.tellg(); - } -} - -int main(int argc, char** argv) -{ - if (argc != 4) - exit_with_usage(); - - try - { - aesni::aes::Key128 key; - aesni::aes::from_string(key, argv[1]); - - AesNI_Aes128_RoundKeys encryption_keys; - - const std::string src_path(argv[2]); - const std::string dest_path(argv[3]); - - const auto src_size = static_cast<std::size_t>(get_file_size(src_path)); - - std::ifstream src_ifs; - src_ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); - src_ifs.open(src_path, std::ifstream::binary); - - std::vector<char> src_buf; - src_buf.reserve(src_size); - src_buf.assign(std::istreambuf_iterator<char>(src_ifs), - std::istreambuf_iterator<char>()); - - aesni_aes128_expand_key(&key, &encryption_keys); - - std::size_t dest_size; - - aesni_encrypt_buffer_ecb128( - src_buf.data(), - src_size, - NULL, - &dest_size, - &encryption_keys, - aesni::ErrorDetailsThrowsInDestructor()); - - std::vector<char> dest_buf; - dest_buf.reserve(dest_size); - - aesni_encrypt_buffer_ecb128( - src_buf.data(), - src_size, - dest_buf.data(), - &dest_size, - &encryption_keys, - aesni::ErrorDetailsThrowsInDestructor()); - - std::ofstream dest_ofs; - dest_ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit); - dest_ofs.open(dest_path, std::ofstream::binary); - dest_ofs.write(dest_buf.data(), dest_size); - } - catch (const aesni::Error& e) - { - std::cerr << e; - return 1; - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - - return 0; -} diff --git a/utils/file/cxx/aes_common.hpp b/utils/file/aes_common.hpp index 28e16df..28e16df 100644 --- a/utils/file/cxx/aes_common.hpp +++ b/utils/file/aes_common.hpp diff --git a/utils/file/cxx/aes_decrypt_bmp.cpp b/utils/file/aes_decrypt_bmp.cpp index 85dffe5..85dffe5 100644 --- a/utils/file/cxx/aes_decrypt_bmp.cpp +++ b/utils/file/aes_decrypt_bmp.cpp diff --git a/utils/file/cxx/aes_decrypt_file.cpp b/utils/file/aes_decrypt_file.cpp index e2da979..e2da979 100644 --- a/utils/file/cxx/aes_decrypt_file.cpp +++ b/utils/file/aes_decrypt_file.cpp diff --git a/utils/file/cxx/aes_encrypt_bmp.cpp b/utils/file/aes_encrypt_bmp.cpp index cf55b0b..cf55b0b 100644 --- a/utils/file/cxx/aes_encrypt_bmp.cpp +++ b/utils/file/aes_encrypt_bmp.cpp diff --git a/utils/file/cxx/aes_encrypt_file.cpp b/utils/file/aes_encrypt_file.cpp index ff6753f..ff6753f 100644 --- a/utils/file/cxx/aes_encrypt_file.cpp +++ b/utils/file/aes_encrypt_file.cpp diff --git a/utils/file/cxx/bmp/butterfly.bmp b/utils/file/bmp/butterfly.bmp Binary files differindex 105a55a..105a55a 100644 --- a/utils/file/cxx/bmp/butterfly.bmp +++ b/utils/file/bmp/butterfly.bmp diff --git a/utils/file/cxx/bmp/cipherfly_cbc.bmp b/utils/file/bmp/cipherfly_cbc.bmp Binary files differindex 664b557..664b557 100644 --- a/utils/file/cxx/bmp/cipherfly_cbc.bmp +++ b/utils/file/bmp/cipherfly_cbc.bmp diff --git a/utils/file/cxx/bmp/cipherfly_ecb.bmp b/utils/file/bmp/cipherfly_ecb.bmp Binary files differindex 78de9a8..78de9a8 100644 --- a/utils/file/cxx/bmp/cipherfly_ecb.bmp +++ b/utils/file/bmp/cipherfly_ecb.bmp diff --git a/utils/file/cxx/CMakeLists.txt b/utils/file/cxx/CMakeLists.txt deleted file mode 100644 index 75895a0..0000000 --- a/utils/file/cxx/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -find_package(Boost REQUIRED COMPONENTS program_options) - -add_executable(util_aes_encrypt_file aes_encrypt_file.cpp aes_common.hpp) -target_include_directories(util_aes_encrypt_file PRIVATE ${Boost_INCLUDE_DIRS}) -target_link_libraries(util_aes_encrypt_file libaesni libaesnixx ${Boost_LIBRARIES}) -set_target_properties(util_aes_encrypt_file PROPERTIES OUTPUT_NAME aes_encrypt_file) - -add_executable(util_aes_decrypt_file aes_decrypt_file.cpp aes_common.hpp) -target_include_directories(util_aes_decrypt_file PRIVATE ${Boost_INCLUDE_DIRS}) -target_link_libraries(util_aes_decrypt_file libaesni libaesnixx ${Boost_LIBRARIES}) -set_target_properties(util_aes_decrypt_file PROPERTIES OUTPUT_NAME aes_decrypt_file) - -add_executable(util_aes_encrypt_bmp aes_encrypt_bmp.cpp aes_common.hpp) -target_include_directories(util_aes_encrypt_bmp PRIVATE ${Boost_INCLUDE_DIRS}) -target_link_libraries(util_aes_encrypt_bmp libaesni libaesnixx ${Boost_LIBRARIES}) -set_target_properties(util_aes_encrypt_bmp PROPERTIES OUTPUT_NAME aes_encrypt_bmp) - -add_executable(util_aes_decrypt_bmp aes_decrypt_bmp.cpp aes_common.hpp) -target_include_directories(util_aes_decrypt_bmp PRIVATE ${Boost_INCLUDE_DIRS}) -target_link_libraries(util_aes_decrypt_bmp libaesni libaesnixx ${Boost_LIBRARIES}) -set_target_properties(util_aes_decrypt_bmp PROPERTIES OUTPUT_NAME aes_decrypt_bmp) |