Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / freebl / ecl / ecp.h
blob1d247b1549fbffc6e4c0f500c51cc10cb8309f19
1 /*
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is the elliptic curve math library for prime field curves.
17 * The Initial Developer of the Original Code is
18 * Sun Microsystems, Inc.
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef __ecp_h_
40 #define __ecp_h_
42 #include "ecl-priv.h"
44 /* Checks if point P(px, py) is at infinity. Uses affine coordinates. */
45 mp_err ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py);
47 /* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */
48 mp_err ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py);
50 /* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,
51 * qy). Uses affine coordinates. */
52 mp_err ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py,
53 const mp_int *qx, const mp_int *qy, mp_int *rx,
54 mp_int *ry, const ECGroup *group);
56 /* Computes R = P - Q. Uses affine coordinates. */
57 mp_err ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py,
58 const mp_int *qx, const mp_int *qy, mp_int *rx,
59 mp_int *ry, const ECGroup *group);
61 /* Computes R = 2P. Uses affine coordinates. */
62 mp_err ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
63 mp_int *ry, const ECGroup *group);
65 /* Validates a point on a GFp curve. */
66 mp_err ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
68 #ifdef ECL_ENABLE_GFP_PT_MUL_AFF
69 /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
70 * a, b and p are the elliptic curve coefficients and the prime that
71 * determines the field GFp. Uses affine coordinates. */
72 mp_err ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px,
73 const mp_int *py, mp_int *rx, mp_int *ry,
74 const ECGroup *group);
75 #endif
77 /* Converts a point P(px, py) from affine coordinates to Jacobian
78 * projective coordinates R(rx, ry, rz). */
79 mp_err ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx,
80 mp_int *ry, mp_int *rz, const ECGroup *group);
82 /* Converts a point P(px, py, pz) from Jacobian projective coordinates to
83 * affine coordinates R(rx, ry). */
84 mp_err ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py,
85 const mp_int *pz, mp_int *rx, mp_int *ry,
86 const ECGroup *group);
88 /* Checks if point P(px, py, pz) is at infinity. Uses Jacobian
89 * coordinates. */
90 mp_err ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py,
91 const mp_int *pz);
93 /* Sets P(px, py, pz) to be the point at infinity. Uses Jacobian
94 * coordinates. */
95 mp_err ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz);
97 /* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
98 * (qx, qy, qz). Uses Jacobian coordinates. */
99 mp_err ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py,
100 const mp_int *pz, const mp_int *qx,
101 const mp_int *qy, mp_int *rx, mp_int *ry,
102 mp_int *rz, const ECGroup *group);
104 /* Computes R = 2P. Uses Jacobian coordinates. */
105 mp_err ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py,
106 const mp_int *pz, mp_int *rx, mp_int *ry,
107 mp_int *rz, const ECGroup *group);
109 #ifdef ECL_ENABLE_GFP_PT_MUL_JAC
110 /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
111 * a, b and p are the elliptic curve coefficients and the prime that
112 * determines the field GFp. Uses Jacobian coordinates. */
113 mp_err ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px,
114 const mp_int *py, mp_int *rx, mp_int *ry,
115 const ECGroup *group);
116 #endif
118 /* Computes R(x, y) = k1 * G + k2 * P(x, y), where G is the generator
119 * (base point) of the group of points on the elliptic curve. Allows k1 =
120 * NULL or { k2, P } = NULL. Implemented using mixed Jacobian-affine
121 * coordinates. Input and output values are assumed to be NOT
122 * field-encoded and are in affine form. */
123 mp_err
124 ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px,
125 const mp_int *py, mp_int *rx, mp_int *ry,
126 const ECGroup *group);
128 /* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic
129 * curve points P and R can be identical. Uses mixed Modified-Jacobian
130 * co-ordinates for doubling and Chudnovsky Jacobian coordinates for
131 * additions. Assumes input is already field-encoded using field_enc, and
132 * returns output that is still field-encoded. Uses 5-bit window NAF
133 * method (algorithm 11) for scalar-point multiplication from Brown,
134 * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic
135 * Curves Over Prime Fields. */
136 mp_err
137 ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py,
138 mp_int *rx, mp_int *ry, const ECGroup *group);
140 #endif /* __ecp_h_ */