Browse Source

no more API_NS2.

master
Michael Hamburg 9 years ago
parent
commit
3a5ba3e075
5 changed files with 22 additions and 21 deletions
  1. +1
    -1
      src/gen_headers/decaf_h.py
  2. +2
    -2
      src/gen_headers/decaf_hxx.py
  3. +0
    -1
      src/per_curve/curve_data.tmpl.h
  4. +4
    -4
      src/per_curve/decaf.tmpl.c
  5. +15
    -13
      src/per_curve/decaf_gen_tables.tmpl.c

+ 1
- 1
src/gen_headers/decaf_h.py View File

@@ -55,7 +55,7 @@ struct %(c_ns)s_precomputed_s;
typedef struct %(c_ns)s_precomputed_s %(c_ns)s_precomputed_s; typedef struct %(c_ns)s_precomputed_s %(c_ns)s_precomputed_s;


/** Size and alignment of precomputed point tables. */ /** Size and alignment of precomputed point tables. */
extern const size_t sizeof_%(c_ns)s_precomputed_s API_VIS, alignof_%(c_ns)s_precomputed_s API_VIS;
extern const size_t %(c_ns)s_sizeof_precomputed_s API_VIS, %(c_ns)s_alignof_precomputed_s API_VIS;


/** Scalar is stored packed, because we don't need the speed. */ /** Scalar is stored packed, because we don't need the speed. */
typedef struct %(c_ns)s_scalar_s { typedef struct %(c_ns)s_scalar_s {


+ 2
- 2
src/gen_headers/decaf_hxx.py View File

@@ -571,8 +571,8 @@ public:
public: public:
/** @cond internal */ /** @cond internal */
friend class OwnedOrUnowned<Precomputed,Precomputed_U>; friend class OwnedOrUnowned<Precomputed,Precomputed_U>;
static inline size_t size() NOEXCEPT { return sizeof_%(c_ns)s_precomputed_s; }
static inline size_t alignment() NOEXCEPT { return alignof_%(c_ns)s_precomputed_s; }
static inline size_t size() NOEXCEPT { return %(c_ns)s_sizeof_precomputed_s; }
static inline size_t alignment() NOEXCEPT { return %(c_ns)s_alignof_precomputed_s; }
static inline const Precomputed_U * defaultValue() NOEXCEPT { return %(c_ns)s_precomputed_base; } static inline const Precomputed_U * defaultValue() NOEXCEPT { return %(c_ns)s_precomputed_base; }
/** @endcond */ /** @endcond */
}; };


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

@@ -1,6 +1,5 @@
#define API_NAME "$(c_ns)" #define API_NAME "$(c_ns)"
#define API_NS(_id) $(c_ns)_##_id #define API_NS(_id) $(c_ns)_##_id
#define API_NS2(_pref,_id) _pref##_$(c_ns)_##_id


#define SCALAR_BITS $(C_NS)_SCALAR_BITS #define SCALAR_BITS $(C_NS)_SCALAR_BITS




+ 4
- 4
src/per_curve/decaf.tmpl.c View File

@@ -49,8 +49,8 @@ extern const gf API_NS(precomputed_base_as_fe)[];
const precomputed_s *API_NS(precomputed_base) = const precomputed_s *API_NS(precomputed_base) =
(const precomputed_s *) &API_NS(precomputed_base_as_fe); (const precomputed_s *) &API_NS(precomputed_base_as_fe);


const size_t API_NS2(sizeof,precomputed_s) = sizeof(precomputed_s);
const size_t API_NS2(alignof,precomputed_s) = sizeof(big_register_t);
const size_t API_NS(sizeof_precomputed_s) = sizeof(precomputed_s);
const size_t API_NS(alignof_precomputed_s) = sizeof(big_register_t);


