Browse Source

template curve_data

master
Michael Hamburg 9 years ago
parent
commit
2e9512292e
4 changed files with 22 additions and 39 deletions
  1. +1
    -1
      Makefile
  2. +3
    -2
      src/per_curve/crypto.tmpl.c
  3. +0
    -34
      src/per_curve/curve_data.tmpl.h
  4. +18
    -2
      src/per_curve/decaf.tmpl.c

+ 1
- 1
Makefile View File

@@ -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 $$@ $$<


+ 3
- 2
src/per_curve/crypto.tmpl.c View File

@@ -7,8 +7,9 @@
#include <decaf/crypto.h>
#include <string.h>

#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


+ 0
- 34
src/per_curve/curve_data.tmpl.h View File

@@ -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 */

+ 18
- 2
src/per_curve/decaf.tmpl.c View File

@@ -10,8 +10,24 @@

#include <decaf.h>

/* 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. */


Loading…
Cancel
Save