Skip to content

Commit

Permalink
Use target attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim van der Molen committed Jun 29, 2024
1 parent 3617882 commit 4b0c860
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 0 additions & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 0 additions & 4 deletions makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions makefile.shared
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<

Expand Down
4 changes: 0 additions & 4 deletions makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/ciphers/aes/aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4b0c860

Please sign in to comment.