From f6596142726ed1104877398126a4e0b3824c82a6 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 9 Feb 2019 17:50:27 +0000 Subject: [PATCH] ecc.[ch]: add elliptic-curve point_copy_into functions. This will let my upcoming new test of memory access patterns run a sequence of tests on different elliptic-curve data which is stored at the same address each time. --- ecc.c | 23 +++++++++++++++++++++++ ecc.h | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/ecc.c b/ecc.c index bf19f80b..acdc7d3f 100644 --- a/ecc.c +++ b/ecc.c @@ -112,6 +112,14 @@ WeierstrassPoint *ecc_weierstrass_point_new_identity(WeierstrassCurve *wc) return wp; } +void ecc_weierstrass_point_copy_into( + WeierstrassPoint *dest, WeierstrassPoint *src) +{ + mp_copy_into(dest->X, src->X); + mp_copy_into(dest->Y, src->Y); + mp_copy_into(dest->Z, src->Z); +} + WeierstrassPoint *ecc_weierstrass_point_copy(WeierstrassPoint *orig) { WeierstrassPoint *wp = ecc_weierstrass_point_new_empty(orig->wc); @@ -610,6 +618,13 @@ MontgomeryPoint *ecc_montgomery_point_new(MontgomeryCurve *mc, mp_int *x) return mp; } +void ecc_montgomery_point_copy_into( + MontgomeryPoint *dest, MontgomeryPoint *src) +{ + mp_copy_into(dest->X, src->X); + mp_copy_into(dest->Z, src->Z); +} + MontgomeryPoint *ecc_montgomery_point_copy(MontgomeryPoint *orig) { MontgomeryPoint *mp = ecc_montgomery_point_new_empty(orig->mc); @@ -904,6 +919,14 @@ EdwardsPoint *ecc_edwards_point_new( ec, monty_import(ec->mc, x), monty_import(ec->mc, y)); } +void ecc_edwards_point_copy_into(EdwardsPoint *dest, EdwardsPoint *src) +{ + mp_copy_into(dest->X, src->X); + mp_copy_into(dest->Y, src->Y); + mp_copy_into(dest->Z, src->Z); + mp_copy_into(dest->T, src->T); +} + EdwardsPoint *ecc_edwards_point_copy(EdwardsPoint *orig) { EdwardsPoint *ep = ecc_edwards_point_new_empty(orig->ec); diff --git a/ecc.h b/ecc.h index def80ace..13118b29 100644 --- a/ecc.h +++ b/ecc.h @@ -61,6 +61,8 @@ WeierstrassPoint *ecc_weierstrass_point_new_from_x( WeierstrassCurve *curve, mp_int *x, unsigned desired_y_parity); /* Memory management: copy and free points. */ +void ecc_weierstrass_point_copy_into( + WeierstrassPoint *dest, WeierstrassPoint *src); WeierstrassPoint *ecc_weierstrass_point_copy(WeierstrassPoint *wc); void ecc_weierstrass_point_free(WeierstrassPoint *point); @@ -143,6 +145,8 @@ void ecc_montgomery_curve_free(MontgomeryCurve *); * explicitly represent the identity for this application. */ MontgomeryPoint *ecc_montgomery_point_new(MontgomeryCurve *mc, mp_int *x); +void ecc_montgomery_point_copy_into( + MontgomeryPoint *dest, MontgomeryPoint *src); MontgomeryPoint *ecc_montgomery_point_copy(MontgomeryPoint *orig); void ecc_montgomery_point_free(MontgomeryPoint *mp); @@ -213,6 +217,7 @@ EdwardsPoint *ecc_edwards_point_new_from_y( EdwardsCurve *curve, mp_int *y, unsigned desired_x_parity); /* Copy and free points. */ +void ecc_edwards_point_copy_into(EdwardsPoint *dest, EdwardsPoint *src); EdwardsPoint *ecc_edwards_point_copy(EdwardsPoint *ec); void ecc_edwards_point_free(EdwardsPoint *point);