Back to index

lightning-sunbird  0.9+nobinonly
ec2.h
Go to the documentation of this file.
00001 /* 
00002  * ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the elliptic curve math library for binary polynomial field curves.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Sun Microsystems, Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __ec2_h_
00040 #define __ec2_h_
00041 
00042 #include "ecl-priv.h"
00043 
00044 /* Checks if point P(px, py) is at infinity.  Uses affine coordinates. */
00045 mp_err ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py);
00046 
00047 /* Sets P(px, py) to be the point at infinity.  Uses affine coordinates. */
00048 mp_err ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py);
00049 
00050 /* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,
00051  * qy). Uses affine coordinates. */
00052 mp_err ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py,
00053                                             const mp_int *qx, const mp_int *qy, mp_int *rx,
00054                                             mp_int *ry, const ECGroup *group);
00055 
00056 /* Computes R = P - Q.  Uses affine coordinates. */
00057 mp_err ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py,
00058                                             const mp_int *qx, const mp_int *qy, mp_int *rx,
00059                                             mp_int *ry, const ECGroup *group);
00060 
00061 /* Computes R = 2P.  Uses affine coordinates. */
00062 mp_err ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
00063                                             mp_int *ry, const ECGroup *group);
00064 
00065 /* Validates a point on a GF2m curve. */
00066 mp_err ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
00067 
00068 /* by default, this routine is unused and thus doesn't need to be compiled */
00069 #ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
00070 /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
00071  * a, b and p are the elliptic curve coefficients and the irreducible that 
00072  * determines the field GF2m.  Uses affine coordinates. */
00073 mp_err ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px,
00074                                             const mp_int *py, mp_int *rx, mp_int *ry,
00075                                             const ECGroup *group);
00076 #endif
00077 
00078 /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
00079  * a, b and p are the elliptic curve coefficients and the irreducible that 
00080  * determines the field GF2m.  Uses Montgomery projective coordinates. */
00081 mp_err ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px,
00082                                              const mp_int *py, mp_int *rx, mp_int *ry,
00083                                              const ECGroup *group);
00084 
00085 #ifdef ECL_ENABLE_GF2M_PROJ
00086 /* Converts a point P(px, py) from affine coordinates to projective
00087  * coordinates R(rx, ry, rz). */
00088 mp_err ec_GF2m_pt_aff2proj(const mp_int *px, const mp_int *py, mp_int *rx,
00089                                              mp_int *ry, mp_int *rz, const ECGroup *group);
00090 
00091 /* Converts a point P(px, py, pz) from projective coordinates to affine
00092  * coordinates R(rx, ry). */
00093 mp_err ec_GF2m_pt_proj2aff(const mp_int *px, const mp_int *py,
00094                                              const mp_int *pz, mp_int *rx, mp_int *ry,
00095                                              const ECGroup *group);
00096 
00097 /* Checks if point P(px, py, pz) is at infinity.  Uses projective
00098  * coordinates. */
00099 mp_err ec_GF2m_pt_is_inf_proj(const mp_int *px, const mp_int *py,
00100                                                    const mp_int *pz);
00101 
00102 /* Sets P(px, py, pz) to be the point at infinity.  Uses projective
00103  * coordinates. */
00104 mp_err ec_GF2m_pt_set_inf_proj(mp_int *px, mp_int *py, mp_int *pz);
00105 
00106 /* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
00107  * (qx, qy, qz).  Uses projective coordinates. */
00108 mp_err ec_GF2m_pt_add_proj(const mp_int *px, const mp_int *py,
00109                                              const mp_int *pz, const mp_int *qx,
00110                                              const mp_int *qy, mp_int *rx, mp_int *ry,
00111                                              mp_int *rz, const ECGroup *group);
00112 
00113 /* Computes R = 2P.  Uses projective coordinates. */
00114 mp_err ec_GF2m_pt_dbl_proj(const mp_int *px, const mp_int *py,
00115                                              const mp_int *pz, mp_int *rx, mp_int *ry,
00116                                              mp_int *rz, const ECGroup *group);
00117 
00118 /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
00119  * a, b and p are the elliptic curve coefficients and the prime that
00120  * determines the field GF2m.  Uses projective coordinates. */
00121 mp_err ec_GF2m_pt_mul_proj(const mp_int *n, const mp_int *px,
00122                                              const mp_int *py, mp_int *rx, mp_int *ry,
00123                                              const ECGroup *group);
00124 #endif
00125 
00126 #endif                                           /* __ec2_h_ */