#define FOR_LIMB(i,op) { unsigned int i=0; for (i=0; i<NLIMBS; i++) { op; }} #define FOR_LIMB(i,op) { unsigned int i=0; for (i=0; i<NLIMBS; i++) { op; }}
#define FOR_LIMB_U(i,op) { unsigned int i=0; UNROLL for (i=0; i<NLIMBS; i++) { op; }} #define FOR_LIMB_U(i,op) { unsigned int i=0; UNROLL for (i=0; i<NLIMBS; i++) { op; }}
@@ -1771,7 +1771,7 @@ prepare_wnaf_table(


extern const gf API_NS(precomputed_wnaf_as_fe)[]; extern const gf API_NS(precomputed_wnaf_as_fe)[];
static const niels_t *API_NS(wnaf_base) = (const niels_t *)API_NS(precomputed_wnaf_as_fe); static const niels_t *API_NS(wnaf_base) = (const niels_t *)API_NS(precomputed_wnaf_as_fe);
const size_t API_NS2(sizeof,precomputed_wnafs) __attribute((visibility("hidden")))
const size_t API_NS(sizeof_precomputed_wnafs) __attribute((visibility("hidden")))
= sizeof(niels_t)<<DECAF_WNAF_FIXED_TABLE_BITS; = sizeof(niels_t)<<DECAF_WNAF_FIXED_TABLE_BITS;


void API_NS(precompute_wnafs) ( void API_NS(precompute_wnafs) (
@@ -1878,5 +1878,5 @@ void API_NS(point_destroy) (
void API_NS(precomputed_destroy) ( void API_NS(precomputed_destroy) (
precomputed_s *pre precomputed_s *pre
) { ) {
decaf_bzero(pre, API_NS2(sizeof,precomputed_s));
decaf_bzero(pre, API_NS(sizeof_precomputed_s));
} }

+ 15
- 13
src/per_curve/decaf_gen_tables.tmpl.c View File

@@ -9,8 +9,11 @@
#include "decaf.h" #include "decaf.h"
#include "decaf_config.h" #include "decaf_config.h"


#define GEN_TABLES
#include "curve_data.h"
#define API_NS(_id) $(c_ns)_##_id
#define SCALAR_BITS $(C_NS)_SCALAR_BITS
static const unsigned char base_point_ser_for_pregen[SER_BYTES] = {
$(decaf_base)
};


/* To satisfy linker. */ /* To satisfy linker. */
const gf API_NS(precomputed_base_as_fe)[1]; const gf API_NS(precomputed_base_as_fe)[1];
@@ -24,7 +27,7 @@ const uint8_t API_NS(x_base_point)[X_PUBLIC_BYTES] = {0};


struct niels_s; struct niels_s;
const gf_s *API_NS(precomputed_wnaf_as_fe); const gf_s *API_NS(precomputed_wnaf_as_fe);
extern const size_t API_NS2(sizeof,precomputed_wnafs);
extern const size_t API_NS(sizeof_precomputed_wnafs);


void API_NS(precompute_wnafs) ( void API_NS(precompute_wnafs) (
struct niels_s *out, struct niels_s *out,
@@ -82,12 +85,12 @@ int main(int argc, char **argv) {
if (ret != DECAF_SUCCESS) return 1; if (ret != DECAF_SUCCESS) return 1;
API_NS(precomputed_s) *pre; API_NS(precomputed_s) *pre;
ret = posix_memalign((void**)&pre, API_NS2(alignof,precomputed_s), API_NS2(sizeof,precomputed_s));
ret = posix_memalign((void**)&pre, API_NS(alignof_precomputed_s), API_NS(sizeof_precomputed_s));
if (ret || !pre) return 1; if (ret || !pre) return 1;
API_NS(precompute)(pre, real_point_base); API_NS(precompute)(pre, real_point_base);
struct niels_s *preWnaf; struct niels_s *preWnaf;
ret = posix_memalign((void**)&preWnaf, API_NS2(alignof,precomputed_s), API_NS2(sizeof,precomputed_wnafs));
ret = posix_memalign((void**)&preWnaf, API_NS(alignof_precomputed_s), API_NS(sizeof_precomputed_wnafs));
if (ret || !preWnaf) return 1; if (ret || !preWnaf) return 1;
API_NS(precompute_wnafs)(preWnaf, real_point_base); API_NS(precompute_wnafs)(preWnaf, real_point_base);


@@ -97,8 +100,7 @@ int main(int argc, char **argv) {
printf("/** @warning: this file was automatically generated. */\n"); printf("/** @warning: this file was automatically generated. */\n");
printf("#include \"field.h\"\n\n"); printf("#include \"field.h\"\n\n");
printf("#include <decaf.h>\n\n"); printf("#include <decaf.h>\n\n");
printf("#define API_NS(_id) %s_##_id\n", API_NAME);
printf("#define API_NS2(_pref,_id) _pref##_%s_##_id\n", API_NAME);
printf("#define API_NS(_id) $(c_ns)_##_id\n");
output = (const gf_s *)real_point_base; output = (const gf_s *)real_point_base;
printf("const API_NS(point_t) API_NS(point_base) = {{\n"); printf("const API_NS(point_t) API_NS(point_base) = {{\n");
@@ -110,10 +112,10 @@ int main(int argc, char **argv) {
output = (const gf_s *)pre; output = (const gf_s *)pre;
printf("const gf API_NS(precomputed_base_as_fe)[%d]\n", printf("const gf API_NS(precomputed_base_as_fe)[%d]\n",
(int)(API_NS2(sizeof,precomputed_s) / sizeof(gf)));
printf("__attribute__((aligned(%d),visibility(\"hidden\"))) = {\n ", (int)API_NS2(alignof,precomputed_s));
(int)(API_NS(sizeof_precomputed_s) / sizeof(gf)));
printf("__attribute__((aligned(%d),visibility(\"hidden\"))) = {\n ", (int)API_NS(alignof_precomputed_s));
for (i=0; i < API_NS2(sizeof,precomputed_s); i+=sizeof(gf)) {
for (i=0; i < API_NS(sizeof_precomputed_s); i+=sizeof(gf)) {
if (i) printf(",\n "); if (i) printf(",\n ");
field_print(output++); field_print(output++);
} }
@@ -121,9 +123,9 @@ int main(int argc, char **argv) {
output = (const gf_s *)preWnaf; output = (const gf_s *)preWnaf;
printf("const gf API_NS(precomputed_wnaf_as_fe)[%d]\n", printf("const gf API_NS(precomputed_wnaf_as_fe)[%d]\n",
(int)(API_NS2(sizeof,precomputed_wnafs) / sizeof(gf)));
printf("__attribute__((aligned(%d),visibility(\"hidden\"))) = {\n ", (int)API_NS2(alignof,precomputed_s));
for (i=0; i < API_NS2(sizeof,precomputed_wnafs); i+=sizeof(gf)) {
(int)(API_NS(sizeof_precomputed_wnafs) / sizeof(gf)));
printf("__attribute__((aligned(%d),visibility(\"hidden\"))) = {\n ", (int)API_NS(alignof_precomputed_s));
for (i=0; i < API_NS(sizeof_precomputed_wnafs); i+=sizeof(gf)) {
if (i) printf(",\n "); if (i) printf(",\n ");
field_print(output++); field_print(output++);
} }


Loading…
Cancel
Save