X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/ceb3f0c0a3b7bb3fa3250d31b04c382894095e52..432c4e184d44704511a5991b80224a87cb1d4613:/field.h diff --git a/field.h b/field.h index ea019c5..7af9b4f 100644 --- a/field.h +++ b/field.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: field.h,v 1.3.4.2 2004/03/21 22:39:46 mdw Exp $ + * $Id: field.h,v 1.8 2004/03/27 17:54:11 mdw Exp $ * * Definitions for field arithmetic * @@ -30,6 +30,21 @@ /*----- Revision history --------------------------------------------------* * * $Log: field.h,v $ + * 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. + * + * Revision 1.6 2004/03/23 15:19:32 mdw + * Test elliptic curves more thoroughly. + * + * 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. * @@ -56,22 +71,44 @@ /*----- Header files ------------------------------------------------------*/ +#ifndef CATACOMB_GRAND_H +# include "grand.h" +#endif + #ifndef CATACOMB_MP_H # 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*/); mp *(*in)(field */*f*/, mp */*d*/, mp */*x*/); mp *(*out)(field */*f*/, mp */*d*/, mp */*x*/); @@ -99,7 +136,11 @@ 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_IN(f, d, x) (f)->ops->in((f), (d), (x)) #define F_OUT(f, d, x) (f)->ops->out((f), (d), (x)) @@ -151,6 +192,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}$% @@ -163,6 +216,21 @@ extern field *field_prime(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