From 2e9512292e83ed5d2c9aae84b7cef08ab8e39937 Mon Sep 17 00:00:00 2001 From: Michael Hamburg Date: Fri, 29 Jan 2016 15:18:51 -0800 Subject: [PATCH] template curve_data --- Makefile | 2 +- src/per_curve/crypto.tmpl.c | 5 +++-- src/per_curve/curve_data.tmpl.h | 34 --------------------------------- src/per_curve/decaf.tmpl.c | 20 +++++++++++++++++-- 4 files changed, 22 insertions(+), 39 deletions(-) delete mode 100644 src/per_curve/curve_data.tmpl.h diff --git a/Makefile b/Makefile index 9d28e30..cfb1e7e 100644 --- a/Makefile +++ b/Makefile @@ -169,7 +169,7 @@ define define_curve LIBCOMPONENTS += $$(BUILD_OBJ)/$(1)/decaf.o $$(BUILD_OBJ)/$(1)/crypto.o $$(BUILD_OBJ)/$(1)/decaf_tables.o PER_OBJ_DIRS += $$(BUILD_OBJ)/$(1) -HEADERS_OF_$(1) = $$(HEADERS_OF_$(2)) $$(BUILD_H)/$(1)/curve_data.h +HEADERS_OF_$(1) = $$(HEADERS_OF_$(2)) $$(BUILD_C)/$(1)/%.c: src/per_curve/%.tmpl.c src/gen_headers/* $$(HEADERS_OF_$(2)) python -B src/gen_headers/template.py --per=curve --item=$(1) --guard=$(1)/`basename $$@` -o $$@ $$< diff --git a/src/per_curve/crypto.tmpl.c b/src/per_curve/crypto.tmpl.c index 4e46d7d..a2697a7 100644 --- a/src/per_curve/crypto.tmpl.c +++ b/src/per_curve/crypto.tmpl.c @@ -7,8 +7,9 @@ #include #include -#define DECAF_JUST_API -#include "curve_data.h" +#define API_NAME "$(c_ns)" +#define API_NS(_id) $(c_ns)_##_id +#define SCALAR_BITS $(C_NS)_SCALAR_BITS #define SCALAR_BYTES ((SCALAR_BITS + 7)/8) /* TODO: canonicalize and freeze the STROBE constants in this file diff --git a/src/per_curve/curve_data.tmpl.h b/src/per_curve/curve_data.tmpl.h deleted file mode 100644 index dc1ba49..0000000 --- a/src/per_curve/curve_data.tmpl.h +++ /dev/null @@ -1,34 +0,0 @@ -#define API_NAME "$(c_ns)" -#define API_NS(_id) $(c_ns)_##_id - -#define SCALAR_BITS $(C_NS)_SCALAR_BITS - -#ifndef DECAF_JUST_API - -#define SCALAR_LIMBS $(C_NS)_SCALAR_LIMBS -#define scalar_t API_NS(scalar_t) -#define point_t API_NS(point_t) -#define precomputed_s API_NS(precomputed_s) -#define IMAGINE_TWIST $(imagine_twist) -#define COFACTOR $(cofactor) - -static const int EDWARDS_D = $(d); - -static const scalar_t sc_p = {{{ - $(scalar_p) -}}}; - -#ifdef GEN_TABLES -/* Not exported, but used by pregen tool. */ -static const unsigned char base_point_ser_for_pregen[SER_BYTES] = { - $(decaf_base) -}; -#endif - -#if COFACTOR==8 - static const gf SQRT_ONE_MINUS_D = {FIELD_LITERAL( - $(sqrt_one_minus_d) - )}; -#endif - -#endif /* DECAF_JUST_API */ diff --git a/src/per_curve/decaf.tmpl.c b/src/per_curve/decaf.tmpl.c index 14fe348..bd81b2b 100644 --- a/src/per_curve/decaf.tmpl.c +++ b/src/per_curve/decaf.tmpl.c @@ -10,8 +10,24 @@ #include -/* Include the curve data here */ -#include "curve_data.h" +#define API_NS(_id) $(c_ns)_##_id +#define SCALAR_BITS $(C_NS)_SCALAR_BITS +#define SCALAR_LIMBS $(C_NS)_SCALAR_LIMBS +#define scalar_t API_NS(scalar_t) +#define point_t API_NS(point_t) +#define precomputed_s API_NS(precomputed_s) +#define IMAGINE_TWIST $(imagine_twist) +#define COFACTOR $(cofactor) + +static const int EDWARDS_D = $(d); +static const scalar_t sc_p = {{{ $(scalar_p) }}}; + +#if COFACTOR==8 + static const gf SQRT_ONE_MINUS_D = {FIELD_LITERAL( + $(sqrt_one_minus_d) + )}; +#endif + #if (COFACTOR == 8) && !IMAGINE_TWIST /* FUTURE: Curve41417 doesn't have these properties. */