X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/f46efa79cd2bb9adc81541f1218965f85a6b2eef..432c4e184d44704511a5991b80224a87cb1d4613:/ec.h diff --git a/ec.h b/ec.h index d398f4a..79e3654 100644 --- a/ec.h +++ b/ec.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: ec.h,v 1.7 2004/03/23 15:19:32 mdw Exp $ + * $Id: ec.h,v 1.8 2004/03/27 17:54:11 mdw Exp $ * * Elliptic curve definitions * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: ec.h,v $ + * Revision 1.8 2004/03/27 17:54:11 mdw + * Standard curves and curve checking. + * * Revision 1.7 2004/03/23 15:19:32 mdw * Test elliptic curves more thoroughly. * @@ -74,8 +77,17 @@ /*----- Header files ------------------------------------------------------*/ -#include "field.h" -#include "mp.h" +#ifndef CATACOMB_FIELD_H +# include "field.h" +#endif + +#ifndef CATACOMB_MP_H +# include "mp.h" +#endif + +#ifndef CATACOMB_QDPARSE_H +# include "qdparse.h" +#endif /*----- Data structures ---------------------------------------------------*/ @@ -84,6 +96,7 @@ typedef struct ec_curve { const struct ec_ops *ops; /* Curve operations */ field *f; /* Underlying field structure */ + mp *a, *b; /* Standard params (internal form) */ } ec_curve; /* --- An elliptic curve point --- */ @@ -135,6 +148,15 @@ typedef struct ec_ops { #define EC_DBL(c, d, p) (c)->ops->dbl((c), (d), (p)) #define EC_CHECK(c, p) (c)->ops->check((c), (p)) +/* --- Elliptic curve parameters --- */ + +typedef struct ec_info { + ec_curve *c; /* The actual curve */ + ec g; /* The common point */ + mp *r; /* Order of %$g$% */ + mp *h; /* Cofactor %$h = \#E/r$% */ +} ec_info; + /*----- Simple memory management things -----------------------------------*/ /* --- @ec_create@ --- * @@ -480,6 +502,100 @@ extern ec_curve *ec_primeproj(field */*f*/, mp */*a*/, mp */*b*/); extern ec_curve *ec_bin(field */*f*/, mp */*a*/, mp */*b*/); extern ec_curve *ec_binproj(field */*f*/, mp */*a*/, mp */*b*/); +/*----- Curve parameter sets ----------------------------------------------*/ + +/* --- @ec_curveparse@ --- * + * + * Arguments: @qd_parse *qd@ = parser context + * + * Returns: Elliptic curve pointer if OK, or null. + * + * Use: Parses an elliptic curve description, which has the form + * + * * a field description + * * an optional `/' + * * `prime', `primeproj', `bin', or `binproj' + * * an optional `:' + * * the %$a$% parameter + * * an optional `,' + * * the %$b$% parameter + */ + +extern ec_curve *ec_curveparse(qd_parse */*qd*/); + +/* --- @ec_ptparse@ --- * + * + * Arguments: @qd_parse *qd@ = parser context + * @ec *p@ = where to put the point + * + * Returns: The point address, or null. + * + * Use: Parses an elliptic curve point. This has the form + * + * * %$x$%-coordinate + * * optional `,' + * * %$y$%-coordinate + */ + +extern ec *ec_ptparse(qd_parse */*qd*/, ec */*p*/); + +/* --- @ec_infoparse@ --- * + * + * Arguments: @qd_parse *qd@ = parser context + * @ec_info *ei@ = curve information block, currently + * uninitialized + * + * Returns: Zero on success, nonzero on failure. + * + * Use: Parses an elliptic curve information string, and stores the + * information in @ei@. This has the form + * + * * elliptic curve description + * * optional `/' + * * common point + * * optional `:' + * * group order + * * optional `*' + * * cofactor + */ + +extern int ec_infoparse(qd_parse */*qd*/, ec_info */*ei*/); + +/* --- @ec_getinfo@ --- * + * + * Arguments: @ec_info *ei@ = where to write the information + * @const char *p@ = string describing a curve + * + * Returns: Null on success, or a pointer to an error message. + * + * Use: Parses out information about a curve. The string is either a + * standard curve name, or a curve info string. + */ + +extern const char *ec_getinfo(ec_info */*ei*/, const char */*p*/); + +/* --- @ec_freeinfo@ --- * + * + * Arguments: @ec_info *ei@ = elliptic curve information block to free + * + * Returns: --- + * + * Use: Frees the information block. + */ + +extern void ec_freeinfo(ec_info */*ei*/); + +/* --- @ec_checkinfo@ --- * + * + * Arguments: @const ec_info *ei@ = elliptic curve information block + * + * Returns: Null if OK, or pointer to error message. + * + * Use: Checks an elliptic curve according to the rules in SEC1. + */ + +extern const char *ec_checkinfo(const ec_info */*ei*/, grand */*gr*/); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus