#ifdef TEST_RIG
-#include <stdio.h>
-
-#include "daftstory.h"
+#include "modes-test.h"
/* --- @OFB_TEST@ --- *
*
#define OFB_TESTX(PRE, pre, name, fname) \
\
-/* --- Initial plaintext for the test --- */ \
- \
-static const octet text[] = TEXT; \
- \
-/* --- Key and IV to use --- */ \
+static pre##_ctx key; \
+static pre##_ofbctx ctx; \
\
-static const octet key[] = KEY; \
-static const octet iv[] = IV; \
+static void pre##_ofb_test_setup(const octet *k, size_t ksz) \
+ { pre##_init(&key, k, ksz); pre##_ofbsetkey(&ctx, &key); } \
\
-/* --- Buffers for encryption and decryption output --- */ \
+static void pre##_ofb_test_reset(const octet *iv) \
+ { pre##_ofbsetiv(&ctx, iv); } \
\
-static octet ct[sizeof(text)]; \
-static octet pt[sizeof(text)]; \
- \
-static void hexdump(const octet *p, size_t sz, size_t off) \
-{ \
- const octet *q = p + sz; \
- for (sz = 0; p < q; p++, sz++) { \
- printf("%02x", *p); \
- if ((off + sz + 1) % PRE##_BLKSZ == 0) \
- putchar(':'); \
- } \
-} \
+static void pre##_ofb_test_enc(const octet *s, octet *d, size_t sz) \
+ { pre##_ofbencrypt(&ctx, s, d, sz); } \
\
-int main(void) \
+int main(int argc, char *argv[]) \
{ \
- size_t sz = 0, rest; \
- pre##_ofbctx ctx; \
- int status = 0; \
- int done = 0; \
- pre##_ctx k; \
- \
- size_t keysz = PRE##_KEYSZ ? \
- PRE##_KEYSZ : strlen((const char *)key); \
- \
- fputs(name "-ofb: ", stdout); \
- \
- pre##_init(&k, key, keysz); \
- pre##_ofbsetkey(&ctx, &k); \
- \
- while (sz <= sizeof(text)) { \
- rest = sizeof(text) - sz; \
- memcpy(ct, text, sizeof(text)); \
- pre##_ofbsetiv(&ctx, iv); \
- pre##_ofbencrypt(&ctx, ct, ct, sz); \
- pre##_ofbencrypt(&ctx, ct + sz, ct + sz, rest); \
- memcpy(pt, ct, sizeof(text)); \
- pre##_ofbsetiv(&ctx, iv); \
- pre##_ofbencrypt(&ctx, pt, pt, rest); \
- pre##_ofbencrypt(&ctx, pt + rest, pt + rest, sz); \
- if (memcmp(pt, text, sizeof(text)) == 0) { \
- done++; \
- if (sizeof(text) < 40 || done % 8 == 0) \
- fputc('.', stdout); \
- if (done % 480 == 0) \
- fputs("\n\t", stdout); \
- fflush(stdout); \
- } else { \
- printf("\nError (sz = %lu)\n", (unsigned long)sz); \
- status = 1; \
- printf("\tplaintext = "); hexdump(text, sz, 0); \
- printf(", "); hexdump(text + sz, rest, sz); \
- fputc('\n', stdout); \
- printf("\tciphertext = "); hexdump(ct, sz, 0); \
- printf(", "); hexdump(ct + sz, rest, sz); \
- fputc('\n', stdout); \
- printf("\trecovered text = "); hexdump(pt, sz, 0); \
- printf(", "); hexdump(pt + sz, rest, sz); \
- fputc('\n', stdout); \
- fputc('\n', stdout); \
- } \
- if (sz < 63) \
- sz++; \
- else \
- sz += 9; \
- } \
- \
- fputs(status ? " failed\n" : " ok\n", stdout); \
- return (status); \
+ return test_encmode(fname "-ofb", PRE##_KEYSZ, PRE##_BLKSZ, 1, 0, \
+ pre##_ofb_test_setup, pre##_ofb_test_reset, \
+ pre##_ofb_test_enc, pre##_ofb_test_enc, \
+ argc, argv); \
}
#else