#include "gcipher.h"
#include "paranoia.h"
#include "safer.h"
-#include "safer-tab.h"
/*----- Global variables --------------------------------------------------*/
/*----- Important tables --------------------------------------------------*/
-static const octet s[265] = SAFER_S, si[256] = SAFER_SI;
+extern const octet safer_s[256], safer_si[256];
+#define S safer_s
+#define SI safer_si
/*----- Main code ---------------------------------------------------------*/
*
* Returns: ---
*
- * Use: Initializes an SAFER expanded key. A default number of
- * rounds is chosen, based on the key length.
+ * Use: Initializes an SAFER expanded key, with lots of options
+ * controlling how to do it.
*/
struct ksched {
memcpy(k, t->x, 8);
if (t->i > 1) {
for (i = 0; i < 8; i++)
- k[i] += s[s[U8(9*t->i + i + 1)]];
+ k[i] += S[S[U8(9*t->i + i + 1)]];
}
}
for (i = 0; i < 8; i++)
}
if (t->i > 1) {
for (i = 0; i < 8; i++)
- k[i] += s[s[U8(9*t->i + i + 1)]];
+ k[i] += S[S[U8(9*t->i + i + 1)]];
}
}
for (i = 0; i < 9; i++)
e ^= *k++; f += *k++; g += *k++; h ^= *k++; \
} while (0)
#define SUB(a, b, c, d, e, f, g, h) do { \
- a = s[U8(a)]; b = si[U8(b)]; c = si[U8(c)]; d = s[U8(d)]; \
- e = s[U8(e)]; f = si[U8(f)]; g = si[U8(g)]; h = s[U8(h)]; \
+ a = S[U8(a)]; b = SI[U8(b)]; c = SI[U8(c)]; d = S[U8(d)]; \
+ e = S[U8(e)]; f = SI[U8(f)]; g = SI[U8(g)]; h = S[U8(h)]; \
} while (0)
#define KAX(k, a, b, c, d, e, f, g, h) do { \
a += *k++; b ^= *k++; c ^= *k++; d += *k++; \
d ^= *--k; c -= *--k; b -= *--k; a ^= *--k; \
} while (0)
#define ISUB(a, b, c, d, e, f, g, h) do { \
- a = si[U8(a)]; b = s[U8(b)]; c = s[U8(c)]; d = si[U8(d)]; \
- e = si[U8(e)]; f = s[U8(f)]; g = s[U8(g)]; h = si[U8(h)]; \
+ a = SI[U8(a)]; b = S[U8(b)]; c = S[U8(c)]; d = SI[U8(d)]; \
+ e = SI[U8(e)]; f = S[U8(f)]; g = S[U8(g)]; h = SI[U8(h)]; \
} while (0)
#define KSX(k, a, b, c, d, e, f, g, h) do { \
h -= *--k; g ^= *--k; f ^= *--k; e -= *--k; \
KXS(k, a, b, c, d, e, f, g, h); \
} while (0)
-
void safer_eblk(const safer_ctx *k, const uint32 *src, uint32 *dst)
{
octet a, b, c, d, e, f, g, h;
PACK(dst, a, b, c, d, e, f, g, h);
}
-BLKC_TEST(SAFER, safer)
+/*----- Test rig ----------------------------------------------------------*/
+
+#ifdef TEST_RIG
+
+#include <mLib/testrig.h>
+
+#define CIPHERS(_) \
+ _(SAFER, safer) \
+ _(SAFERSK, safersk)
+
+CIPHERS(BLKC_VERIFY)
+
+static const test_chunk defs[] = {
+ CIPHERS(BLKC_TESTDEFS)
+ { 0, 0, { 0 } }
+};
+
+int main(int argc, char *argv[])
+{
+ test_run(argc, argv, defs, SRCDIR "/t/safer");
+ return (0);
+}
+
+#endif
/*----- That's all, folks -------------------------------------------------*/