X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/f46efa79cd2bb9adc81541f1218965f85a6b2eef..34e4f738bcba58e6d8c4cabbb0b3232a65b42a9d:/field.h diff --git a/field.h b/field.h index 21ac7dd..bf0428a 100644 --- a/field.h +++ b/field.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: field.h,v 1.7 2004/03/27 00:04:46 mdw Exp $ + * $Id: field.h,v 1.9 2004/04/01 12:50:09 mdw Exp $ * * Definitions for field arithmetic * @@ -30,6 +30,16 @@ /*----- Revision history --------------------------------------------------* * * $Log: field.h,v $ + * Revision 1.9 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.) + * + * Revision 1.8 2004/03/27 17:54:11 mdw + * Standard curves and curve checking. + * * Revision 1.7 2004/03/27 00:04:46 mdw * Implement efficient reduction for pleasant-looking primes. * @@ -76,11 +86,18 @@ # 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 { @@ -99,6 +116,7 @@ typedef struct field_ops { 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*/); @@ -131,6 +149,7 @@ typedef struct field_ops { #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)) @@ -168,6 +187,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@ --- * @@ -206,6 +250,21 @@ extern field *field_niceprime(mp */*p*/); extern field *field_binpoly(mp */*p*/); +/* --- @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' or `binpoly' + * * an optional `:' + * * the field modulus + */ + +extern field *field_parse(qd_parse */*qd*/); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus