From 4b0c860aa55c010c60a3a634470bd037a56c3e54 Mon Sep 17 00:00:00 2001 From: Tim van der Molen Date: Sat, 29 Jun 2024 19:43:19 +0200 Subject: [PATCH] Use target attributes --- README.md | 4 ++-- makefile | 7 ------- makefile.mingw | 4 ---- makefile.msvc | 4 ---- makefile.shared | 4 ---- makefile.unix | 4 ---- src/ciphers/aes/aesni.c | 7 +++++++ 7 files changed, 9 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 599459548..661fdbcce 100644 --- a/README.md +++ b/README.md @@ -150,9 +150,9 @@ If you have `libtommath` in a non-standard location: make CFLAGS="-DUSE_LTM -DLTM_DESC -I/opt/devel/ltm" EXTRALIBS="/opt/devel/ltm/libtommath.a" all -You want to enable AES-NI support, but compile the rest of the library without the requirement for SSE4.1: +You want to enable AES-NI support: - make CFLAGS=-DLTC_AES_NI CFLAGS_AES_NI="-maes -msse4.1" + make CFLAGS=-DLTC_AES_NI ## Installation diff --git a/makefile b/makefile index be847b759..2d038207e 100644 --- a/makefile +++ b/makefile @@ -56,13 +56,6 @@ ifneq ($V,1) endif ${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@ -#AES-NI support requires special compiler flags -src/ciphers/aes/aesni.o: src/ciphers/aes/aesni.c -ifneq ($V,1) - @echo " * ${CC} $@" ${silent_echo} -endif - ${silent} ${CC} ${LTC_CFLAGS} ${CFLAGS_AES_NI} -c $< -o $@ - .c.o: ifneq ($V,1) @echo " * ${CC} $@" ${silent_echo} diff --git a/makefile.mingw b/makefile.mingw index a53d4bccb..4c9af5946 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -250,10 +250,6 @@ src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/aes/aes_enc_desc.o: src/ciphers/aes/aes.c $(CC) $(LTC_CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o -#SPECIAL: AES-NI support requires special compiler flags -src/ciphers/aes/aesni.o: src/ciphers/aes/aesni.c - $(CC) $(LTC_CFLAGS) $(CFLAGS_AES_NI) -c src/ciphers/aes/aesni.c -o src/ciphers/aes/aesni.o - #SPECIAL: these are the rules to make certain object files src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c diff --git a/makefile.msvc b/makefile.msvc index 3fd839d5c..ad65eb698 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -243,10 +243,6 @@ src/ciphers/aes/aes_enc.obj: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/aes/aes_enc_desc.obj: src/ciphers/aes/aes_desc.c $(CC) $(LTC_CFLAGS) /DENCRYPT_ONLY /c src/ciphers/aes/aes_desc.c /Fosrc/ciphers/aes/aes_enc_desc.obj -#SPECIAL: AES-NI support requires special compiler flags -src/ciphers/aes/aesni.obj: src/ciphers/aes/aesni.c - $(CC) $(LTC_CFLAGS) $(CFLAGS_AES_NI) /c src/ciphers/aes/aesni.c /Fosrc/ciphers/aes/aesni.obj - #SPECIAL: these are the rules to make certain object files src/ciphers/aes/aes.obj: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/twofish/twofish.obj: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c diff --git a/makefile.shared b/makefile.shared index 795bd3e5d..310840c99 100644 --- a/makefile.shared +++ b/makefile.shared @@ -73,10 +73,6 @@ src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/aes/aes_enc_desc.o: src/ciphers/aes/aes_desc.c $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o -#AES-NI support requires special compiler flags -src/ciphers/aes/aesni.o: src/ciphers/aes/aesni.c - $(LTCOMPILE) $(LTC_CFLAGS) $(CFLAGS_AES_NI) $(CPPFLAGS) $(LTC_LDFLAGS) -c src/ciphers/aes/aesni.c -o src/ciphers/aes/aesni.o - .c.o: $(LTCOMPILE) $(LTC_CFLAGS) $(CPPFLAGS) $(LTC_LDFLAGS) -o $@ -c $< diff --git a/makefile.unix b/makefile.unix index 226066148..a46736c28 100644 --- a/makefile.unix +++ b/makefile.unix @@ -264,10 +264,6 @@ src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/aes/aes_enc_desc.o: src/ciphers/aes/aes_desc.c $(CC) $(LTC_CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes_desc.c -o src/ciphers/aes/aes_enc_desc.o -#SPECIAL: AES-NI support requires special compiler flags -src/ciphers/aes/aesni.o: src/ciphers/aes/aesni.c - $(CC) $(LTC_CFLAGS) $(CFLAGS_AES_NI) -c src/ciphers/aes/aesni.c -o src/ciphers/aes/aesni.o - #SPECIAL: these are the rules to make certain object files src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c diff --git a/src/ciphers/aes/aesni.c b/src/ciphers/aes/aesni.c index 2a5f95af5..a0d02d98a 100644 --- a/src/ciphers/aes/aesni.c +++ b/src/ciphers/aes/aesni.c @@ -11,6 +11,10 @@ #if defined(LTC_AES_NI) +#if !(defined(__GNUC__) || defined(__clang__)) +#define __attribute__() +#endif + const struct ltc_cipher_descriptor aesni_desc = { "aes", @@ -42,6 +46,7 @@ static const ulong32 rcon[] = { @param skey The key in as scheduled by this function. @return CRYPT_OK if successful */ +__attribute__((__target__("aes,sse4.1"))) int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) { int i; @@ -168,6 +173,7 @@ int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ @param skey The key as scheduled @return CRYPT_OK if successful */ +__attribute__((__target__("aes"))) #ifdef LTC_CLEAN_STACK static int s_aesni_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey) #else @@ -219,6 +225,7 @@ int aesni_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetri @param skey The key as scheduled @return CRYPT_OK if successful */ +__attribute__((__target__("aes"))) #ifdef LTC_CLEAN_STACK static int s_aesni_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey) #else