Back to index

lightning-sunbird  0.9+nobinonly
ecp.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 prime 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 __ecp_h_
00040 #define __ecp_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_GFp_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_GFp_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_GFp_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_GFp_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_GFp_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 GFp curve. */
00066 mp_err ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
00067 
00068 #ifdef ECL_ENABLE_GFP_PT_MUL_AFF
00069 /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
00070  * a, b and p are the elliptic curve coefficients and the prime that
00071  * determines the field GFp.  Uses affine coordinates. */
00072 mp_err ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px,
00073                                            const mp_int *py, mp_int *rx, mp_int *ry,
00074                                            const ECGroup *group);
00075 #endif
00076 
00077 /* Converts a point P(px, py) from affine coordinates to Jacobian
00078  * projective coordinates R(rx, ry, rz). */
00079 mp_err ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx,
00080                                            mp_int *ry, mp_int *rz, const ECGroup *group);
00081 
00082 /* Converts a point P(px, py, pz) from Jacobian projective coordinates to
00083  * affine coordinates R(rx, ry). */
00084 mp_err ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py,
00085                                            const mp_int *pz, mp_int *rx, mp_int *ry,
00086                                            const ECGroup *group);
00087 
00088 /* Checks if point P(px, py, pz) is at infinity.  Uses Jacobian
00089  * coordinates. */
00090 mp_err ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py,
00091                                                  const mp_int *pz);
00092 
00093 /* Sets P(px, py, pz) to be the point at infinity.  Uses Jacobian
00094  * coordinates. */
00095 mp_err ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz);
00096 
00097 /* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
00098  * (qx, qy, qz).  Uses Jacobian coordinates. */
00099 mp_err ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py,
00100                                                   const mp_int *pz, const mp_int *qx,
00101                                                   const mp_int *qy, mp_int *rx, mp_int *ry,
00102                                                   mp_int *rz, const ECGroup *group);
00103 
00104 /* Computes R = 2P.  Uses Jacobian coordinates. */
00105 mp_err ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py,
00106                                            const mp_int *pz, mp_int *rx, mp_int *ry,
00107                                            mp_int *rz, const ECGroup *group);
00108 
00109 #ifdef ECL_ENABLE_GFP_PT_MUL_JAC
00110 /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
00111  * a, b and p are the elliptic curve coefficients and the prime that
00112  * determines the field GFp.  Uses Jacobian coordinates. */
00113 mp_err ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px,
00114                                            const mp_int *py, mp_int *rx, mp_int *ry,
00115                                            const ECGroup *group);
00116 #endif
00117 
00118 /* Computes R(x, y) = k1 * G + k2 * P(x, y), where G is the generator
00119  * (base point) of the group of points on the elliptic curve. Allows k1 =
00120  * NULL or { k2, P } = NULL.  Implemented using mixed Jacobian-affine
00121  * coordinates. Input and output values are assumed to be NOT
00122  * field-encoded and are in affine form. */
00123 mp_err
00124  ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px,
00125                                    const mp_int *py, mp_int *rx, mp_int *ry,
00126                                    const ECGroup *group);
00127 
00128 /* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic
00129  * curve points P and R can be identical. Uses mixed Modified-Jacobian
00130  * co-ordinates for doubling and Chudnovsky Jacobian coordinates for
00131  * additions. Assumes input is already field-encoded using field_enc, and
00132  * returns output that is still field-encoded. Uses 5-bit window NAF
00133  * method (algorithm 11) for scalar-point multiplication from Brown,
00134  * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic 
00135  * Curves Over Prime Fields. */
00136 mp_err
00137  ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py,
00138                                       mp_int *rx, mp_int *ry, const ECGroup *group);
00139 
00140 #endif                                           /* __ecp_h_ */