Skip to content

Commit e68d720

Browse files
committed
Add group element storage type
1 parent ff889f7 commit e68d720

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/group.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ typedef struct {
2525
int infinity; /* whether this represents the point at infinity */
2626
} secp256k1_gej_t;
2727

28+
typedef struct {
29+
secp256k1_fe_storage_t x;
30+
secp256k1_fe_storage_t y;
31+
} secp256k1_ge_storage_t;
32+
2833
/** Set a group element equal to the point at infinity */
2934
static void secp256k1_ge_set_infinity(secp256k1_ge_t *r);
3035

@@ -99,4 +104,10 @@ static void secp256k1_gej_clear(secp256k1_gej_t *r);
99104
/** Clear a secp256k1_ge_t to prevent leaking sensitive information. */
100105
static void secp256k1_ge_clear(secp256k1_ge_t *r);
101106

107+
/** Convert a group element to the storage type. */
108+
static void secp256k1_ge_to_storage(secp256k1_ge_storage_t *r, const secp256k1_ge_t*);
109+
110+
/** Convert a group element back from the storage type. */
111+
static void secp256k1_ge_from_storage(secp256k1_ge_t *r, const secp256k1_ge_storage_t*);
112+
102113
#endif

src/group_impl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,23 @@ static void secp256k1_gej_get_hex(char *r131, const secp256k1_gej_t *a) {
392392
secp256k1_ge_get_hex(r131, &t);
393393
}
394394

395+
static void secp256k1_ge_to_storage(secp256k1_ge_storage_t *r, const secp256k1_ge_t *a) {
396+
secp256k1_fe_t x, y;
397+
VERIFY_CHECK(!a->infinity);
398+
x = a->x;
399+
secp256k1_fe_normalize(&x);
400+
y = a->y;
401+
secp256k1_fe_normalize(&y);
402+
secp256k1_fe_to_storage(&r->x, &x);
403+
secp256k1_fe_to_storage(&r->y, &y);
404+
}
405+
406+
static void secp256k1_ge_from_storage(secp256k1_ge_t *r, const secp256k1_ge_storage_t *a) {
407+
secp256k1_fe_from_storage(&r->x, &a->x);
408+
secp256k1_fe_from_storage(&r->y, &a->y);
409+
r->infinity = 0;
410+
}
411+
395412
#ifdef USE_ENDOMORPHISM
396413
static void secp256k1_gej_mul_lambda(secp256k1_gej_t *r, const secp256k1_gej_t *a) {
397414
static const secp256k1_fe_t beta = SECP256K1_FE_CONST(

0 commit comments

Comments
 (0)