Remove the curve448 vector code
[openssl.git] / crypto / ec / curve448 / point_448.h
index 72a5e80f6f800e7fb46a7607ab95410760308a58..ed3920a8488cbb4791612d79eee273d3dce0885d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
  * Copyright 2015-2016 Cryptography Research, Inc.
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * Originally written by Mike Hamburg
  */
 
-#ifndef __C448_POINT_448_H__
-# define __C448_POINT_448_H__ 1
+#ifndef HEADER_POINT_448_H
+# define HEADER_POINT_448_H
 
 # include "curve448utils.h"
 # include "field.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+/* Comb config: number of combs, n, t, s. */
+#define COMBS_N 5
+#define COMBS_T 5
+#define COMBS_S 18
 
-# define C448_448_SCALAR_LIMBS ((446-1)/C448_WORD_BITS+1)
+/* Projective Niels coordinates */
+typedef struct {
+    gf a, b, c;
+} niels_s, niels_t[1];
+typedef struct {
+    niels_t n;
+    gf z;
+} pniels_t[1];
+
+/* Precomputed base */
+struct curve448_precomputed_s {
+    niels_t table[COMBS_N << (COMBS_T - 1)];
+};
+
+# define C448_SCALAR_LIMBS ((446-1)/C448_WORD_BITS+1)
 
 /* The number of bits in a scalar */
-# define C448_448_SCALAR_BITS 446
+# define C448_SCALAR_BITS 446
 
 /* Number of bytes in a serialized scalar. */
-# define C448_448_SCALAR_BYTES 56
+# define C448_SCALAR_BYTES 56
 
 /* X448 encoding ratio. */
-# define C448_X448_ENCODE_RATIO 2
+# define X448_ENCODE_RATIO 2
 
 /* Number of bytes in an x448 public key */
-# define C448_X448_PUBLIC_BYTES 56
+# define X448_PUBLIC_BYTES 56
 
 /* Number of bytes in an x448 private key */
-# define C448_X448_PRIVATE_BYTES 56
+# define X448_PRIVATE_BYTES 56
 
 /* Twisted Edwards extended homogeneous coordinates */
 typedef struct curve448_point_s {
@@ -50,7 +65,7 @@ typedef struct curve448_precomputed_s curve448_precomputed_s;
 
 /* Scalar is stored packed, because we don't need the speed. */
 typedef struct curve448_scalar_s {
-    c448_word_t limb[C448_448_SCALAR_LIMBS];
+    c448_word_t limb[C448_SCALAR_LIMBS];
 } curve448_scalar_t[1];
 
 /* A scalar equal to 1. */
@@ -78,7 +93,7 @@ extern const struct curve448_precomputed_s *curve448_precomputed_base;
  */
 __owur c448_error_t curve448_scalar_decode(
                             curve448_scalar_t out,
-                            const unsigned char ser[C448_448_SCALAR_BYTES]);
+                            const unsigned char ser[C448_SCALAR_BYTES]);
 
 /*
  * Read a scalar from wire format or from bytes.  Reduces mod scalar prime.
@@ -96,11 +111,11 @@ void curve448_scalar_decode_long(curve448_scalar_t out,
  * ser (out): Serialized form of a scalar.
  * s (in): Deserialized scalar.
  */
-void curve448_scalar_encode(unsigned char ser[C448_448_SCALAR_BYTES],
+void curve448_scalar_encode(unsigned char ser[C448_SCALAR_BYTES],
                             const curve448_scalar_t s);
 
 /*
- * Add two scalars. The scalars may use the same memory.
+ * Add two scalars. |a|, |b| and |out| may alias each other.
  * 
  * a (in): One scalar.
  * b (in): Another scalar.
@@ -110,7 +125,7 @@ void curve448_scalar_add(curve448_scalar_t out,
                          const curve448_scalar_t a, const curve448_scalar_t b);
 
 /*
- * Subtract two scalars.  The scalars may use the same memory.
+ * Subtract two scalars.  |a|, |b| and |out| may alias each other.
  * a (in): One scalar.
  * b (in): Another scalar.
  * out (out): a-b.
@@ -119,7 +134,7 @@ void curve448_scalar_sub(curve448_scalar_t out,
                          const curve448_scalar_t a, const curve448_scalar_t b);
 
 /*
- * Multiply two scalars. The scalars may use the same memory.
+ * Multiply two scalars. |a|, |b| and |out| may alias each other.
  * 
  * a (in): One scalar.
  * b (in): Another scalar.
@@ -129,7 +144,7 @@ void curve448_scalar_mul(curve448_scalar_t out,
                          const curve448_scalar_t a, const curve448_scalar_t b);
 
 /*
-* Halve a scalar.  The scalars may use the same memory.
+* Halve a scalar.  |a| and |out| may alias each other.
 * 
 * a (in): A scalar.
 * out (out): a/2.
@@ -198,12 +213,12 @@ void curve448_point_double(curve448_point_t two_a, const curve448_point_t a);
  * C448_FAILURE: The scalarmul didn't succeed, because the base point is in a
  * small subgroup.
  */
-__owur c448_error_t c448_x448(uint8_t out[C448_X448_PUBLIC_BYTES],
-                              const uint8_t base[C448_X448_PUBLIC_BYTES],
-                              const uint8_t scalar[C448_X448_PRIVATE_BYTES]);
+__owur c448_error_t x448_int(uint8_t out[X448_PUBLIC_BYTES],
+                             const uint8_t base[X448_PUBLIC_BYTES],
+                             const uint8_t scalar[X448_PRIVATE_BYTES]);
 
 /*
- * Multiply a point by C448_X448_ENCODE_RATIO, then encode it like RFC 7748.
+ * Multiply a point by X448_ENCODE_RATIO, then encode it like RFC 7748.
  *
  * This function is mainly used internally, but is exported in case
  * it will be useful.
@@ -215,14 +230,14 @@ __owur c448_error_t c448_x448(uint8_t out[C448_X448_PUBLIC_BYTES],
  *
  * As it happens, this aligns with the base point definitions; that is,
  * if you pass the Decaf/Ristretto base point to this function, the result
- * will be C448_X448_ENCODE_RATIO times the X448
+ * will be X448_ENCODE_RATIO times the X448
  * base point.
  *
  * out (out): The scaled and encoded point.
  * p (in): The point to be scaled and encoded.
  */
 void curve448_point_mul_by_ratio_and_encode_like_x448(
-                                        uint8_t out[C448_X448_PUBLIC_BYTES],
+                                        uint8_t out[X448_PUBLIC_BYTES],
                                         const curve448_point_t p);
 
 /*
@@ -232,9 +247,8 @@ void curve448_point_mul_by_ratio_and_encode_like_x448(
  * out (out): The scaled point base*scalar
  * scalar (in): The scalar to multiply by.
  */
-void c448_x448_derive_public_key(
-                                uint8_t out[C448_X448_PUBLIC_BYTES],
-                                const uint8_t scalar[C448_X448_PRIVATE_BYTES]);
+void x448_derive_public_key(uint8_t out[X448_PUBLIC_BYTES],
+                            const uint8_t scalar[X448_PRIVATE_BYTES]);
 
 /*
  * Multiply a precomputed base point by a scalar: out = scalar*base.
@@ -284,8 +298,4 @@ void curve448_scalar_destroy(curve448_scalar_t scalar);
 /* Overwrite point with zeros. */
 void curve448_point_destroy(curve448_point_t point);
 
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif                          /* __C448_POINT_448_H__ */
+#endif                          /* HEADER_POINT_448_H */