xref: /illumos-gate/usr/src/common/crypto/ecc/ec2.h (revision c40a6cd785e883b3f052b122c332e21174fc1871)
1*f9fbec18Smcpowers /*
2*f9fbec18Smcpowers  * ***** BEGIN LICENSE BLOCK *****
3*f9fbec18Smcpowers  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4*f9fbec18Smcpowers  *
5*f9fbec18Smcpowers  * The contents of this file are subject to the Mozilla Public License Version
6*f9fbec18Smcpowers  * 1.1 (the "License"); you may not use this file except in compliance with
7*f9fbec18Smcpowers  * the License. You may obtain a copy of the License at
8*f9fbec18Smcpowers  * http://www.mozilla.org/MPL/
9*f9fbec18Smcpowers  *
10*f9fbec18Smcpowers  * Software distributed under the License is distributed on an "AS IS" basis,
11*f9fbec18Smcpowers  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12*f9fbec18Smcpowers  * for the specific language governing rights and limitations under the
13*f9fbec18Smcpowers  * License.
14*f9fbec18Smcpowers  *
15*f9fbec18Smcpowers  * The Original Code is the elliptic curve math library for binary polynomial field curves.
16*f9fbec18Smcpowers  *
17*f9fbec18Smcpowers  * The Initial Developer of the Original Code is
18*f9fbec18Smcpowers  * Sun Microsystems, Inc.
19*f9fbec18Smcpowers  * Portions created by the Initial Developer are Copyright (C) 2003
20*f9fbec18Smcpowers  * the Initial Developer. All Rights Reserved.
21*f9fbec18Smcpowers  *
22*f9fbec18Smcpowers  * Contributor(s):
23*f9fbec18Smcpowers  *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
24*f9fbec18Smcpowers  *
25*f9fbec18Smcpowers  * Alternatively, the contents of this file may be used under the terms of
26*f9fbec18Smcpowers  * either the GNU General Public License Version 2 or later (the "GPL"), or
27*f9fbec18Smcpowers  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28*f9fbec18Smcpowers  * in which case the provisions of the GPL or the LGPL are applicable instead
29*f9fbec18Smcpowers  * of those above. If you wish to allow use of your version of this file only
30*f9fbec18Smcpowers  * under the terms of either the GPL or the LGPL, and not to allow others to
31*f9fbec18Smcpowers  * use your version of this file under the terms of the MPL, indicate your
32*f9fbec18Smcpowers  * decision by deleting the provisions above and replace them with the notice
33*f9fbec18Smcpowers  * and other provisions required by the GPL or the LGPL. If you do not delete
34*f9fbec18Smcpowers  * the provisions above, a recipient may use your version of this file under
35*f9fbec18Smcpowers  * the terms of any one of the MPL, the GPL or the LGPL.
36*f9fbec18Smcpowers  *
37*f9fbec18Smcpowers  * ***** END LICENSE BLOCK ***** */
38*f9fbec18Smcpowers /*
39*f9fbec18Smcpowers  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
40*f9fbec18Smcpowers  * Use is subject to license terms.
41*f9fbec18Smcpowers  *
42*f9fbec18Smcpowers  * Sun elects to use this software under the MPL license.
43*f9fbec18Smcpowers  */
44*f9fbec18Smcpowers 
45*f9fbec18Smcpowers #ifndef _EC2_H
46*f9fbec18Smcpowers #define _EC2_H
47*f9fbec18Smcpowers 
48*f9fbec18Smcpowers #include "ecl-priv.h"
49*f9fbec18Smcpowers 
50*f9fbec18Smcpowers /* Checks if point P(px, py) is at infinity.  Uses affine coordinates. */
51*f9fbec18Smcpowers mp_err ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py);
52*f9fbec18Smcpowers 
53*f9fbec18Smcpowers /* Sets P(px, py) to be the point at infinity.  Uses affine coordinates. */
54*f9fbec18Smcpowers mp_err ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py);
55*f9fbec18Smcpowers 
56*f9fbec18Smcpowers /* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx,
57*f9fbec18Smcpowers  * qy). Uses affine coordinates. */
58*f9fbec18Smcpowers mp_err ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py,
59*f9fbec18Smcpowers 						  const mp_int *qx, const mp_int *qy, mp_int *rx,
60*f9fbec18Smcpowers 						  mp_int *ry, const ECGroup *group);
61*f9fbec18Smcpowers 
62*f9fbec18Smcpowers /* Computes R = P - Q.  Uses affine coordinates. */
63*f9fbec18Smcpowers mp_err ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py,
64*f9fbec18Smcpowers 						  const mp_int *qx, const mp_int *qy, mp_int *rx,
65*f9fbec18Smcpowers 						  mp_int *ry, const ECGroup *group);
66*f9fbec18Smcpowers 
67*f9fbec18Smcpowers /* Computes R = 2P.  Uses affine coordinates. */
68*f9fbec18Smcpowers mp_err ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx,
69*f9fbec18Smcpowers 						  mp_int *ry, const ECGroup *group);
70*f9fbec18Smcpowers 
71*f9fbec18Smcpowers /* Validates a point on a GF2m curve. */
72*f9fbec18Smcpowers mp_err ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group);
73*f9fbec18Smcpowers 
74*f9fbec18Smcpowers /* by default, this routine is unused and thus doesn't need to be compiled */
75*f9fbec18Smcpowers #ifdef ECL_ENABLE_GF2M_PT_MUL_AFF
76*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
77*f9fbec18Smcpowers  * a, b and p are the elliptic curve coefficients and the irreducible that
78*f9fbec18Smcpowers  * determines the field GF2m.  Uses affine coordinates. */
79*f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px,
80*f9fbec18Smcpowers 						  const mp_int *py, mp_int *rx, mp_int *ry,
81*f9fbec18Smcpowers 						  const ECGroup *group);
82*f9fbec18Smcpowers #endif
83*f9fbec18Smcpowers 
84*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
85*f9fbec18Smcpowers  * a, b and p are the elliptic curve coefficients and the irreducible that
86*f9fbec18Smcpowers  * determines the field GF2m.  Uses Montgomery projective coordinates. */
87*f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px,
88*f9fbec18Smcpowers 						   const mp_int *py, mp_int *rx, mp_int *ry,
89*f9fbec18Smcpowers 						   const ECGroup *group);
90*f9fbec18Smcpowers 
91*f9fbec18Smcpowers #ifdef ECL_ENABLE_GF2M_PROJ
92*f9fbec18Smcpowers /* Converts a point P(px, py) from affine coordinates to projective
93*f9fbec18Smcpowers  * coordinates R(rx, ry, rz). */
94*f9fbec18Smcpowers mp_err ec_GF2m_pt_aff2proj(const mp_int *px, const mp_int *py, mp_int *rx,
95*f9fbec18Smcpowers 						   mp_int *ry, mp_int *rz, const ECGroup *group);
96*f9fbec18Smcpowers 
97*f9fbec18Smcpowers /* Converts a point P(px, py, pz) from projective coordinates to affine
98*f9fbec18Smcpowers  * coordinates R(rx, ry). */
99*f9fbec18Smcpowers mp_err ec_GF2m_pt_proj2aff(const mp_int *px, const mp_int *py,
100*f9fbec18Smcpowers 						   const mp_int *pz, mp_int *rx, mp_int *ry,
101*f9fbec18Smcpowers 						   const ECGroup *group);
102*f9fbec18Smcpowers 
103*f9fbec18Smcpowers /* Checks if point P(px, py, pz) is at infinity.  Uses projective
104*f9fbec18Smcpowers  * coordinates. */
105*f9fbec18Smcpowers mp_err ec_GF2m_pt_is_inf_proj(const mp_int *px, const mp_int *py,
106*f9fbec18Smcpowers 							  const mp_int *pz);
107*f9fbec18Smcpowers 
108*f9fbec18Smcpowers /* Sets P(px, py, pz) to be the point at infinity.  Uses projective
109*f9fbec18Smcpowers  * coordinates. */
110*f9fbec18Smcpowers mp_err ec_GF2m_pt_set_inf_proj(mp_int *px, mp_int *py, mp_int *pz);
111*f9fbec18Smcpowers 
112*f9fbec18Smcpowers /* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is
113*f9fbec18Smcpowers  * (qx, qy, qz).  Uses projective coordinates. */
114*f9fbec18Smcpowers mp_err ec_GF2m_pt_add_proj(const mp_int *px, const mp_int *py,
115*f9fbec18Smcpowers 						   const mp_int *pz, const mp_int *qx,
116*f9fbec18Smcpowers 						   const mp_int *qy, mp_int *rx, mp_int *ry,
117*f9fbec18Smcpowers 						   mp_int *rz, const ECGroup *group);
118*f9fbec18Smcpowers 
119*f9fbec18Smcpowers /* Computes R = 2P.  Uses projective coordinates. */
120*f9fbec18Smcpowers mp_err ec_GF2m_pt_dbl_proj(const mp_int *px, const mp_int *py,
121*f9fbec18Smcpowers 						   const mp_int *pz, mp_int *rx, mp_int *ry,
122*f9fbec18Smcpowers 						   mp_int *rz, const ECGroup *group);
123*f9fbec18Smcpowers 
124*f9fbec18Smcpowers /* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters
125*f9fbec18Smcpowers  * a, b and p are the elliptic curve coefficients and the prime that
126*f9fbec18Smcpowers  * determines the field GF2m.  Uses projective coordinates. */
127*f9fbec18Smcpowers mp_err ec_GF2m_pt_mul_proj(const mp_int *n, const mp_int *px,
128*f9fbec18Smcpowers 						   const mp_int *py, mp_int *rx, mp_int *ry,
129*f9fbec18Smcpowers 						   const ECGroup *group);
130*f9fbec18Smcpowers #endif
131*f9fbec18Smcpowers 
132*f9fbec18Smcpowers #endif /* _EC2_H */
133