From 0fbc4e489b19bcb89a7052fe72b2c5416d63fbc1 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 4 Mar 2014 19:18:52 +0100 Subject: [PATCH] protect all tables by an ifdef; adjust safer to the same concept --- src/ciphers/aes/aes.c | 1 + src/ciphers/aes/aes_tab.c | 4 ++++ src/ciphers/safer/safer.c | 4 +++- src/ciphers/safer/safer_tab.c | 10 ++++------ src/ciphers/safer/saferp.c | 5 +++-- src/ciphers/twofish/twofish.c | 1 + src/ciphers/twofish/twofish_tab.c | 2 ++ src/hashes/whirl/whirl.c | 1 + src/hashes/whirl/whirltab.c | 4 ++++ src/mac/pelican/pelican.c | 1 + src/prngs/sober128.c | 1 + src/prngs/sober128tab.c | 5 +++++ 12 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/ciphers/aes/aes.c b/src/ciphers/aes/aes.c index 4ff1d24f5..29d7ed2e0 100644 --- a/src/ciphers/aes/aes.c +++ b/src/ciphers/aes/aes.c @@ -88,6 +88,7 @@ const struct ltc_cipher_descriptor aes_enc_desc = #endif +#define __LTC_AES_TAB_C__ #include "aes_tab.c" static ulong32 setup_mix(ulong32 temp) diff --git a/src/ciphers/aes/aes_tab.c b/src/ciphers/aes/aes_tab.c index 1c3de7051..9c902e88d 100644 --- a/src/ciphers/aes/aes_tab.c +++ b/src/ciphers/aes/aes_tab.c @@ -23,6 +23,8 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e]; Td4[x] = Si[x].[01, 01, 01, 01]; */ +#ifdef __LTC_AES_TAB_C__ + /** @file aes_tab.c AES tables @@ -1023,6 +1025,8 @@ static const ulong32 rcon[] = { 0x1B000000UL, 0x36000000UL, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ }; +#endif /* __LTC_AES_TAB_C__ */ + /* $Source$ */ /* $Revision$ */ /* $Date$ */ diff --git a/src/ciphers/safer/safer.c b/src/ciphers/safer/safer.c index dcfd65515..94435de8b 100644 --- a/src/ciphers/safer/safer.c +++ b/src/ciphers/safer/safer.c @@ -32,6 +32,9 @@ #ifdef LTC_SAFER +#define __LTC_SAFER_TAB_C__ +#include "safer_tab.c" + const struct ltc_cipher_descriptor safer_k64_desc = { "safer-k64", @@ -95,7 +98,6 @@ const struct ltc_cipher_descriptor #define IPHT(x, y) { x -= y; y -= x; } /******************* Types ****************************************************/ -extern const unsigned char safer_ebox[], safer_lbox[]; #ifdef LTC_CLEAN_STACK static void _Safer_Expand_Userkey(const unsigned char *userkey_1, diff --git a/src/ciphers/safer/safer_tab.c b/src/ciphers/safer/safer_tab.c index 4740caaf0..308fe55be 100644 --- a/src/ciphers/safer/safer_tab.c +++ b/src/ciphers/safer/safer_tab.c @@ -14,13 +14,11 @@ Tables for LTC_SAFER block ciphers */ -#include "tomcrypt.h" - -#if defined(LTC_SAFERP) || defined(LTC_SAFER) +#ifdef __LTC_SAFER_TAB_C__ /* This is the box defined by ebox[x] = 45^x mod 257. * Its assumed that the value "256" corresponds to zero. */ -const unsigned char safer_ebox[256] = { +static const unsigned char safer_ebox[256] = { 1, 45, 226, 147, 190, 69, 21, 174, 120, 3, 135, 164, 184, 56, 207, 63, 8, 103, 9, 148, 235, 38, 168, 107, 189, 24, 52, 27, 187, 191, 114, 247, 64, 53, 72, 156, 81, 47, 59, 85, 227, 192, 159, 216, 211, 243, 141, 177, @@ -40,7 +38,7 @@ const unsigned char safer_ebox[256] = { }; /* This is the inverse of ebox or the base 45 logarithm */ -const unsigned char safer_lbox[256] = { +static const unsigned char safer_lbox[256] = { 128, 0, 176, 9, 96, 239, 185, 253, 16, 18, 159, 228, 105, 186, 173, 248, 192, 56, 194, 101, 79, 6, 148, 252, 25, 222, 106, 27, 93, 78, 168, 130, 112, 237, 232, 236, 114, 179, 21, 195, 255, 171, 182, 71, 68, 1, 172, 37, @@ -59,7 +57,7 @@ const unsigned char safer_lbox[256] = { 184, 64, 120, 45, 58, 233, 100, 31, 146, 144, 125, 57, 111, 224, 137, 48 }; -#endif +#endif /* __LTC_SAFER_TAB_C__ */ diff --git a/src/ciphers/safer/saferp.c b/src/ciphers/safer/saferp.c index a9e9980a5..9d384da75 100644 --- a/src/ciphers/safer/saferp.c +++ b/src/ciphers/safer/saferp.c @@ -17,6 +17,9 @@ #ifdef LTC_SAFERP +#define __LTC_SAFER_TAB_C__ +#include "safer_tab.c" + const struct ltc_cipher_descriptor saferp_desc = { "safer+", @@ -42,8 +45,6 @@ const struct ltc_cipher_descriptor saferp_desc = * array of 16 bytes b[0..15] which is the block of data */ -extern const unsigned char safer_ebox[], safer_lbox[]; - #define ROUND(b, i) \ b[0] = (safer_ebox[(b[0] ^ skey->saferp.K[i][0]) & 255] + skey->saferp.K[i+1][0]) & 255; \ b[1] = safer_lbox[(b[1] + skey->saferp.K[i][1]) & 255] ^ skey->saferp.K[i+1][1]; \ diff --git a/src/ciphers/twofish/twofish.c b/src/ciphers/twofish/twofish.c index 44b4b6b47..6fc2c8ec9 100644 --- a/src/ciphers/twofish/twofish.c +++ b/src/ciphers/twofish/twofish.c @@ -62,6 +62,7 @@ static const unsigned char qord[4][5] = { #ifdef LTC_TWOFISH_TABLES +#define __LTC_TWOFISH_TAB_C__ #include "twofish_tab.c" #define sbox(i, x) ((ulong32)SBOX[i][(x)&255]) diff --git a/src/ciphers/twofish/twofish_tab.c b/src/ciphers/twofish/twofish_tab.c index 9f46006af..7ea858661 100644 --- a/src/ciphers/twofish/twofish_tab.c +++ b/src/ciphers/twofish/twofish_tab.c @@ -14,6 +14,7 @@ Twofish tables, Tom St Denis */ #ifdef LTC_TWOFISH_TABLES +#ifdef __LTC_TWOFISH_TAB_C__ /* pre generated 8x8 tables from the four 4x4s */ static const unsigned char SBOX[2][256] = { @@ -489,6 +490,7 @@ static const ulong32 rs_tab7[256] = { #endif /* LTC_TWOFISH_ALL_TABLES */ +#endif /* __LTC_TWOFISH_TAB_C__ */ #endif /* $Source$ */ diff --git a/src/hashes/whirl/whirl.c b/src/hashes/whirl/whirl.c index 1ae716fc3..af5625a7e 100644 --- a/src/hashes/whirl/whirl.c +++ b/src/hashes/whirl/whirl.c @@ -37,6 +37,7 @@ const struct ltc_hash_descriptor whirlpool_desc = }; /* the sboxes */ +#define __LTC_WHIRLTAB_C__ #include "whirltab.c" /* get a_{i,j} */ diff --git a/src/hashes/whirl/whirltab.c b/src/hashes/whirl/whirltab.c index ff5c77293..bb4b77ab2 100644 --- a/src/hashes/whirl/whirltab.c +++ b/src/hashes/whirl/whirltab.c @@ -2,6 +2,9 @@ @file whirltab.c LTC_WHIRLPOOL tables, Tom St Denis */ + +#ifdef __LTC_WHIRLTAB_C__ + static const ulong64 sbox0[] = { CONST64(0x18186018c07830d8), CONST64(0x23238c2305af4626), CONST64(0xc6c63fc67ef991b8), CONST64(0xe8e887e8136fcdfb), CONST64(0x878726874ca113cb), CONST64(0xb8b8dab8a9626d11), CONST64(0x0101040108050209), CONST64(0x4f4f214f426e9e0d), @@ -577,6 +580,7 @@ CONST64(0xca2dbf07ad5a8333), CONST64(0x6302aa71c81949d9), }; +#endif /* __LTC_WHIRLTAB_C__ */ /* $Source$ */ /* $Revision$ */ diff --git a/src/mac/pelican/pelican.c b/src/mac/pelican/pelican.c index ecdb9aeaa..8622f55f1 100644 --- a/src/mac/pelican/pelican.c +++ b/src/mac/pelican/pelican.c @@ -17,6 +17,7 @@ #ifdef LTC_PELICAN +#define __LTC_AES_TAB_C__ #define ENCRYPT_ONLY #define PELI_TAB #include "../../ciphers/aes/aes_tab.c" diff --git a/src/prngs/sober128.c b/src/prngs/sober128.c index 1d5b267a7..7a45e1b5e 100644 --- a/src/prngs/sober128.c +++ b/src/prngs/sober128.c @@ -18,6 +18,7 @@ #ifdef LTC_SOBER128 +#define __LTC_SOBER128TAB_C__ #include "sober128tab.c" const struct ltc_prng_descriptor sober128_desc = diff --git a/src/prngs/sober128tab.c b/src/prngs/sober128tab.c index 674a35530..74e4f8808 100644 --- a/src/prngs/sober128tab.c +++ b/src/prngs/sober128tab.c @@ -2,6 +2,9 @@ @file sober128tab.c SOBER-128 Tables */ + +#ifdef __LTC_SOBER128TAB_C__ + /* $ID$ */ /* @(#)TuringMultab.h 1.3 (QUALCOMM) 02/09/03 */ /* Multiplication table for Turing using 0xD02B4367 */ @@ -157,6 +160,8 @@ static const ulong32 Sbox[256] = { 0xf9e6053f, 0xa4b0d300, 0xd499cbcc, 0xb95e3d40, }; +#endif /* __LTC_SOBER128TAB_C__ */ + /* $Source$ */ /* $Revision$ */ /* $Date$ */