From f752dfe56b67f2729df0c54c83612ba36f8133bc Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 25 Jun 2015 01:18:24 +0300 Subject: remove specialized buffer encryption functions --- utils/file/aes128ecb_encrypt_file.cpp | 103 ---------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 utils/file/aes128ecb_encrypt_file.cpp (limited to 'utils/file/aes128ecb_encrypt_file.cpp') 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 - * \date 2015 - * \copyright This file is licensed under the terms of the MIT License. - * See LICENSE.txt for details. - */ - -#include -#include - -#include - -#include -#include -#include -#include -#include - -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(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 src_buf; - src_buf.reserve(src_size); - src_buf.assign(std::istreambuf_iterator(src_ifs), - std::istreambuf_iterator()); - - 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 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; -} -- cgit v1.2.3