diff options
| author | J08nY | 2019-11-25 21:25:29 +0100 |
|---|---|---|
| committer | J08nY | 2019-11-25 21:25:29 +0100 |
| commit | de491a6191b465edb7bd9a01a5177ac9bf836747 (patch) | |
| tree | 18459bc2cb101782e2157b0e9313d288d1b6a43b /pyecsca/codegen/templates | |
| parent | 8a56c7a95e662862cfe78b834ccb091e95d5372f (diff) | |
| download | pyecsca-codegen-de491a6191b465edb7bd9a01a5177ac9bf836747.tar.gz pyecsca-codegen-de491a6191b465edb7bd9a01a5177ac9bf836747.tar.zst pyecsca-codegen-de491a6191b465edb7bd9a01a5177ac9bf836747.zip | |
Start Python codegen impl.
Diffstat (limited to 'pyecsca/codegen/templates')
| -rw-r--r-- | pyecsca/codegen/templates/__init__.py | 0 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/coords.c | 33 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/coords.h | 5 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/curve.c | 28 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/curve.h | 8 |
5 files changed, 74 insertions, 0 deletions
diff --git a/pyecsca/codegen/templates/__init__.py b/pyecsca/codegen/templates/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pyecsca/codegen/templates/__init__.py diff --git a/pyecsca/codegen/templates/coords.c b/pyecsca/codegen/templates/coords.c new file mode 100644 index 0000000..00f6086 --- /dev/null +++ b/pyecsca/codegen/templates/coords.c @@ -0,0 +1,33 @@ +point_t *point_new(void) { + point_t *result = malloc(sizeof(point_t)); + {%- for variable in variables %} + bn_init(&result->{{ variable }}); + {%- endfor %} + + return result; +} + +point_t *point_copy(const point_t *from) { + point_t *result = point_new(); + point_set(from, result); + return result; +} + +void point_set(const point_t *from, point_t *out) { + {%- for variable in variables %} + bn_copy(&from->{{ variable }}, &out->{{ variable }}); + {%- endfor %} +} + +void point_free(point_t *point) { + {%- for variable in variables %} + bn_clear(&point->{{ variable }}); + {%- endfor %} + free(point); +} + +int point_to_affine(point_t *point, const char coord, curve_t *curve, bn_t *out) { + +} + +int point_from_affine(bn_t *x, bn_t *y, curve_t *curve, point_t *out); diff --git a/pyecsca/codegen/templates/coords.h b/pyecsca/codegen/templates/coords.h new file mode 100644 index 0000000..6890c11 --- /dev/null +++ b/pyecsca/codegen/templates/coords.h @@ -0,0 +1,5 @@ +typedef struct { + {%- for variable in variables %} + bn_t {{ variable }}; + {%- endfor %} +} point_t;
\ No newline at end of file diff --git a/pyecsca/codegen/templates/curve.c b/pyecsca/codegen/templates/curve.c new file mode 100644 index 0000000..a49adde --- /dev/null +++ b/pyecsca/codegen/templates/curve.c @@ -0,0 +1,28 @@ +curve_t* curve_new(const named_bn_t **params, int num_params) { + curve_t *result = malloc(sizeof(curve_t)); + {%- for param in params %} + bn_init(&result->{{ param }}); + {%- endfor %} + bn_init(&result->n); + + for (int i = 0; i < num_params; ++i) { + switch (params[i]->name) { + {%- for param in params %} + case '{{ param }}': bn_copy(params[i]->value, result->{{ param }}); + break; + {%- endfor %} + default: + curve_free(result); + return NULL; + } + } + return result; +} + +void curve_free(curve_t *curve) { + {%- for param in params %} + bn_clear(&curve->{{ param }}); + {%- endfor %} + bn_clear(&curve->n); + free(curve); +}
\ No newline at end of file diff --git a/pyecsca/codegen/templates/curve.h b/pyecsca/codegen/templates/curve.h new file mode 100644 index 0000000..ff4a078 --- /dev/null +++ b/pyecsca/codegen/templates/curve.h @@ -0,0 +1,8 @@ +typedef struct { + {%- for param in params %} + bn_t {{ param }}; + {%- endfor %} + bn_t n; + bn_t h; + point_t neutral; +} curve_t;
\ No newline at end of file |
