Hey all,
I want to try and keep this question concise, but if more information is needed please say. My goal is to create some code to work with elliptic curves and friends and I want to try and start off well with reasonable structures for curves and points.
For a curve i would want things like the curve coefficients, but I also want the structure to hold the context for the general ring so I can perform arithmetic and other things.
From the documentation, the two obvious structures would be
typedef struct
{
gr_ptr a;
gr_ptr b;
gr_ctx_t ctx; // to perform arithmetic we will need the gr_ctx
} ec_weierstrass_curve_t;
or
typedef struct
{
gr_ptr a;
gr_ptr b;
gr_ctx_ptr ctx; // to perform arithmetic we will need the gr_ctx
} ec_weierstrass_curve_t;
I can't tell which of these is better, but I cannot make either work.
The issue is how I initialise this curve. Say I write a function:
void ec_weierstrass_curve_init(ec_weierstrass_curve_t *E, gr_ctx_t ctx)
{
E->ctx = ctx;
E->a = gr_heap_init(E->ctx);
E->b = gr_heap_init(E->ctx);
}
Then I can pass a context to this function and store a pointer to it (gr_ctx_ptr) in the structure. The issue with this seems to then be that if I try and do GR_TMP_INIT(x, E->ctx);, this fails and I can't find a reasonable way to deference the pointer.
Instead, if I try and store `gr_ctx_t` itself, then I need something like gr_ctx_copy(E->ctx, ctx), but I can't find such a function.
What I have at the moment is
typedef struct
{
gr_ptr a;
gr_ptr b;
gr_ctx_struct* ctx; // to perform arithmetic we will need the gr_ctx
} ec_weierstrass_curve_t;
which seems to "work" but I'm worried this is a bit of a hack and I'm mainly concerned that I'm just doing something fundamentally wrong.
Also, should I be using `gr_init_heap` here? I tried `gr_init()` instead, but this gave me a bus error.