diff options
| author | J08nY | 2025-10-02 14:20:32 +0200 |
|---|---|---|
| committer | J08nY | 2025-10-02 14:20:32 +0200 |
| commit | bb51b7890448201679878fe7df1bb79df8e336e0 (patch) | |
| tree | 6abd6c911732981d137bc15f522fe0ce616d6670 /pyecsca/codegen | |
| parent | dc1241a76f5658a481613817a71c62fbb9234250 (diff) | |
| download | pyecsca-codegen-bb51b7890448201679878fe7df1bb79df8e336e0.tar.gz pyecsca-codegen-bb51b7890448201679878fe7df1bb79df8e336e0.tar.zst pyecsca-codegen-bb51b7890448201679878fe7df1bb79df8e336e0.zip | |
Use bn clear functions.
Diffstat (limited to 'pyecsca/codegen')
| -rw-r--r-- | pyecsca/codegen/bn/bn.c | 36 | ||||
| -rw-r--r-- | pyecsca/codegen/bn/bn.h | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/render.py | 3 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult.c | 4 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_bgmw.c | 3 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_bnaf.c | 3 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_booth.c | 0 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_comb.c | 7 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_fixed_w.c | 3 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_sliding_w.c | 3 | ||||
| -rw-r--r-- | pyecsca/codegen/templates/mult_wnaf.c | 3 |
11 files changed, 52 insertions, 17 deletions
diff --git a/pyecsca/codegen/bn/bn.c b/pyecsca/codegen/bn/bn.c index d3b7968..6dea91c 100644 --- a/pyecsca/codegen/bn/bn.c +++ b/pyecsca/codegen/bn/bn.c @@ -548,6 +548,14 @@ void bn_naf_reverse(wnaf_t *naf) { } } +void bn_naf_clear(wnaf_t *naf) { + if (naf == NULL) { + return; + } + free(naf->data); + free(naf); +} + wsliding_t *bn_wsliding_ltr(const bn_t *bn, int w) { if (w > 8 || w < 2) { return NULL; @@ -679,6 +687,14 @@ exit_k: return result; } +void bn_wsliding_clear(wsliding_t *wsliding) { + if (wsliding == NULL) { + return; + } + free(wsliding->data); + free(wsliding); +} + small_base_t *bn_convert_base_small(const bn_t *bn, int m) { small_base_t *result = NULL; @@ -717,6 +733,14 @@ exit_k: return result; } +void bn_small_base_clear(small_base_t *sb) { + if (sb == NULL) { + return; + } + free(sb->data); + free(sb); +} + large_base_t *bn_convert_base_large(const bn_t *bn, const bn_t *m) { large_base_t *result = NULL; @@ -755,4 +779,16 @@ exit_len: bn_clear(&k); exit_k: return result; +} + +void bn_large_base_clear(large_base_t *lb) { + if (lb == NULL) { + return; + } + for (int i = 0; i < lb->length; i++) { + bn_clear(&lb->data[i]); + } + free(lb->data); + bn_clear(&lb->m); + free(lb); }
\ No newline at end of file diff --git a/pyecsca/codegen/bn/bn.h b/pyecsca/codegen/bn/bn.h index 78d2d94..d6a6add 100644 --- a/pyecsca/codegen/bn/bn.h +++ b/pyecsca/codegen/bn/bn.h @@ -143,11 +143,15 @@ void bn_naf_pad_right(wnaf_t *naf, int8_t value, size_t amount); void bn_naf_strip_left(wnaf_t *naf, int8_t value); void bn_naf_strip_right(wnaf_t *naf, int8_t value); void bn_naf_reverse(wnaf_t *naf); +void bn_naf_clear(wnaf_t *naf); wsliding_t *bn_wsliding_ltr(const bn_t *bn, int w); wsliding_t *bn_wsliding_rtl(const bn_t *bn, int w); +void bn_wsliding_clear(wsliding_t *wsliding); small_base_t *bn_convert_base_small(const bn_t *bn, int m); +void bn_small_base_clear(small_base_t *sb); large_base_t *bn_convert_base_large(const bn_t *bn, const bn_t *m); +void bn_large_base_clear(large_base_t *lb); #endif //BN_H_
\ No newline at end of file diff --git a/pyecsca/codegen/render.py b/pyecsca/codegen/render.py index 692deab..b1c1477 100644 --- a/pyecsca/codegen/render.py +++ b/pyecsca/codegen/render.py @@ -30,7 +30,7 @@ from pyecsca.ec.mult import ( BGMWMultiplier, CombMultiplier, AccumulationOrder, - ProcessingDirection + ProcessingDirection, WindowBoothMultiplier ) from pyecsca.ec.op import OpType, CodeOp @@ -227,6 +227,7 @@ def render_scalarmult_impl(scalarmult: ScalarMultiplier) -> str: DifferentialLadderMultiplier=DifferentialLadderMultiplier, BinaryNAFMultiplier=BinaryNAFMultiplier, WindowNAFMultiplier=WindowNAFMultiplier, + WindowBoothMultiplier=WindowBoothMultiplier, SlidingWindowMultiplier=SlidingWindowMultiplier, FixedWindowLTRMultiplier=FixedWindowLTRMultiplier, FullPrecompMultiplier=FullPrecompMultiplier, diff --git a/pyecsca/codegen/templates/mult.c b/pyecsca/codegen/templates/mult.c index 0144e36..4070952 100644 --- a/pyecsca/codegen/templates/mult.c +++ b/pyecsca/codegen/templates/mult.c @@ -31,6 +31,10 @@ {% include "mult_wnaf.c" %} +{%- elif isinstance(scalarmult, WindowBoothMultiplier) -%} + + {% include "mult_booth.c" %} + {%- elif isinstance(scalarmult, SlidingWindowMultiplier) -%} {% include "mult_sliding_w.c" %} diff --git a/pyecsca/codegen/templates/mult_bgmw.c b/pyecsca/codegen/templates/mult_bgmw.c index 5298fb1..e2e8c72 100644 --- a/pyecsca/codegen/templates/mult_bgmw.c +++ b/pyecsca/codegen/templates/mult_bgmw.c @@ -48,8 +48,7 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin {%- endif %} point_accumulate(a, b, curve, a); } - free(bs->data); - free(bs); + bn_small_base_clear(bs); {%- if "scl" in scalarmult.formulas %} point_scl(a, curve, a); diff --git a/pyecsca/codegen/templates/mult_bnaf.c b/pyecsca/codegen/templates/mult_bnaf.c index 090807c..9c760af 100644 --- a/pyecsca/codegen/templates/mult_bnaf.c +++ b/pyecsca/codegen/templates/mult_bnaf.c @@ -103,8 +103,7 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin point_t *q = scalar_mult_rtl(point, neg, curve, naf, bits); {% endif %} - free(naf->data); - free(naf); + bn_naf_clear(naf); {%- if "scl" in scalarmult.formulas %} point_scl(q, curve, q); diff --git a/pyecsca/codegen/templates/mult_booth.c b/pyecsca/codegen/templates/mult_booth.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pyecsca/codegen/templates/mult_booth.c diff --git a/pyecsca/codegen/templates/mult_comb.c b/pyecsca/codegen/templates/mult_comb.c index a0fbd10..1fbb5a3 100644 --- a/pyecsca/codegen/templates/mult_comb.c +++ b/pyecsca/codegen/templates/mult_comb.c @@ -65,12 +65,7 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin {% endif %} } } - for (int i = 0; i < bs->length; i++) { - bn_clear(&bs->data[i]); - } - free(bs->data); - bn_clear(&bs->m); - free(bs); + bn_large_base_clear(bs); bn_clear(&base); diff --git a/pyecsca/codegen/templates/mult_fixed_w.c b/pyecsca/codegen/templates/mult_fixed_w.c index e756af5..6a079b3 100644 --- a/pyecsca/codegen/templates/mult_fixed_w.c +++ b/pyecsca/codegen/templates/mult_fixed_w.c @@ -53,8 +53,7 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin point_accumulate(q, points[val-1], curve, q); } } - free(bs->data); - free(bs); + bn_small_base_clear(bs); {%- if "scl" in scalarmult.formulas %} point_scl(q, curve, q); diff --git a/pyecsca/codegen/templates/mult_sliding_w.c b/pyecsca/codegen/templates/mult_sliding_w.c index 1e80a84..347c313 100644 --- a/pyecsca/codegen/templates/mult_sliding_w.c +++ b/pyecsca/codegen/templates/mult_sliding_w.c @@ -34,8 +34,7 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin {%- endif %} point_set(q, out); - free(ws->data); - free(ws); + bn_wsliding_clear(ws); for (long i = 0; i < {{ 2 ** (scalarmult.width - 1) }}; i++) { point_free(points[i]); } diff --git a/pyecsca/codegen/templates/mult_wnaf.c b/pyecsca/codegen/templates/mult_wnaf.c index c9228fb..569e78b 100644 --- a/pyecsca/codegen/templates/mult_wnaf.c +++ b/pyecsca/codegen/templates/mult_wnaf.c @@ -40,8 +40,7 @@ static void scalar_mult_inner(bn_t *scalar, point_t *point, curve_t *curve, poin {%- endif %} } } - free(naf->data); - free(naf); + bn_naf_clear(naf); {%- if "scl" in scalarmult.formulas %} point_scl(q, curve, q); |
