From 97a2a0f1672ca3a237f4afee794da76626ddb6a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 12 Feb 2002 14:52:00 +0100
Subject: [PATCH] * aes-internal.h (AES_SMALL): New macro.

Rev: src/nettle/aes-internal.h:1.3
Rev: src/nettle/aes-tables.c:1.3
---
 aes-internal.h | 16 ++++++++++++++--
 aes-tables.c   |  7 +++++--
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/aes-internal.h b/aes-internal.h
index 081f8864..79d34e44 100644
--- a/aes-internal.h
+++ b/aes-internal.h
@@ -28,6 +28,11 @@
 
 #include "aes.h"
 
+/* Define to use only small tables. */
+#ifndef AES_SMALL
+# define AES_SMALL 1
+#endif
+
 /* Macros */
 #define ROTBYTE(x) (((x) >> 8) | (((x) & 0xff) << 24))
 #define ROTRBYTE(x) (((x) << 8) | (((x) >> 24) & 0xff))
@@ -37,13 +42,20 @@
                         ((box)[(((x) >> 24) & 0xff)] << 24))
 
 /* Don't pollute global namespace too much */
-#define dtbl _aes_dtbl
+#if AES_SMALL
+# define dtbl _aes_dtbl_small
+# define _AES_TABLE_SIZE 1
+#else
+# define dtbl _aes_dtbl
+# define _AES_TABLE_SIZE 4
+#endif
+
 #define itbl _aes_itbl
 #define sbox _aes_sbox
 #define isbox _aes_isbox
 
 /* Internal tables */
-extern const uint32_t dtbl[4][0x100];
+extern const uint32_t dtbl[_AES_TABLE_SIZE][0x100];
 extern const uint32_t itbl[];
 extern const uint8_t sbox[0x100];
 extern const uint8_t isbox[0x100];
diff --git a/aes-tables.c b/aes-tables.c
index 27b1f964..1029c560 100644
--- a/aes-tables.c
+++ b/aes-tables.c
@@ -39,7 +39,7 @@
  * consistent with the row numbering. */
 
 const uint32_t
-dtbl[4][0x100] =
+dtbl[_AES_TABLE_SIZE][0x100] =
 {
   { 
     0xa56363c6,0x847c7cf8,0x997777ee,0x8d7b7bf6,
@@ -106,7 +106,9 @@ dtbl[4][0x100] =
     0xdabfbf65,0x31e6e6d7,0xc6424284,0xb86868d0,
     0xc3414182,0xb0999929,0x772d2d5a,0x110f0f1e,
     0xcbb0b07b,0xfc5454a8,0xd6bbbb6d,0x3a16162c,
-  },{ 
+  },
+#if !AES_SMALL
+  { 
     0x6363c6a5,0x7c7cf884,0x7777ee99,0x7b7bf68d,
     0xf2f2ff0d,0x6b6bd6bd,0x6f6fdeb1,0xc5c59154,
     0x30306050,0x01010203,0x6767cea9,0x2b2b567d,
@@ -302,6 +304,7 @@ dtbl[4][0x100] =
     0x82c34141,0x29b09999,0x5a772d2d,0x1e110f0f,
     0x7bcbb0b0,0xa8fc5454,0x6dd6bbbb,0x2c3a1616,
   },
+#endif /* !AES_SMALL */
 };
 
 /* These tables combine both the S-boxes and the mixcolumn
-- 
GitLab