Generate precomputed tables as sources in `precomps/'.
[u/mdw/catacomb] / symm / skipjack.c
index bd58ede..82c1a72 100644 (file)
@@ -32,7 +32,6 @@
 #include "blkc.h"
 #include "gcipher.h"
 #include "skipjack.h"
-#include "skipjack-tab.h"
 
 /*----- Global variables --------------------------------------------------*/
 
@@ -40,7 +39,7 @@ const octet skipjack_keysz[] = { KSZ_SET, 10, 0 };
 
 /*----- The Skipjack S-box ------------------------------------------------*/
 
-static const octet f[256] = SKIPJACK_S;
+extern const octet skipjack_s[256];
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -83,10 +82,10 @@ void skipjack_init(skipjack_ctx *k, const void *buf, size_t sz)
 
 #define G(x, k) do {                                                   \
   octet _x = U8(x >> 8), _y = U8(x);                                   \
-  _x ^= f[_y ^ U8(k >> 24)];                                           \
-  _y ^= f[_x ^ U8(k >> 16)];                                           \
-  _x ^= f[_y ^ U8(k >> 8)];                                            \
-  _y ^= f[_x ^ U8(k >> 0)];                                            \
+  _x ^= skipjack_s[_y ^ U8(k >> 24)];                                  \
+  _y ^= skipjack_s[_x ^ U8(k >> 16)];                                  \
+  _x ^= skipjack_s[_y ^ U8(k >>         8)];                                   \
+  _y ^= skipjack_s[_x ^ U8(k >>         0)];                                   \
   x = (_x << 8) | _y;                                                  \
 } while (0)
 
@@ -128,10 +127,10 @@ void skipjack_eblk(const skipjack_ctx *k, const uint32 *s, uint32 *d)
 
 #define G_INV(x, k) do {                                               \
   octet _x = U8(x >> 8), _y = U8(x);                                   \
-  _y ^= f[_x ^ U8(k >> 0)];                                            \
-  _x ^= f[_y ^ U8(k >> 8)];                                            \
-  _y ^= f[_x ^ U8(k >> 16)];                                           \
-  _x ^= f[_y ^ U8(k >> 24)];                                           \
+  _y ^= skipjack_s[_x ^ U8(k >>         0)];                                   \
+  _x ^= skipjack_s[_y ^ U8(k >>         8)];                                   \
+  _y ^= skipjack_s[_x ^ U8(k >> 16)];                                  \
+  _x ^= skipjack_s[_y ^ U8(k >> 24)];                                  \
   x = (_x << 8) | _y;                                                  \
 } while (0)