Hack on the newly imported X25519 and X448 code.
[secnet] / f25519.h
index fc75546..8450748 100644 (file)
--- a/f25519.h
+++ b/f25519.h
@@ -1,3 +1,42 @@
+/*
+ * f25519.h: arithmetic modulo 2^255 - 19
+ */
+/*
+ * This file is Free Software.  It has been modified to as part of its
+ * incorporation into secnet.
+ *
+ * Copyright 2017 Mark Wooding
+ *
+ * You may redistribute this file and/or modify it under the terms of
+ * the permissive licence shown below.
+ *
+ * You may redistribute secnet as a whole and/or modify it under the
+ * terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3, or (at your option) any
+ * later version.
+ *
+ * This program 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
+ * along with this program; if not, see
+ * https://www.gnu.org/licenses/gpl.html.
+ */
+/*
+ * Imported from Catacomb, and lightly modified for Secnet (2017-04-30):
+ *
+ *   * Use `fake-mLib-bits.h' in place of the real <mLib/bits.h>.
+ *
+ *   * Remove the 16/32-bit implementation, since C99 always has 64-bit
+ *     arithmetic.
+ *
+ *   * Disable some of the operations which aren't needed for X25519.
+ *     (They're used for Ed25519, which we don't need.)
+ *
+ * The file's original comment headers are preserved below.
+ */
 /* -*-c-*-
  *
  * Arithmetic modulo 2^255 - 19
@@ -34,7 +73,7 @@
 
 /*----- Header files ------------------------------------------------------*/
 
-#include <mLib/bits.h>
+#include "fake-mLib-bits.h"
 
 #ifndef CATACOMB_QFARITH_H
 #  include "qfarith.h"
 
 typedef union {
   int32 p26[10];
-  int16 p10[26];
 } f25519;
 
-#if !defined(F25519_IMPL) && defined(HAVE_INT64)
-#  define F25519_IMPL 26
-#endif
-
-#ifndef F25519_IMPL
-#  define F25519_IMPL 10
-#endif
-
 /*----- Functions provided ------------------------------------------------*/
 
+#define F25519_TRIM_X25519
+
 /* --- @f25519_set@ --- *
  *
  * Arguments:  @f25519 *z@ = where to write the result
@@ -108,6 +140,8 @@ extern void f25519_load(f25519 */*z*/, const octet /*xv*/[32]);
 
 extern void f25519_store(octet /*zv*/[32], const f25519 */*x*/);
 
+#ifndef F25519_TRIM_X25519
+
 /* --- @f25519_pick2@ --- *
  *
  * Arguments:  @f25519 *z@ = where to put the result (may alias @x@ or @y@)
@@ -141,6 +175,8 @@ extern void f25519_pick2(f25519 */*z*/, const f25519 */*x*/,
 extern void f25519_pickn(f25519 */*z*/, const f25519 */*v*/, size_t /*n*/,
                         size_t /*i*/);
 
+#endif
+
 /* --- @f25519_condswap@ --- *
  *
  * Arguments:  @f25519 *x, *y@ = two operands
@@ -181,6 +217,8 @@ extern void f25519_add(f25519 */*z*/,
 extern void f25519_sub(f25519 */*z*/,
                       const f25519 */*x*/, const f25519 */*y*/);
 
+#ifndef F25519_TRIM_X25519
+
 /* --- @f25519_neg@ --- *
  *
  * Arguments:  @f25519 *z@ = where to put the result (may alias @x@)
@@ -208,6 +246,8 @@ extern void f25519_neg(f25519 */*z*/, const f25519 */*x*/);
 
 extern void f25519_condneg(f25519 */*z*/, const f25519 */*x*/, uint32 /*m*/);
 
+#endif
+
 /* --- @f25519_mulconst@ --- *
  *
  * Arguments:  @f25519 *z@ = where to put the result (may alias @x@)
@@ -260,6 +300,8 @@ extern void f25519_sqr(f25519 */*z*/, const f25519 */*x*/);
 
 extern void f25519_inv(f25519 */*z*/, const f25519 */*x*/);
 
+#ifndef F25519_TRIM_X25519
+
 /* --- @f25519_quosqrt@ --- *
  *
  * Arguments:  @f25519 *z@ = where to put the result (may alias @x@ or @y@)
@@ -276,6 +318,8 @@ extern void f25519_inv(f25519 */*z*/, const f25519 */*x*/);
 extern int f25519_quosqrt(f25519 */*z*/,
                          const f25519 */*x*/, const f25519 */*y*/);
 
+#endif
+
 /*----- That's all, folks -------------------------------------------------*/
 
 #ifdef __cplusplus