X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/432c4e184d44704511a5991b80224a87cb1d4613..7280f7f44cfae62f6d34761ac88aa19da7da5dd8:/field.h diff --git a/field.h b/field.h index 7af9b4f..6085716 100644 --- a/field.h +++ b/field.h @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: field.h,v 1.8 2004/03/27 17:54:11 mdw Exp $ + * $Id$ * * Definitions for field arithmetic * * (c) 2000 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,53 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- 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. - * - * 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 @@ -91,6 +56,7 @@ typedef struct field { mp *m; /* Modulus (prime and binary) */ unsigned long nbits; /* Length of field element in bits */ size_t noctets; /* Length of element in octets */ + mp *q; /* Number of elements in field */ } field; enum { @@ -109,6 +75,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*/); @@ -141,6 +108,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)) @@ -178,6 +146,50 @@ 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*/); + +/*----- Arithmetic --------------------------------------------------------*/ + +/* --- @field_exp@ --- * + * + * Arguments: @field *f@ = pointer to field + * @mp *d@ = fake destination + * @mp *a@ = base + * @mp *e@ = exponent + * + * Returns: Result, %$a^e$%. + * + * Use: Exponentiation in a finite field. Note that all quantities + * are in internal format. This is a generic implementation + * suitable for use with all fields and is not intended to be + * optimal. + */ + +extern mp *field_exp(field */*f*/, mp */*d*/, mp */*a*/, mp */*e*/); + /*----- Creating fields ---------------------------------------------------*/ /* --- @field_prime@ --- * @@ -196,7 +208,7 @@ extern field *field_prime(mp */*p*/); * * Arguments: @mp *p@ = the characteristic of the field * - * Returns: A pointer to the field. + * Returns: A pointer to the field, or null. * * Use: Creates a field structure for a prime field of size %$p$%, * using efficient reduction for nice primes. @@ -216,6 +228,20 @@ extern field *field_niceprime(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 @@ -224,9 +250,10 @@ extern field *field_binpoly(mp */*p*/); * * Use: Parses a field description, which has the form * - * * `prime', `niceprime' or `binpoly' + * * `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*/);