From 83f29da294c05c99aba06dfa7a5a095326a1d101 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 13 Jul 2015 14:38:16 -1000 Subject: [PATCH] MSVC AES-NI support --- include/NOD/Util.hpp | 13 ++++++++----- lib/aes.cpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/NOD/Util.hpp b/include/NOD/Util.hpp index 46127d6..0541943 100644 --- a/include/NOD/Util.hpp +++ b/include/NOD/Util.hpp @@ -1,6 +1,14 @@ #ifndef __NOD_UTIL_HPP__ #define __NOD_UTIL_HPP__ +#if _WIN32 && UNICODE +#include +#include +#else +#include +#endif +#include + #include #include #include @@ -13,16 +21,11 @@ extern LogVisor::LogModule LogModule; /* filesystem char type */ #if _WIN32 && UNICODE -#include -#include -#include #define NOD_UCS2 1 typedef struct _stat Sstat; static inline int Mkdir(const wchar_t* path, int) {return _wmkdir(path);} static inline int Stat(const wchar_t* path, Sstat* statout) {return _wstat(path, statout);} #else -#include -#include typedef struct stat Sstat; static inline int Mkdir(const char* path, mode_t mode) {return mkdir(path, mode);} static inline int Stat(const char* path, Sstat* statout) {return stat(path, statout);} diff --git a/lib/aes.cpp b/lib/aes.cpp index 26109b2..68cc785 100644 --- a/lib/aes.cpp +++ b/lib/aes.cpp @@ -478,7 +478,7 @@ void SoftwareAES::encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outb } } -#if __AES__ +#if __AES__ || _MSC_VER >= 1800 #include @@ -598,12 +598,18 @@ public: static int HAS_AES_NI = -1; std::unique_ptr NewAES() { -#if __AES__ +#if __AES__ || _MSC_VER >= 1800 if (HAS_AES_NI == -1) { +#if _MSC_VER + int info[4]; + __cpuid(info, 1); + HAS_AES_NI = ((info[2] & 0x2000000) != 0); +#else unsigned int a,b,c,d; __cpuid(1, a,b,c,d); HAS_AES_NI = ((c & 0x2000000) != 0); +#endif } if (HAS_AES_NI) return std::unique_ptr(new NiAES);