X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/9b8b6877809f0626e8e3eff1f731b1daa796fecb..b817bfc642225b8c3c0b6a7e42d1fb949b61a606:/field.h diff --git a/field.h b/field.h index 909332f..5790284 100644 --- a/field.h +++ b/field.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: field.h,v 1.5 2004/03/23 12:08:26 mdw Exp $ + * $Id: field.h,v 1.11 2004/04/08 01:36:15 mdw Exp $ * * Definitions for field arithmetic * @@ -27,32 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: field.h,v $ - * Revision 1.5 2004/03/23 12:08:26 mdw - * Random field-element selection. - * - * Revision 1.4 2004/03/21 22:52:06 mdw - * Merge and close elliptic curve branch. - * - * Revision 1.3.4.2 2004/03/21 22:39:46 mdw - * Elliptic curves on binary fields work. - * - * Revision 1.3.4.1 2004/03/20 00:13:31 mdw - * Projective coordinates for prime curves - * - * Revision 1.3 2002/01/13 13:48:44 mdw - * Further progress. - * - * Revision 1.2 2001/05/07 17:30:13 mdw - * Add an internal-representation no-op function. - * - * Revision 1.1 2001/04/29 18:12:33 mdw - * Prototype version. - * - */ - #ifndef CATACOMB_FIELD_H #define CATACOMB_FIELD_H @@ -70,19 +44,37 @@ # include "mp.h" #endif +#ifndef CATACOMB_QDPARSE_H +# include "qdparse.h" +#endif + /*----- Data structures ---------------------------------------------------*/ typedef struct field { const struct field_ops *ops; /* Field operations */ mp *zero, *one; /* Identities in the field */ + mp *m; /* Modulus (prime and binary) */ + unsigned long nbits; /* Length of field element in bits */ + size_t noctets; /* Length of element in octets */ } field; +enum { + FTY_PRIME, + FTY_BINARY +}; + typedef struct field_ops { + /* --- General information --- */ + + unsigned ty; /* What kind of field this is */ + const char *name; /* Human-readable name string */ + /* --- Universal operations --- */ void (*destroy)(field */*f*/); mp *(*rand)(field */*f*/, mp */*d*/, grand */*r*/); + int (*samep)(field */*f*/, field */*g*/); mp *(*in)(field */*f*/, mp */*d*/, mp */*x*/); mp *(*out)(field */*f*/, mp */*d*/, mp */*x*/); @@ -110,7 +102,12 @@ typedef struct field_ops { } field_ops; +#define F_TYPE(f) (f)->ops->ty +#define F_NAME(f) (f)->ops->name + #define F_DESTROY(f) (f)->ops->destroy((f)) +#define F_RAND(f, d, r) (f)->ops->rand((f), (d), (r)) +#define F_SAMEP(f, g) (f)->ops->samep((f), (g)) #define F_IN(f, d, x) (f)->ops->in((f), (d), (x)) #define F_OUT(f, d, x) (f)->ops->out((f), (d), (x)) @@ -148,6 +145,31 @@ typedef struct field_ops { extern mp *field_id(field */*f*/, mp */*d*/, mp */*x*/); +/* --- @field_samep@ --- * + * + * Arguments: @field *f, *g@ = two fields + * + * Returns: Nonzero if the fields are identical (not just isomorphic). + * + * Use: Checks for sameness of fields. This function does the full + * check, not just the field-type-specific check done by the + * @sampep@ field operation. + */ + +extern int field_samep(field */*f*/, field */*g*/); + +/* --- @field_stdsamep@ --- * + * + * Arguments: @field *f, *g@ = two fields + * + * Returns: Nonzero if the fields are identical (not just isomorphic). + * + * Use: Standard sameness check, based on equality of the @m@ + * member. + */ + +extern int field_stdsamep(field */*f*/, field */*g*/); + /*----- Creating fields ---------------------------------------------------*/ /* --- @field_prime@ --- * @@ -162,6 +184,18 @@ extern mp *field_id(field */*f*/, mp */*d*/, mp */*x*/); extern field *field_prime(mp */*p*/); +/* --- @field_niceprime@ --- * + * + * Arguments: @mp *p@ = the characteristic of the field + * + * Returns: A pointer to the field. + * + * Use: Creates a field structure for a prime field of size %$p$%, + * using efficient reduction for nice primes. + */ + +extern field *field_niceprime(mp */*p*/); + /* --- @field_binpoly@ --- * * * Arguments: @mp *p@ = an irreducible polynomial over %$\gf{2}$% @@ -174,6 +208,36 @@ extern field *field_prime(mp */*p*/); extern field *field_binpoly(mp */*p*/); +/* --- @field_binnorm@ --- * + * + * Arguments: @mp *p@ = the reduction polynomial + * @mp *beta@ = representation of normal point + * + * Returns: A pointer to the field. + * + * Use: Creates a field structure for a binary field mod @p@ which + * uses a normal basis representation externally. Computations + * are still done on a polynomial-basis representation. + */ + +extern field *field_binnorm(mp */*p*/, mp */*beta*/); + +/* --- @field_parse@ --- * + * + * Arguments: @qd_parse *qd@ = parser context + * + * Returns: Field pointer if OK, or null. + * + * Use: Parses a field description, which has the form + * + * * `prime', `niceprime', `binpoly', or `binnorm' + * * an optional `:' + * * the field modulus + * * for `binnorm', an optional `,' and the beta value + */ + +extern field *field_parse(qd_parse */*qd*/); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus