X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..HEAD:/math/g-bin.c diff --git a/math/g-bin.c b/math/g-bin.c index 79a989fa..683f94ee 100644 --- a/math/g-bin.c +++ b/math/g-bin.c @@ -32,8 +32,7 @@ #include "mpmont.h" #include "pgen.h" -#define ge mp * -#include "group.h" +#define ge ge_bin #include "group-guts.h" /*----- Main code ---------------------------------------------------------*/ @@ -42,27 +41,30 @@ static void gdestroygroup(group *gg) { gctx_bin *g = (gctx_bin *)gg; - mp_drop(g->gen); mp_drop(g->g.r); mp_drop(g->g.h); + mp_drop(g->gen.x); mp_drop(g->g.r); mp_drop(g->g.h); gfreduce_destroy(&g->r); DESTROY(g); } -static mp **gcreate(group *gg) - { mp **x = CREATE(mp *); *x = MP_COPY(*gg->i); return (x); } +static ge_bin *gcreate(group *gg) { + gctx_bin *g = (gctx_bin *)gg; ge_bin *x = CREATE(ge_bin); + x->x = MP_COPY(g->one.x); return (x); +} -static void gcopy(group *gg, mp **d, mp **x) - { mp *t = MP_COPY(*x); MP_DROP(*d); *d = t; } +static void gcopy(group *gg, ge_bin *d, ge_bin *x) + { mp *t = MP_COPY(x->x); MP_DROP(d->x); d->x = t; } -static void gburn(group *gg, mp **x) { (*x)->f |= MP_BURN; } +static void gburn(group *gg, ge_bin *x) { x->x->f |= MP_BURN; } -static void gdestroy(group *gg, mp **x) { MP_DROP(*x); DESTROY(x); } +static void gdestroy(group *gg, ge_bin *x) { MP_DROP(x->x); DESTROY(x); } static int gsamep(group *gg, group *hh) { gctx_bin *g = (gctx_bin *)gg, *h = (gctx_bin *)hh; return (MP_EQ(g->r.p, h->r.p)); } -static int geq(group *gg, mp **x, mp **y) { return (MP_EQ(*x, *y)); } +static int geq(group *gg, ge_bin *x, ge_bin *y) + { return (MP_EQ(x->x, y->x)); } static const char *gcheck(group *gg, grand *gr) { gctx_bin *g = (gctx_bin *)gg; int rc; mp *t, *tt; @@ -74,58 +76,61 @@ static const char *gcheck(group *gg, grand *gr) { return (group_stdcheck(gg, gr)); } -static void gmul(group *gg, mp **d, mp **x, mp **y) { - gctx_bin *g = (gctx_bin *)gg; mp *r = gf_mul(*d, *x, *y); - *d = gfreduce_do(&g->r, r, r); +static void gmul(group *gg, ge_bin *d, ge_bin *x, ge_bin *y) { + gctx_bin *g = (gctx_bin *)gg; mp *r = gf_mul(d->x, x->x, y->x); + d->x = gfreduce_do(&g->r, r, r); } -static void gsqr(group *gg, mp **d, mp **x) { - gctx_bin *g = (gctx_bin *)gg; mp *r = gf_sqr(*d, *x); - *d = gfreduce_do(&g->r, r, r); +static void gsqr(group *gg, ge_bin *d, ge_bin *x) { + gctx_bin *g = (gctx_bin *)gg; mp *r = gf_sqr(d->x, x->x); + d->x = gfreduce_do(&g->r, r, r); } -static void ginv(group *gg, mp **d, mp **x) - { gctx_bin *g = (gctx_bin *)gg; *d = gf_modinv(*d, *x, g->r.p); } +static void ginv(group *gg, ge_bin *d, ge_bin *x) + { gctx_bin *g = (gctx_bin *)gg; d->x = gf_modinv(d->x, x->x, g->r.p); } -static void gexp(group *gg, mp **d, mp **x, mp *n) - { gctx_bin *g = (gctx_bin *)gg; *d = gfreduce_exp(&g->r, *d, *x, n); } +static void gexp(group *gg, ge_bin *d, ge_bin *x, mp *n) { + gctx_bin *g = (gctx_bin *)gg; + d->x = gfreduce_exp(&g->r, d->x, x->x, n); +} -static int gread(group *gg, mp **d, const mptext_ops *ops, void *p) { +static int gread(group *gg, ge_bin *d, const mptext_ops *ops, void *p) { mp *t; if ((t = mp_read(MP_NEW, 0, ops, p)) == 0) return (-1); - mp_drop(*d); *d = t; return (0); + mp_drop(d->x); d->x = t; return (0); } -static int gwrite(group *gg, mp **x, const mptext_ops *ops, void *p) { +static int gwrite(group *gg, ge_bin *x, const mptext_ops *ops, void *p) { int rc = -1; - if (!ops->put("0x", 2, p) && !mp_write(*x, 16, ops, p)) rc = 0; + if (!ops->put("0x", 2, p) && !mp_write(x->x, 16, ops, p)) rc = 0; return (rc); } -static mp *gtoint(group *gg, mp *d, mp **x) { return MP_COPY(*x); } +static mp *gtoint(group *gg, mp *d, ge_bin *x) { return MP_COPY(x->x); } -static int gfromint(group *gg, mp **d, mp *x) { *d = MP_COPY(x); return 0; } +static int gfromint(group *gg, ge_bin *d, mp *x) + { d->x = MP_COPY(x); return 0; } -static int gtobuf(group *gg, buf *b, mp **x) - { int rc = buf_putmp(b, *x); return (rc); } +static int gtobuf(group *gg, buf *b, ge_bin *x) + { int rc = buf_putmp(b, x->x); return (rc); } -static int gfrombuf(group *gg, buf *b, mp **d) { +static int gfrombuf(group *gg, buf *b, ge_bin *d) { gctx_bin *g = (gctx_bin *)gg; mp *x; if ((x = buf_getmp(b)) == 0) return (-1); - MP_DROP(*d); *d = gfreduce_do(&g->r, x, x); + MP_DROP(d->x); d->x = gfreduce_do(&g->r, x, x); return (0); } -static int gtoraw(group *gg, buf *b, mp **x) { - gctx_bin * g = (gctx_bin *)gg; octet *q; +static int gtoraw(group *gg, buf *b, ge_bin *x) { + gctx_bin *g = (gctx_bin *)gg; octet *q; if ((q = buf_get(b, g->g.noctets)) == 0) return (-1); - mp_storeb(*x, q, g->g.noctets); return (0); + mp_storeb(x->x, q, g->g.noctets); return (0); } -static int gfromraw(group *gg, buf *b, mp **d) { - gctx_bin * g = (gctx_bin *)gg; mp *x; octet *q; +static int gfromraw(group *gg, buf *b, ge_bin *d) { + gctx_bin *g = (gctx_bin *)gg; mp *x; octet *q; if ((q = buf_get(b, g->g.noctets)) == 0) return (-1); x = mp_loadb(MP_NEW, q, g->g.noctets); - MP_DROP(*d); *d = gfreduce_do(&g->r, x, x); + MP_DROP(d->x); d->x = gfreduce_do(&g->r, x, x); return (0); } @@ -162,9 +167,9 @@ group *group_binary(const gbin_param *gb) g->g.nbits = mp_bits(gb->p) - 1; g->g.noctets = (g->g.nbits + 7) >> 3; gfreduce_create(&g->r, gb->p); - g->one = MP_ONE; + g->one.x = MP_ONE; g->g.i = &g->one; - g->gen = MP_COPY(gb->g); + g->gen.x = MP_COPY(gb->g); g->g.g = &g->gen; g->g.r = MP_COPY(gb->q); t = mp_lsl(MP_NEW, MP_ONE, g->g.nbits);