@@@ test keccak and sha3
[secnet] / x448.c
diff --git a/x448.c b/x448.c
index d766e5c..332ff7b 100644 (file)
--- a/x448.c
+++ b/x448.c
@@ -7,7 +7,26 @@
 
 /*----- Licensing notice --------------------------------------------------*
  *
- * This file is part of Catacomb.
+ * This file is part of secnet.
+ * See README for full list of copyright holders.
+ *
+ * secnet is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version d of the License, or
+ * (at your option) any later version.
+ *
+ * secnet is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with secnet; if not, see
+ * https://www.gnu.org/licenses/gpl.html.
+ *
+ * This file was originally part of Catacomb, but has been automatically
+ * modified for incorporation into secnet: see `import-catacomb-crypto'
+ * for details.
  *
  * Catacomb is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Library General Public License as
@@ -27,7 +46,7 @@
 
 /*----- Header files ------------------------------------------------------*/
 
-#include <mLib/bits.h>
+#include "fake-mLib-bits.h"
 
 #include "montladder.h"
 #include "fgoldi.h"
@@ -39,24 +58,6 @@ const octet x448_base[56] = { 5, 0, /* ... */ };
 
 #define A0 39081
 
-/*----- Key fetching ------------------------------------------------------*/
-
-const key_fetchdef x448_pubfetch[] = {
-  { "pub",     offsetof(x448_pub, pub),        KENC_BINARY,    0 },
-  { 0,         0,                              0,              0 }
-};
-
-static const key_fetchdef priv[] = {
-  { "priv",    offsetof(x448_priv, priv),      KENC_BINARY,    0 },
-  { 0,         0,                              0,              0 }
-};
-
-const key_fetchdef x448_privfetch[] = {
-  { "pub",     offsetof(x448_priv, pub),       KENC_BINARY,    0 },
-  { "private", 0,                              KENC_STRUCT,    priv },
-  { 0,         0,                              0,              0 }
-};
-
 /*----- Main code ---------------------------------------------------------*/
 
 /* --- @x448@ --- *
@@ -93,90 +94,4 @@ void x448(octet zz[X448_OUTSZ],
   fgoldi_store(zz, &x1);
 }
 
-/*----- Test rig ----------------------------------------------------------*/
-
-#ifdef TEST_RIG
-
-#include <mLib/report.h>
-#include <mLib/str.h>
-#include <mLib/testrig.h>
-
-static int vrf_x448(dstr dv[])
-{
-  dstr dz = DSTR_INIT;
-  int ok = 1;
-
-  if (dv[0].len != 56) die(1, "bad key length");
-  if (dv[1].len != 56) die(1, "bad public length");
-  if (dv[2].len != 56) die(1, "bad result length");
-
-  dstr_ensure(&dz, 56); dz.len = 56;
-  x448((octet *)dz.buf,
-       (const octet *)dv[0].buf,
-       (const octet *)dv[1].buf);
-  if (memcmp(dz.buf, dv[2].buf, 56) != 0) {
-    ok = 0;
-    fprintf(stderr, "failed!");
-    fprintf(stderr, "\n\t   k = "); type_hex.dump(&dv[0], stderr);
-    fprintf(stderr, "\n\t   p = "); type_hex.dump(&dv[1], stderr);
-    fprintf(stderr, "\n\twant = "); type_hex.dump(&dv[2], stderr);
-    fprintf(stderr, "\n\tcalc = "); type_hex.dump(&dz, stderr);
-    fprintf(stderr, "\n");
-  }
-
-  dstr_destroy(&dz);
-  return (ok);
-}
-
-static int vrf_mct(dstr dv[])
-{
-  octet b0[56], b1[56], *k = b0, *x = b1, *t;
-  unsigned long i, niter;
-  dstr d = DSTR_INIT;
-  int ok = 1;
-
-  if (dv[0].len != sizeof(b0)) { fprintf(stderr, "k len\n"); exit(2); }
-  if (dv[1].len != sizeof(b1)) { fprintf(stderr, "x len\n"); exit(2); }
-  if (dv[3].len != sizeof(b0)) { fprintf(stderr, "result len\n"); exit(2); }
-  memcpy(b0, dv[0].buf, sizeof(b0));
-  memcpy(b1, dv[1].buf, sizeof(b1));
-  niter = *(unsigned long *)dv[2].buf;
-  dstr_ensure(&d, 56); d.len = 56; t = (octet *)d.buf;
-
-  for (i = 0; i < niter; i++) {
-    x448(x, k, x);
-    t = x; x = k; k = t;
-  }
-  memcpy(d.buf, k, d.len);
-
-  if (memcmp(d.buf, dv[3].buf, d.len) != 0) {
-    ok = 0;
-    fprintf(stderr, "failed...");
-    fprintf(stderr, "\n\tinitial k = "); type_hex.dump(&dv[0], stderr);
-    fprintf(stderr, "\n\tinitial x = "); type_hex.dump(&dv[1], stderr);
-    fprintf(stderr, "\n\titerations = %lu", niter);
-    fprintf(stderr, "\n\texpected = "); type_hex.dump(&dv[3], stderr);
-    fprintf(stderr, "\n\tcalculated = "); type_hex.dump(&d, stderr);
-    fputc('\n', stderr);
-  }
-
-  dstr_destroy(&d);
-  return (ok);
-}
-
-static test_chunk tests[] = {
-  { "x448", vrf_x448, { &type_hex, &type_hex, &type_hex } },
-  { "x448-mct", vrf_mct,
-    { &type_hex, &type_hex, &type_ulong, &type_hex } },
-  { 0, 0, { 0 } }
-};
-
-int main(int argc, char *argv[])
-{
-  test_run(argc, argv, tests, SRCDIR "/t/x448");
-  return (0);
-}
-
-#endif
-
 /*----- That's all, folks -------------------------------------------------*/