explicit AESNI flag

This commit is contained in:
orignal 2014-06-02 10:05:04 -04:00
parent 6518727270
commit a728d9db5b
3 changed files with 16 additions and 12 deletions

View File

@ -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

14
aes.cpp
View File

@ -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

7
aes.h
View File

@ -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;