Browse Source

generator should now be python3 clean

master
Michael Hamburg 7 years ago
parent
commit
bd2a516210
11 changed files with 34 additions and 31 deletions
  1. +16
    -13
      Makefile
  2. +3
    -3
      src/generator/curve_data.py
  3. +1
    -1
      src/include/decaf/crypto.tmpl.hxx
  4. +1
    -1
      src/per_curve/eddsa.tmpl.h
  5. +5
    -5
      src/per_curve/point.tmpl.h
  6. +1
    -1
      src/per_curve/point.tmpl.hxx
  7. +1
    -1
      src/per_curve/scalar.tmpl.c
  8. +3
    -3
      src/per_field/f_field.tmpl.h
  9. +1
    -1
      src/public_include/decaf.tmpl.h
  10. +1
    -1
      src/public_include/decaf.tmpl.hxx
  11. +1
    -1
      src/public_include/decaf/eddsa.tmpl.hxx

+ 16
- 13
Makefile View File

@@ -30,6 +30,8 @@ LD = $(CC)
LDXX = $(CXX)
ASM ?= $(CC)

PYTHON ?= python

WARNFLAGS = -pedantic -Wall -Wextra -Werror -Wunreachable-code \
-Wmissing-declarations -Wunused-function -Wno-overlength-strings $(EXWARN)

@@ -77,7 +79,8 @@ GEN_CODE= $(GEN_CODE_1:%.tmpl.hxx=%.hxx)
HEADERS= Makefile $(shell find src test -name "*.h") $(BUILD_OBJ)/timestamp $(GEN_CODE)

# components needed by the lib
LIBCOMPONENTS = $(BUILD_OBJ)/utils.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/sha512.o $(BUILD_OBJ)/spongerng.o # and per-field components
LIBCOMPONENTS = $(BUILD_OBJ)/utils.o $(BUILD_OBJ)/shake.o $(BUILD_OBJ)/sha512.o $(BUILD_OBJ)/spongerng.o
# and per-field components

BENCHCOMPONENTS = $(BUILD_OBJ)/bench.o $(BUILD_OBJ)/shake.o

