From a728d9db5bcb7482a04fa1d3935324418cc0a1c8 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 2 Jun 2014 10:05:04 -0400 Subject: [PATCH] explicit AESNI flag --- Makefile | 7 ++++++- aes.cpp | 14 +++++++------- aes.h | 7 +++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index a30b268c..149ade28 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,11 @@ INCFLAGS = LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem -lboost_regex -lboost_program_options -lpthread LIBS = +#check if AES-NI is supported by CPU +ifneq ($(shell grep -c aes /proc/cpuinfo),0) + CPU_FLAGS = -DAESNI +endif + all: obj i2p i2p: $(OBJECTS:obj/%=obj/%) @@ -20,7 +25,7 @@ i2p: $(OBJECTS:obj/%=obj/%) .SUFFIXES: .c .cc .C .cpp .o obj/%.o : %.cpp - $(CC) -o $@ $< -c $(CFLAGS) $(INCFLAGS) + $(CC) -o $@ $< -c $(CFLAGS) $(INCFLAGS) $(CPU_FLAGS) obj: mkdir -p obj diff --git a/aes.cpp b/aes.cpp index c4b1df17..a2114846 100644 --- a/aes.cpp +++ b/aes.cpp @@ -7,7 +7,7 @@ namespace i2p namespace crypto { -#ifdef __x86_64__ +#ifdef AESNI ECBCryptoAESNI::ECBCryptoAESNI () { @@ -167,7 +167,7 @@ namespace crypto void CBCEncryption::Encrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out) { -#ifdef __x86_64__ +#ifdef AESNI __asm__ ( "movups (%[iv]), %%xmm1 \n" @@ -207,7 +207,7 @@ namespace crypto void CBCEncryption::Encrypt (const uint8_t * in, uint8_t * out) { -#ifdef __x86_64__ +#ifdef AESNI __asm__ ( "movups (%[iv]), %%xmm1 \n" @@ -228,7 +228,7 @@ namespace crypto void CBCDecryption::Decrypt (int numBlocks, const ChipherBlock * in, ChipherBlock * out) { -#ifdef __x86_64__ +#ifdef AESNI __asm__ ( "movups (%[iv]), %%xmm1 \n" @@ -270,7 +270,7 @@ namespace crypto void CBCDecryption::Decrypt (const uint8_t * in, uint8_t * out) { -#ifdef __x86_64__ +#ifdef AESNI __asm__ ( "movups (%[iv]), %%xmm1 \n" @@ -291,7 +291,7 @@ namespace crypto void TunnelEncryption::Encrypt (uint8_t * payload) { -#ifdef __x86_64__ +#ifdef AESNI __asm__ ( // encrypt IV @@ -325,7 +325,7 @@ namespace crypto void TunnelDecryption::Decrypt (uint8_t * payload) { -#ifdef __x86_64__ +#ifdef AESNI __asm__ ( // decrypt IV diff --git a/aes.h b/aes.h index 46500d7f..c69764b4 100644 --- a/aes.h +++ b/aes.h @@ -21,8 +21,7 @@ namespace crypto } }; -#ifdef __x86_64__ - // AES-NI assumed +#ifdef AESNI class ECBCryptoAESNI { public: @@ -154,7 +153,7 @@ namespace crypto private: ECBEncryption m_IVEncryption; -#ifdef __x86_64__ +#ifdef AESNI ECBEncryption m_LayerEncryption; #else CBCEncryption m_LayerEncryption; @@ -176,7 +175,7 @@ namespace crypto private: ECBDecryption m_IVDecryption; -#ifdef __x86_64__ +#ifdef AESNI ECBDecryption m_LayerDecryption; #else CBCDecryption m_LayerDecryption;