aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt11
-rw-r--r--cxx/CMakeLists.txt4
-rw-r--r--cxx/include/aesxx/api.hpp12
-rw-r--r--src/box.c6
-rw-r--r--src/error.c47
-rw-r--r--utils/block_dumper.hpp8
-rw-r--r--utils/decrypt_block.cpp10
-rw-r--r--utils/decrypt_bmp.cpp12
-rw-r--r--utils/decrypt_file.cpp12
-rw-r--r--utils/encrypt_block.cpp8
-rw-r--r--utils/encrypt_bmp.cpp12
-rw-r--r--utils/encrypt_file.cpp12
12 files changed, 92 insertions, 62 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 57398a2..1c16efd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,15 +1,24 @@
-project(aes_tools C CXX ASM_MASM)
+project(aes_tools)
file(GLOB_RECURSE libaes_headers "include/*.h")
+
if(LIBAES_USE_ASM)
+ enable_language(ASM_MASM)
+
file(GLOB libaes_c_sources "src/*.c")
file(GLOB libaes_asm_sources "src/asm/*.asm")
+
set(libaes_sources ${libaes_asm_sources} ${libaes_c_sources})
set_source_files_properties(${libaes_asm_sources} PROPERTIES COMPILE_FLAGS "/safeseh")
# Setting CMAKE_ASM_MASM_FLAGS doesn't work: http://www.cmake.org/Bug/view.php?id=14711
else()
file(GLOB_RECURSE libaes_sources "src/*.c")
endif()
+
+if(CMAKE_COMPILER_IS_GNUCC)
+ add_compile_options(-mssse3 -maes)
+endif()
+
add_library(libaes ${libaes_sources} ${libaes_headers})
target_include_directories(libaes PUBLIC include/)
target_compile_definitions(libaes PRIVATE _CRT_SECURE_NO_WARNINGS)
diff --git a/cxx/CMakeLists.txt b/cxx/CMakeLists.txt
index 418f004..97cb9a5 100644
--- a/cxx/CMakeLists.txt
+++ b/cxx/CMakeLists.txt
@@ -3,3 +3,7 @@ find_package(Boost REQUIRED)
add_library(libaesxx INTERFACE)
target_include_directories(libaesxx INTERFACE include/ ${Boost_INCLUDE_DIRS})
target_link_libraries(libaesxx INTERFACE libaes)
+
+if(CMAKE_COMPILER_IS_GNUCC)
+ target_compile_options(libaesxx INTERFACE -std=c++11)
+endif()
diff --git a/cxx/include/aesxx/api.hpp b/cxx/include/aesxx/api.hpp
index 0b183a8..bfe453c 100644
--- a/cxx/include/aesxx/api.hpp
+++ b/cxx/include/aesxx/api.hpp
@@ -69,20 +69,20 @@ namespace aes
const typename Types<algorithm>::RoundKeys& encryption_keys,
typename Types<algorithm>::RoundKeys& decryption_keys);
- template <Algorithm algorithm, Mode mode, typename std::enable_if<ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <Algorithm algorithm, Mode mode, typename std::enable_if<ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
inline void encrypt_block(
const typename Types<algorithm>::Block& plaintext,
const typename Types<algorithm>::RoundKeys& round_keys,
typename Types<algorithm>::Block& iv,
typename Types<algorithm>::Block& ciphertext);
- template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
inline void encrypt_block(
const typename Types<algorithm>::Block& plaintext,
const typename Types<algorithm>::RoundKeys& round_keys,
typename Types<algorithm>::Block& ciphertext);
- template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
inline void encrypt_block(
const typename Types<algorithm>::Block& plaintext,
const typename Types<algorithm>::RoundKeys& round_keys,
@@ -92,20 +92,20 @@ namespace aes
encrypt_block<algorithm, mode>(plaintext, round_keys, ciphertext);
}
- template <Algorithm algorithm, Mode mode, typename std::enable_if<ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <Algorithm algorithm, Mode mode, typename std::enable_if<ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
inline void decrypt_block(
const typename Types<algorithm>::Block& ciphertext,
const typename Types<algorithm>::RoundKeys& round_keys,
typename Types<algorithm>::Block& iv,
typename Types<algorithm>::Block& plaintext);
- template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
inline void decrypt_block(
const typename Types<algorithm>::Block& ciphertext,
const typename Types<algorithm>::RoundKeys& round_keys,
typename Types<algorithm>::Block& plaintext);
- template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <Algorithm algorithm, Mode mode, typename std::enable_if<!ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
inline void decrypt_block(
const typename Types<algorithm>::Block& ciphertext,
const typename Types<algorithm>::RoundKeys& round_keys,
diff --git a/src/box.c b/src/box.c
index ca5479e..6ba833d 100644
--- a/src/box.c
+++ b/src/box.c
@@ -429,7 +429,8 @@ AES_StatusCode aes_box_encrypt_buffer(
box, src, dest, err_details)))
return status;
- (char*) src += block_size, (char*) dest += block_size;
+ src = (char*) src + block_size;
+ dest = (char*) dest + block_size;
}
if (padding_size == 0)
@@ -596,7 +597,8 @@ AES_StatusCode aes_box_decrypt_buffer(
box, src, dest, err_details)))
return status;
- (char*) src += block_size, (char*) dest += block_size;
+ src = (char*) src + block_size;
+ dest = (char*) dest + block_size;
}
if (max_padding_size == 0)
diff --git a/src/error.c b/src/error.c
index 15b2aeb..d5dec0b 100644
--- a/src/error.c
+++ b/src/error.c
@@ -13,6 +13,38 @@
#include <stdlib.h>
#include <string.h>
+#if defined(_MSC_VER) && _MSC_VER < 1900
+
+#include <stdarg.h>
+
+#define snprintf c99_snprintf
+#define vsnprintf c99_vsnprintf
+
+__inline int c99_vsnprintf(char *dest, size_t dest_size, const char *fmt, va_list ap)
+{
+ int dest_len = -1;
+
+ if (dest_size != 0)
+ dest_len = _vsnprintf_s(dest, dest_size, _TRUNCATE, fmt, ap);
+ if (dest_len == -1)
+ dest_len = _vscprintf(fmt, ap);
+
+ return dest_len;
+}
+
+__inline int c99_snprintf(char *dest, size_t dest_size, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+
+ int dest_len = c99_vsnprintf(dest, dest_size, fmt, ap);
+
+ va_end(ap);
+ return dest_len;
+}
+
+#endif
+
static void aes_fill_string(char* dest, size_t dest_size, const char* src)
{
strncpy(dest, src, dest_size);
@@ -59,9 +91,9 @@ static size_t aes_format_null_argument_error(
const char* const param_name = err_details->params.null_arg.param_name;
if (dest == NULL && dest_size == 0)
- return _snprintf(NULL, 0, fmt, param_name) + 1;
+ return snprintf(NULL, 0, fmt, param_name) + 1;
- _snprintf(dest, dest_size, fmt, param_name);
+ snprintf(dest, dest_size, fmt, param_name);
return strlen(dest);
}
@@ -75,9 +107,9 @@ static size_t aes_format_parse_error(
const char* const what = err_details->params.parse_error.what;
if (dest == NULL)
- return _snprintf(NULL, 0, fmt, src, what) + 1;
+ return snprintf(NULL, 0, fmt, src, what) + 1;
- _snprintf(dest, dest_size, fmt, src, what);
+ snprintf(dest, dest_size, fmt, src, what);
return strlen(dest);
}
@@ -90,9 +122,9 @@ static size_t aes_format_not_implemented_error(
const char* const src = err_details->params.not_implemented.what;
if (dest == NULL)
- return _snprintf(NULL, 0, fmt, src) + 1;
+ return snprintf(NULL, 0, fmt, src) + 1;
- _snprintf(dest, dest_size, fmt, src);
+ snprintf(dest, dest_size, fmt, src);
return strlen(dest);
}
@@ -124,7 +156,8 @@ size_t aes_format_error(
static void aes_collect_call_stack(AES_ErrorDetails* err_details)
{
- err_details->call_stack_size = CaptureStackBackTrace(1, AES_MAX_CALL_STACK_LENGTH, err_details->call_stack, NULL);
+ err_details->call_stack_size = CaptureStackBackTrace(
+ 1, AES_MAX_CALL_STACK_LENGTH, err_details->call_stack, NULL);
}
#else
static void aes_collect_call_stack(AES_ErrorDetails* err_details)
diff --git a/utils/block_dumper.hpp b/utils/block_dumper.hpp
index d2b76bf..d344cda 100644
--- a/utils/block_dumper.hpp
+++ b/utils/block_dumper.hpp
@@ -82,26 +82,26 @@ namespace
dump_decryption_keys<algorithm>(wrapper.decryption_keys);
}
- template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
void dump_next_iv(
const aes::EncryptWrapper<algorithm, mode>& wrapper)
{
dump_block<algorithm>("Next initialization vector", wrapper.iv);
}
- template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
void dump_next_iv(
const aes::EncryptWrapper<algorithm, mode>&)
{ }
- template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<aes::ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
void dump_next_iv(
const aes::DecryptWrapper<algorithm, mode>& wrapper)
{
dump_block<algorithm>("Next initialization vector", wrapper.iv);
}
- template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitializationVector<mode>::value>::type* = 0>
+ template <aes::Algorithm algorithm, aes::Mode mode, typename std::enable_if<!aes::ModeRequiresInitializationVector<mode>::value>::type* = nullptr>
void dump_next_iv(
const aes::DecryptWrapper<algorithm, mode>&)
{ }
diff --git a/utils/decrypt_block.cpp b/utils/decrypt_block.cpp
index 2029669..6cc9c0a 100644
--- a/utils/decrypt_block.cpp
+++ b/utils/decrypt_block.cpp
@@ -151,16 +151,14 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, input.get_iv_string());
+ aes::Box box{ algorithm, key, mode, iv };
- decrypt_using_particular_box(
- aes::Box(algorithm, key, mode, iv),
- input.get_input_block_strings());
+ decrypt_using_particular_box(box, input.get_input_block_strings());
}
else
{
- decrypt_using_particular_box(
- aes::Box(algorithm, key),
- input.get_input_block_strings());
+ aes::Box box{ algorithm, key };
+ decrypt_using_particular_box(box, input.get_input_block_strings());
}
}
}
diff --git a/utils/decrypt_bmp.cpp b/utils/decrypt_bmp.cpp
index f098017..1e286e6 100644
--- a/utils/decrypt_bmp.cpp
+++ b/utils/decrypt_bmp.cpp
@@ -98,18 +98,14 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
+ aes::Box box{ algorithm, key, mode, iv };
- decrypt_bmp(
- aes::Box(algorithm, key, mode, iv),
- ciphertext_path,
- plaintext_path);
+ decrypt_bmp(box, ciphertext_path, plaintext_path);
}
else
{
- decrypt_bmp(
- aes::Box(algorithm, key),
- ciphertext_path,
- plaintext_path);
+ aes::Box box{ algorithm, key };
+ decrypt_bmp(box, ciphertext_path, plaintext_path);
}
}
}
diff --git a/utils/decrypt_file.cpp b/utils/decrypt_file.cpp
index 33083b7..cd955bb 100644
--- a/utils/decrypt_file.cpp
+++ b/utils/decrypt_file.cpp
@@ -83,18 +83,14 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
+ aes::Box box{ algorithm, key, mode, iv };
- decrypt_file(
- aes::Box(algorithm, key, mode, iv),
- ciphertext_path,
- plaintext_path);
+ decrypt_file(box, ciphertext_path, plaintext_path);
}
else
{
- decrypt_file(
- aes::Box(algorithm, key),
- ciphertext_path,
- plaintext_path);
+ aes::Box box{ algorithm, key };
+ decrypt_file(box, ciphertext_path, plaintext_path);
}
}
}
diff --git a/utils/encrypt_block.cpp b/utils/encrypt_block.cpp
index ac6a45a..da33612 100644
--- a/utils/encrypt_block.cpp
+++ b/utils/encrypt_block.cpp
@@ -151,14 +151,14 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, input.get_iv_string());
+ aes::Box box{ algorithm, key, mode, iv };
- encrypt_using_particular_box(
- aes::Box(algorithm, key, mode, iv), input.get_input_block_strings());
+ encrypt_using_particular_box(box, input.get_input_block_strings());
}
else
{
- encrypt_using_particular_box(
- aes::Box(algorithm, key), input.get_input_block_strings());
+ aes::Box box{ algorithm, key };
+ encrypt_using_particular_box(box, input.get_input_block_strings());
}
}
}
diff --git a/utils/encrypt_bmp.cpp b/utils/encrypt_bmp.cpp
index 086e14d..67ec412 100644
--- a/utils/encrypt_bmp.cpp
+++ b/utils/encrypt_bmp.cpp
@@ -98,18 +98,14 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
+ aes::Box box{ algorithm, key, mode, iv };
- encrypt_bmp(
- aes::Box(algorithm, key, mode, iv),
- plaintext_path,
- ciphertext_path);
+ encrypt_bmp(box, plaintext_path, ciphertext_path);
}
else
{
- encrypt_bmp(
- aes::Box(algorithm, key),
- plaintext_path,
- ciphertext_path);
+ aes::Box box{ algorithm, key };
+ encrypt_bmp(box, plaintext_path, ciphertext_path);
}
}
}
diff --git a/utils/encrypt_file.cpp b/utils/encrypt_file.cpp
index 9a3dda8..4161e92 100644
--- a/utils/encrypt_file.cpp
+++ b/utils/encrypt_file.cpp
@@ -83,18 +83,14 @@ namespace
{
aes::Box::Block iv;
aes::Box::parse_block(iv, algorithm, settings.get_iv_string());
+ aes::Box box{ algorithm, key, mode, iv };
- encrypt_file(
- aes::Box(algorithm, key, mode, iv),
- plaintext_path,
- ciphertext_path);
+ encrypt_file(box, plaintext_path, ciphertext_path);
}
else
{
- encrypt_file(
- aes::Box(algorithm, key),
- plaintext_path,
- ciphertext_path);
+ aes::Box box{ algorithm, key };
+ encrypt_file(box, plaintext_path, ciphertext_path);
}
}
}