@@ -125,16 +128,16 @@ $(BUILD_INC)/%: src/public_include/% $(BUILD_OBJ)/timestamp
cp -f $< $@
$(BUILD_INC)/%.h: src/public_include/%.tmpl.h src/generator/*
python -B src/generator/template.py --per=global --guard=$(@:$(BUILD_INC)/%=%) -o $@ $<
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_INC)/%=%) -o $@ $<
$(BUILD_C)/%.h: src/include/%.tmpl.h src/generator/*
python -B src/generator/template.py --per=global --guard=$(@:$(BUILD_C)/%=%) -o $@ $<
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_C)/%=%) -o $@ $<
$(BUILD_INC)/%.hxx: src/public_include/%.tmpl.hxx src/generator/*
python -B src/generator/template.py --per=global --guard=$(@:$(BUILD_INC)/%=%) -o $@ $<
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_INC)/%=%) -o $@ $<
$(BUILD_C)/%.hxx: src/include/%.tmpl.hxx src/generator/*
python -B src/generator/template.py --per=global --guard=$(@:$(BUILD_C)/%=%) -o $@ $<
$(PYTHON) -B src/generator/template.py --per=global --guard=$(@:$(BUILD_C)/%=%) -o $@ $<

################################################################
# Per-field code: call with field, arch
@@ -147,10 +150,10 @@ LIBCOMPONENTS += $$(COMPONENTS_OF_$(1))
PER_OBJ_DIRS += $$(BUILD_OBJ)/$(1)

$$(BUILD_C)/$(1)/%.c: src/per_field/%.tmpl.c src/generator/* Makefile
python -B src/generator/template.py --per=field --guard=$(1)/`basename $$@` --item=$(1) -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=field --guard=$(1)/`basename $$@` --item=$(1) -o $$@ $$<
$$(BUILD_H)/$(1)/%.h: src/per_field/%.tmpl.h src/generator/* Makefile
python -B src/generator/template.py --per=field --guard=$(1)/`basename $$@` --item=$(1) -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=field --guard=$(1)/`basename $$@` --item=$(1) -o $$@ $$<

$$(BUILD_OBJ)/$(1)/%.o: $$(BUILD_C)/$(1)/%.c $$(HEADERS_OF_$(1))
$$(CC) $$(CFLAGS) -I src/$(1) -I src/$(1)/$$(ARCH_FOR_$(1)) -I $(BUILD_H)/$(1) \
@@ -182,22 +185,22 @@ HEADERS_OF_$(1) = $$(HEADERS_OF_$(2)) $$(GLOBAL_HEADERS_OF_$(1))
HEADERS += $$(GLOBAL_HEADERS_OF_$(1))

$$(BUILD_C)/$(1)/%.c: src/per_curve/%.tmpl.c src/generator/* Makefile
python -B src/generator/template.py --per=curve --item=$(1) --guard=$(1)/`basename $$@` -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$(1)/`basename $$@` -o $$@ $$<
$$(BUILD_H)/$(1)/%.h: src/per_curve/%.tmpl.h src/generator/* Makefile
python -B src/generator/template.py --per=curve --item=$(1) --guard=$(1)/`basename $$@` -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$(1)/`basename $$@` -o $$@ $$<
$$(BUILD_INC)/decaf/point_$(3).%: src/per_curve/point.tmpl.% src/generator/* Makefile
python -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$$(BUILD_INC)/decaf/ed$(3).%: src/per_curve/eddsa.tmpl.% src/generator/* Makefile
python -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$$(BUILD_INC)/decaf/elligator_$(3).%: src/per_curve/elligator.tmpl.% src/generator/* Makefile
python -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$$(BUILD_INC)/decaf/scalar_$(3).%: src/per_curve/scalar.tmpl.% src/generator/* Makefile
python -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<
$(PYTHON) -B src/generator/template.py --per=curve --item=$(1) --guard=$$(@:$(BUILD_INC)/%=%) -o $$@ $$<

$$(BUILD_IBIN)/decaf_gen_tables_$(1): $$(BUILD_OBJ)/$(1)/decaf_gen_tables.o \
$$(BUILD_OBJ)/$(1)/decaf.o $$(BUILD_OBJ)/$(1)/scalar.o $$(BUILD_OBJ)/utils.o \


+ 3
- 3
src/generator/curve_data.py View File

@@ -74,7 +74,7 @@ def ser(x,bits,paren=None):
def msqrt(x,p,hi_bit_clear = True):
if p % 4 == 3: ret = pow(x,(p+1)//4,p)
elif p % 8 == 5:
for u in xrange(1,1000):
for u in range(1,1000):
if pow(u,(p-1)//2,p) != 1: break
u = pow(u,(p-1)//4,p)
ret = pow(x,(p+3)//8,p)
@@ -93,14 +93,14 @@ def ceil_log2(x):
out += 1
return out

for field,data in field_data.iteritems():
for field,data in field_data.items():
if "modulus" not in data:
data["modulus"] = eval(data["gf_desc"].replace("^","**"))
if "gf_bits" not in data:
data["gf_bits"] = ceil_log2(data["modulus"])

for curve,data in curve_data.iteritems():
for curve,data in curve_data.items():
for key in field_data[data["field"]]:
if key not in data:
data[key] = field_data[data["field"]][key]


+ 1
- 1
src/include/decaf/crypto.tmpl.hxx View File

@@ -6,5 +6,5 @@
*/

$("\n".join([
"#include <decaf/crypto_%s.hxx>" % g for g in sorted([c["bits"] for _,c in curve.iteritems()])
"#include <decaf/crypto_%s.hxx>" % g for g in sorted([c["bits"] for _,c in curve.items()])
]))

+ 1
- 1
src/per_curve/eddsa.tmpl.h View File

