X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/34e4f738bcba58e6d8c4cabbb0b3232a65b42a9d..b817bfc642225b8c3c0b6a7e42d1fb949b61a606:/group.h?ds=sidebyside diff --git a/group.h b/group.h index 383bc82..9211a58 100644 --- a/group.h +++ b/group.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: group.h,v 1.1 2004/04/01 12:50:09 mdw Exp $ + * $Id: group.h,v 1.4 2004/04/08 01:36:15 mdw Exp $ * * General cyclic group abstraction * @@ -27,18 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: group.h,v $ - * Revision 1.1 2004/04/01 12:50:09 mdw - * Add cyclic group abstraction, with test code. Separate off exponentation - * functions for better static linking. Fix a buttload of bugs on the way. - * Generally ensure that negative exponents do inversion correctly. Add - * table of standard prime-field subgroups. (Binary field subgroups are - * currently unimplemented but easy to add if anyone ever finds a good one.) - * - */ - #ifndef CATACOMB_GROUP_H #define CATACOMB_GROUP_H @@ -76,10 +64,10 @@ typedef struct ge ge; /* Group element (abstract type) */ #endif -typedef struct group { +typedef struct group_ { const struct group_ops *ops; /* Operations table */ size_t nbits; /* Size of an element in bits */ - size_t noctets; /* Size of an element in octets */ + size_t noctets; /* Size of raw element in octets */ ge *i; /* Identity element */ ge *g; /* Generator element */ mp *r; /* Order of the generator */ @@ -137,6 +125,8 @@ typedef struct group_ops { int (*fromec)(group */*g*/, ge */*d*/, ec */*p*/); int (*tobuf)(group */*h*/, buf */*b*/, ge */*x*/); int (*frombuf)(group */*h*/, buf */*b*/, ge */*d*/); + int (*toraw)(group */*h*/, buf */*b*/, ge */*x*/); + int (*fromraw)(group */*h*/, buf */*b*/, ge */*d*/); } group_ops; @@ -174,6 +164,8 @@ enum { #define G_FROMEC(g, d, p) (g)->ops->fromec((g), (d), (p)) #define G_TOBUF(g, b, x) (g)->ops->tobuf((g), (b), (x)) #define G_FROMBUF(g, b, d) (g)->ops->frombuf((g), (b), (d)) +#define G_TORAW(g, b, x) (g)->ops->toraw((g), (b), (x)) +#define G_FROMRAW(g, b, d) (g)->ops->fromraw((g), (b), (d)) /*----- Handy functions ---------------------------------------------------*/ @@ -334,7 +326,7 @@ typedef struct gprime_param { * * Arguments: @const gprime_param *gp@ = group parameters * - * Returns: A pointer to the group. + * Returns: A pointer to the group, or null. * * Use: Constructs an abstract group interface for a subgroup of a * prime field. Group elements are @mp *@ pointers. @@ -348,7 +340,7 @@ group *group_prime(const gprime_param */*gp*/); * * Arguments: @const ec_info *ei@ = elliptic curve parameters * - * Returns: A pointer to the group. + * Returns: A pointer to the group, or null. * * Use: Constructs an abstract group interface for an elliptic curve * group. Group elements are @ec@ structures. The contents of