Skip to content

Commit

Permalink
protect all tables by an ifdef; adjust safer to the same concept
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaeckel committed Mar 4, 2014
1 parent 0aee5f3 commit 0fbc4e4
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/ciphers/aes/aes.c
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/ciphers/aes/aes_tab.c
Expand Up @@ -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
Expand Down Expand Up @@ -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$ */
4 changes: 3 additions & 1 deletion src/ciphers/safer/safer.c
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/ciphers/safer/safer_tab.c
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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__ */



Expand Down
5 changes: 3 additions & 2 deletions src/ciphers/safer/saferp.c
Expand Up @@ -17,6 +17,9 @@

#ifdef LTC_SAFERP

#define __LTC_SAFER_TAB_C__
#include "safer_tab.c"

const struct ltc_cipher_descriptor saferp_desc =
{
"safer+",
Expand All @@ -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]; \
Expand Down
1 change: 1 addition & 0 deletions src/ciphers/twofish/twofish.c
Expand Up @@ -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])
Expand Down
2 changes: 2 additions & 0 deletions src/ciphers/twofish/twofish_tab.c
Expand Up @@ -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] = {
Expand Down Expand Up @@ -489,6 +490,7 @@ static const ulong32 rs_tab7[256] = {

#endif /* LTC_TWOFISH_ALL_TABLES */

#endif /* __LTC_TWOFISH_TAB_C__ */
#endif

/* $Source$ */
Expand Down
1 change: 1 addition & 0 deletions src/hashes/whirl/whirl.c
Expand Up @@ -37,6 +37,7 @@ const struct ltc_hash_descriptor whirlpool_desc =
};

/* the sboxes */
#define __LTC_WHIRLTAB_C__
#include "whirltab.c"

/* get a_{i,j} */
Expand Down
4 changes: 4 additions & 0 deletions src/hashes/whirl/whirltab.c
Expand Up @@ -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),
Expand Down Expand Up @@ -577,6 +580,7 @@ CONST64(0xca2dbf07ad5a8333),
CONST64(0x6302aa71c81949d9),
};

#endif /* __LTC_WHIRLTAB_C__ */

/* $Source$ */
/* $Revision$ */
Expand Down
1 change: 1 addition & 0 deletions src/mac/pelican/pelican.c
Expand Up @@ -17,6 +17,7 @@

#ifdef LTC_PELICAN

#define __LTC_AES_TAB_C__
#define ENCRYPT_ONLY
#define PELI_TAB
#include "../../ciphers/aes/aes_tab.c"
Expand Down
1 change: 1 addition & 0 deletions src/prngs/sober128.c
Expand Up @@ -18,6 +18,7 @@

#ifdef LTC_SOBER128

#define __LTC_SOBER128TAB_C__
#include "sober128tab.c"

const struct ltc_prng_descriptor sober128_desc =
Expand Down
5 changes: 5 additions & 0 deletions src/prngs/sober128tab.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -157,6 +160,8 @@ static const ulong32 Sbox[256] = {
0xf9e6053f, 0xa4b0d300, 0xd499cbcc, 0xb95e3d40,
};

#endif /* __LTC_SOBER128TAB_C__ */

/* $Source$ */
/* $Revision$ */
/* $Date$ */

0 comments on commit 0fbc4e4

Please sign in to comment.