@@ -9,7 +9,7 @@ extern "C" {
#endif

/** Number of bytes in an EdDSA public key. */
#define DECAF_EDDSA_$(gf_shortname)_PUBLIC_BYTES $((gf_bits)/8 + 1)
#define DECAF_EDDSA_$(gf_shortname)_PUBLIC_BYTES $((gf_bits)//8 + 1)

/** Number of bytes in an EdDSA private key. */
#define DECAF_EDDSA_$(gf_shortname)_PRIVATE_BYTES DECAF_EDDSA_$(gf_shortname)_PUBLIC_BYTES


+ 5
- 5
src/per_curve/point.tmpl.h View File

@@ -24,24 +24,24 @@ typedef struct gf_$(gf_shortname)_s {
/** @endcond */

/** Number of bytes in a serialized point. */
#define $(C_NS)_SER_BYTES $((gf_bits-2)/8 + 1)
#define $(C_NS)_SER_BYTES $((gf_bits-2)//8 + 1)

/** Number of bytes in an elligated point. For now set the same as SER_BYTES
* but could be different for other curves.
*/
#define $(C_NS)_HASH_BYTES $((gf_bits-2)/8 + 1)
#define $(C_NS)_HASH_BYTES $((gf_bits-2)//8 + 1)

/** Number of bytes in a serialized scalar. */
#define $(C_NS)_SCALAR_BYTES $((scalar_bits-1)/8 + 1)
#define $(C_NS)_SCALAR_BYTES $((scalar_bits-1)//8 + 1)

/** Number of bits in the "which" field of an elligator inverse */
#define $(C_NS)_INVERT_ELLIGATOR_WHICH_BITS $(ceil_log2(cofactor) + 7 + elligator_onto - ((gf_bits-2) % 8))

/** Number of bytes in an x$(gf_shortname) public key */
#define DECAF_X$(gf_shortname)_PUBLIC_BYTES $((gf_bits-1)/8 + 1)
#define DECAF_X$(gf_shortname)_PUBLIC_BYTES $((gf_bits-1)//8 + 1)

/** Number of bytes in an x$(gf_shortname) private key */
#define DECAF_X$(gf_shortname)_PRIVATE_BYTES $((gf_bits-1)/8 + 1)
#define DECAF_X$(gf_shortname)_PRIVATE_BYTES $((gf_bits-1)//8 + 1)

/** Twisted Edwards extended homogeneous coordinates */
typedef struct $(c_ns)_point_s {


+ 1
- 1
src/per_curve/point.tmpl.hxx View File

@@ -49,7 +49,7 @@ static inline const char *name() { return "$(name)"; }
static const int REMOVED_COFACTOR = $(cofactor);

/** Residue class of field modulus: p == this mod 2*(this-1) */
static const int FIELD_MODULUS_TYPE = $([2**i+1 for i in xrange(1,10) if modulus % 2**(i+1) != 1][0]);
static const int FIELD_MODULUS_TYPE = $(modulus &~ (modulus-3));

/** @cond internal */
class Point;


+ 1
- 1
src/per_curve/scalar.tmpl.c View File

@@ -15,7 +15,7 @@ static const decaf_word_t MONTGOMERY_FACTOR = (decaf_word_t)0x$("%x" % pow(-q,2*
static const scalar_t sc_p = {{{
$(ser(q,64,"SC_LIMB"))
}}}, sc_r2 = {{{
$(ser(((2**128)**((scalar_bits+63)/64))%q,64,"SC_LIMB"))
$(ser(((2**128)**((scalar_bits+63)//64))%q,64,"SC_LIMB"))
}}};
/* End of template stuff */



+ 3
- 3
src/per_field/f_field.tmpl.h View File

@@ -7,9 +7,9 @@
#include "word.h"

#define __DECAF_$(gf_shortname)_GF_DEFINED__ 1
#define NLIMBS ($(gf_impl_bits/8)/sizeof(word_t))
#define X_SER_BYTES $(((gf_bits-1)/8 + 1))
#define SER_BYTES $(((gf_bits-2)/8 + 1))
#define NLIMBS ($(gf_impl_bits//8)/sizeof(word_t))
#define X_SER_BYTES $(((gf_bits-1)//8 + 1))
#define SER_BYTES $(((gf_bits-2)//8 + 1))
typedef struct gf_$(gf_shortname)_s {
word_t limb[NLIMBS];
} __attribute__((aligned(32))) gf_$(gf_shortname)_s, gf_$(gf_shortname)_t[1];


+ 1
- 1
src/public_include/decaf.tmpl.h View File

@@ -14,5 +14,5 @@
*/

$("\n".join([
"#include <decaf/point_%s.h>" % g for g in sorted([c["bits"] for _,c in curve.iteritems()])
"#include <decaf/point_%s.h>" % g for g in sorted([c["bits"] for _,c in curve.items()])
]))

+ 1
- 1
src/public_include/decaf.tmpl.hxx View File

@@ -1,7 +1,7 @@
/** Master header for Decaf library, C++ version. */

$("\n".join([
"#include <decaf/point_%s.hxx>" % g for g in sorted([c["bits"] for _,c in curve.iteritems()])
"#include <decaf/point_%s.hxx>" % g for g in sorted([c["bits"] for _,c in curve.items()])
]))

namespace decaf {


+ 1
- 1
src/public_include/decaf/eddsa.tmpl.hxx View File

@@ -4,5 +4,5 @@

namespace decaf { enum Prehashed { PURE, PREHASHED }; }
$("\n".join([
"#include <decaf/ed%s.hxx>" % g for g in sorted([c["bits"] for _,c in curve.iteritems()])
"#include <decaf/ed%s.hxx>" % g for g in sorted([c["bits"] for _,c in curve.items()])
]))

Loading…
Cancel
Save