mirror of
https://github.com/libtom/libtomcrypt
synced 2026-08-25 20:26:07 -04:00
Create ENCRYPT_ONLY descriptors in amalgamated build.
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
parent
3520a0fcf5
commit
f940880a67
5 changed files with 28 additions and 11 deletions
4
makefile
4
makefile
|
|
@ -156,6 +156,10 @@ pre_gen/tomcrypt_amalgam.c: $(TAB_SOURCES) $(SOURCES)
|
|||
printf "#define LTC_WHIRLTAB_C\n\n" >> $@
|
||||
printf "#include \"tomcrypt_private.h\"\n\n" >> $@
|
||||
cat $^ >> $@
|
||||
printf "#define ENCRYPT_ONLY\n\n" >> $@
|
||||
cat src/ciphers/aes/aes.c >> $@
|
||||
cat src/ciphers/aes/aes_desc.c >> $@
|
||||
printf "#undef ENCRYPT_ONLY\n\n" >> $@
|
||||
|
||||
pre_gen: pre_gen/tomcrypt_amalgam.c
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ const struct ltc_cipher_descriptor rijndael_enc_desc =
|
|||
#include "aes_tab.c"
|
||||
#endif
|
||||
|
||||
#define setup_mix rijndael_setup_mix
|
||||
|
||||
#ifndef RIJNDAEL_SETUP_MIX
|
||||
#define RIJNDAEL_SETUP_MIX
|
||||
static ulong32 setup_mix(ulong32 temp)
|
||||
{
|
||||
return (Te4_3[LTC_BYTE(temp, 2)]) ^
|
||||
|
|
@ -74,9 +78,9 @@ static ulong32 setup_mix(ulong32 temp)
|
|||
(Te4_1[LTC_BYTE(temp, 0)]) ^
|
||||
(Te4_0[LTC_BYTE(temp, 3)]);
|
||||
}
|
||||
#endif /* RIJNDAEL_SETUP_MIX */
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
#ifdef LTC_SMALL_CODE
|
||||
#if !defined(ENCRYPT_ONLY) && defined(LTC_SMALL_CODE)
|
||||
static ulong32 setup_mix2(ulong32 temp)
|
||||
{
|
||||
return Td0(255 & Te4[LTC_BYTE(temp, 3)]) ^
|
||||
|
|
@ -84,7 +88,6 @@ static ulong32 setup_mix2(ulong32 temp)
|
|||
Td2(255 & Te4[LTC_BYTE(temp, 1)]) ^
|
||||
Td3(255 & Te4[LTC_BYTE(temp, 0)]);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -728,6 +731,7 @@ int ECB_KS(int *keysize)
|
|||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#undef setup_mix
|
||||
#undef SETUP
|
||||
#undef ECB_ENC
|
||||
#undef ECB_DEC
|
||||
|
|
|
|||
|
|
@ -272,6 +272,8 @@ int AES_KS(int *keysize)
|
|||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#undef AES_SETUP
|
||||
#undef AES_ENC
|
||||
#undef AES_DEC
|
||||
|
|
@ -279,5 +281,3 @@ int AES_KS(int *keysize)
|
|||
#undef AES_TEST
|
||||
#undef AES_KS
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ const struct ltc_cipher_descriptor aesni_desc =
|
|||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#define setup_mix(t, c) _mm_extract_epi32(_mm_aeskeygenassist_si128(t, 0), c)
|
||||
#define aesni_setup_mix(t, c) _mm_extract_epi32(_mm_aeskeygenassist_si128(t, 0), c)
|
||||
#define temp_load(k) _mm_loadu_si128((__m128i*)(k))
|
||||
#define temp_update(t, k) _mm_insert_epi32(t, k, 3)
|
||||
#define temp_invert(k) _mm_aesimc_si128(*((__m128i*)(k)))
|
||||
|
|
@ -84,7 +84,7 @@ int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
|||
if (keylen == 16) {
|
||||
temp = temp_load(key);
|
||||
for (;;) {
|
||||
rk[4] = rk[0] ^ setup_mix(temp, 3) ^ rcon[i];
|
||||
rk[4] = rk[0] ^ aesni_setup_mix(temp, 3) ^ rcon[i];
|
||||
rk[5] = rk[1] ^ rk[4];
|
||||
rk[6] = rk[2] ^ rk[5];
|
||||
rk[7] = rk[3] ^ rk[6];
|
||||
|
|
@ -99,7 +99,7 @@ int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
|||
LOAD32L(rk[5], key + 20);
|
||||
temp = temp_load(key + 8);
|
||||
for (;;) {
|
||||
rk[6] = rk[0] ^ setup_mix(temp, 3) ^ rcon[i];
|
||||
rk[6] = rk[0] ^ aesni_setup_mix(temp, 3) ^ rcon[i];
|
||||
rk[7] = rk[1] ^ rk[6];
|
||||
rk[8] = rk[2] ^ rk[7];
|
||||
rk[9] = rk[3] ^ rk[8];
|
||||
|
|
@ -118,7 +118,7 @@ int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
|||
LOAD32L(rk[7], key + 28);
|
||||
temp = temp_load(key + 16);
|
||||
for (;;) {
|
||||
rk[8] = rk[0] ^ setup_mix(temp, 3) ^ rcon[i];
|
||||
rk[8] = rk[0] ^ aesni_setup_mix(temp, 3) ^ rcon[i];
|
||||
rk[9] = rk[1] ^ rk[8];
|
||||
rk[10] = rk[2] ^ rk[9];
|
||||
rk[11] = rk[3] ^ rk[10];
|
||||
|
|
@ -126,7 +126,7 @@ int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
|||
break;
|
||||
}
|
||||
temp = temp_update(temp, rk[11]);
|
||||
rk[12] = rk[4] ^ setup_mix(temp, 2);
|
||||
rk[12] = rk[4] ^ aesni_setup_mix(temp, 2);
|
||||
rk[13] = rk[5] ^ rk[12];
|
||||
rk[14] = rk[6] ^ rk[13];
|
||||
rk[15] = rk[7] ^ rk[14];
|
||||
|
|
@ -377,6 +377,10 @@ int aesni_keysize(int *keysize)
|
|||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#undef aesni_setup_mix
|
||||
#undef temp_load
|
||||
#undef temp_update
|
||||
#undef temp_invert
|
||||
#undef rcon
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -528,5 +528,10 @@ int fortuna_test(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#undef AES_SETUP
|
||||
#undef AES_ENC
|
||||
#undef AES_DONE
|
||||
#undef AES_TEST
|
||||
|
||||
#endif /* LTC_FORTUNA */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue