From e68d7208ecb5410af3fb822caa51c6aaa53aa5b6 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 25 Jan 2015 00:31:56 -0400 Subject: [PATCH] Add group element storage type --- src/group.h | 11 +++++++++++ src/group_impl.h | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/group.h b/src/group.h index 212c5d26a7..10892e75b1 100644 --- a/src/group.h +++ b/src/group.h @@ -25,6 +25,11 @@ typedef struct { int infinity; /* whether this represents the point at infinity */ } secp256k1_gej_t; +typedef struct { + secp256k1_fe_storage_t x; + secp256k1_fe_storage_t y; +} secp256k1_ge_storage_t; + /** Set a group element equal to the point at infinity */ static void secp256k1_ge_set_infinity(secp256k1_ge_t *r); @@ -99,4 +104,10 @@ static void secp256k1_gej_clear(secp256k1_gej_t *r); /** Clear a secp256k1_ge_t to prevent leaking sensitive information. */ static void secp256k1_ge_clear(secp256k1_ge_t *r); +/** Convert a group element to the storage type. */ +static void secp256k1_ge_to_storage(secp256k1_ge_storage_t *r, const secp256k1_ge_t*); + +/** Convert a group element back from the storage type. */ +static void secp256k1_ge_from_storage(secp256k1_ge_t *r, const secp256k1_ge_storage_t*); + #endif diff --git a/src/group_impl.h b/src/group_impl.h index 81939326e6..abd1f846ac 100644 --- a/src/group_impl.h +++ b/src/group_impl.h @@ -392,6 +392,23 @@ static void secp256k1_gej_get_hex(char *r131, const secp256k1_gej_t *a) { secp256k1_ge_get_hex(r131, &t); } +static void secp256k1_ge_to_storage(secp256k1_ge_storage_t *r, const secp256k1_ge_t *a) { + secp256k1_fe_t x, y; + VERIFY_CHECK(!a->infinity); + x = a->x; + secp256k1_fe_normalize(&x); + y = a->y; + secp256k1_fe_normalize(&y); + secp256k1_fe_to_storage(&r->x, &x); + secp256k1_fe_to_storage(&r->y, &y); +} + +static void secp256k1_ge_from_storage(secp256k1_ge_t *r, const secp256k1_ge_storage_t *a) { + secp256k1_fe_from_storage(&r->x, &a->x); + secp256k1_fe_from_storage(&r->y, &a->y); + r->infinity = 0; +} + #ifdef USE_ENDOMORPHISM static void secp256k1_gej_mul_lambda(secp256k1_gej_t *r, const secp256k1_gej_t *a) { static const secp256k1_fe_t beta = SECP256K1_FE_CONST(